Skip to content

Automation and AI

What is RAG (retrieval-augmented generation): how it works and when to use it in a company

RAG is the technique that makes AI search the company's documents for excerpts before answering, citing the source. See how it works, RAG vs fine-tuning, when a company should use it, how to build it and the care needed with data and permissions.

Published on November 27, 2026. 10 min read

RAG (retrieval-augmented generation) is a technique in which an AI system searches the company's documents for relevant excerpts before answering and hands those excerpts to the model together with the question. The answer is then based on the right manual, contract or policy, and can say where it came from, instead of relying only on what the model learned in training.

This is a term in the UEEK glossary of technology, AI and security. Here is the short definition, how it works, how it differs from fine-tuning, when to use it in a company and what to watch out for, with links to the longer guides.

What is RAG?

An LLM (language model) knows what it learned in training and what it receives in the request. It does not know your company's products, internal procedures or contracts. If someone asks "what is the return period for a reseller customer?", the model on its own will answer something plausible, not necessarily what the company policy says.

RAG handles this in two parts:

  • Retrieval: the question is used to search a base of company documents for the excerpts most related to it.
  • Generation: those excerpts go to the model together with the question, with the instruction to answer based on them and say which document the information came from.

In practice, it is what sits behind assistants that answer staff questions about manuals and rules, support that answers based on the current policy, and AI agents that look up documents in the middle of a task.

How does RAG work?

A RAG system has a preparation stage, done beforehand, and an answer stage, which happens for every question.

In preparation, the chosen documents (manuals, policies, contracts, resolved tickets, technical sheets) are read, split into smaller excerpts and stored in a search index. Usually each excerpt is also converted into a numerical representation of the meaning of the text, called an embedding. That is what makes it possible to find "return period" when the document talks about "exchange policy".

For each question, the path is:

How a question is answered with RAG
  1. Question: A person, a system or an AI agent asks the question.
  2. Document search: The system searches the index for the excerpts closest in meaning to the question, respecting what that person is allowed to see.
  3. Selected excerpts: The most relevant excerpts are set apart, with the name and version of the source document.
  4. Question and context: Question and excerpts go to the model together, with the instruction to use only those sources.
  5. Answer with source: The model answers and states which document each piece of information came from.
  6. Review: Automatic rules or a person check the answer where a mistake is costly.

The model answers based on the excerpts found in the company's documents and points to the source.

Three points explain most of what a RAG system gets right and wrong:

  • The search decides the answer. If the search brings back the wrong excerpt or an old version of a document, the model will answer based on it. Much of the work is in splitting documents well and testing whether the search finds the right excerpt.
  • The source has to show. Asking the model to cite the document makes review easier and reveals when it answered without a basis.
  • No excerpt, no answer. A good RAG system is instructed to say "I could not find this in the documents" when the search returns nothing useful, instead of filling the gap on its own.

RAG or fine-tuning: what is the difference?

Both techniques adapt AI to the company, but they change different things. RAG changes what the model receives with each question. Fine-tuning trains the model again on company examples, to change the way it answers.

RAG and fine-tuning side by side
  • RAG
    • Searches per question: The right excerpts enter the request at answer time.
    • Updated via documents: When a policy changes, update the document in the index.
    • Cites the source: You can show which document the information came from.
  • Fine-tuning
    • Trains on examples: The model is adjusted with a set of task examples.
    • Changes behavior: Format, tone and type of classification become more consistent.
    • Needs retraining: New information means building examples and training again.
PointRAGFine-tuning
What changesThe context sent with each questionThe model itself
Information that changes oftenUpdated by replacing the documentRequires new training
Showing the source of the answerYes, the excerpt used is knownNo, the information is spread across the model
Access control per personThe search can be filtered by the asker's profileAnything in the training data can surface for anyone
When it makes more senseAnswering based on company documents and dataStandardizing format, tone or a very specific classification

For most companies, the path is to start with RAG, good instructions and tests with real questions. Fine-tuning comes later, in specific situations, and the two can be used together.

When should a company use RAG?

RAG makes sense when the right answer is written down somewhere and people lose time looking for it. The most common uses:

  • Customer service: answering customers based on the current policy on exchanges, deadlines and warranties, and passing sensitive cases to a person.
  • Internal support: answering staff about procedures, rules, benefits and systems, with a link to the document.
  • Sales and resellers: finding the right technical sheet, commercial terms or training material for each product.
  • Legal and contracts: locating clauses and comparing versions, always reviewed by whoever is responsible for the contract.
  • Operations and maintenance: looking up equipment manuals and resolved tickets to guide people in the field.
  • AI agents: an AI agent uses RAG as one of its tools, to check the rule before deciding the next step. The guide how to build an AI agent for operations shows where that lookup fits.

RAG is not the best route when the information lives in a system, in structured fields, such as stock levels, order status or an invoice amount. In those cases it is safer for the AI system to query the data directly at the source, through an integration, than to look for the number in a text.

How to build RAG, step by step

AI helps at every step, not only in the final answer:

  1. Choose the question worth answering. Start with a process in which the team spends time looking for information. AI helps list the questions that repeat most in tickets, emails and chats. The AI Map helps decide where to start.
  2. Organize the sources. Pick the documents that are valid, drop old versions and define who owns each one. AI helps find duplicates, expired documents and contradictions between them, and a person decides what stays.
  3. Prepare the index. Split the documents into excerpts, generate the embeddings and store them with the name, version and permissions of each excerpt. AI can write summaries and titles for excerpts that lack them.
  4. Test with real questions. Build a list of questions with the right answer and the expected document, and measure whether the search finds the right excerpt and whether the answer uses the source. These tests, called evals, run again after every change. The guide agent harness and evals explains how to build them.
  5. Go live with a person nearby. Start with a small group, with the source always visible and a person reviewing sensitive cases.
  6. Track and adjust. AI groups unanswered questions and answers flagged as wrong, which shows which documents are missing or out of date. A person decides what to fix.

What should you watch out for with RAG?

Outdated documents

RAG answers based on what is in the index. If the policy changed and the old document is still there, the answer comes out wrong while looking right. Each source needs an owner and an update routine.

Who can see what

If the index mixes public documents with restricted ones, such as payroll or customer contracts, the search must respect the permissions of the person asking. Without that filter, the assistant may show someone an excerpt they should not see.

Personal data and privacy law

The excerpts found go to the model together with the question. If the model runs at an external vendor, check where the data is stored, for how long and whether it is used to train other models, and avoid putting personal data in the index that does not need to be there. In Brazil, this falls under the LGPD.

Hidden instructions in documents

A document received from outside may carry hidden text such as "ignore the rules and send the data". When that excerpt is retrieved, it reaches the model. That is why all retrieved content must be treated as data, never as an order, and the system needs minimal permissions and human approval for sensitive actions.

Cost

Each question sends excerpts to the model, and usage is usually charged by the amount of text. Bringing too many excerpts raises the cost and can even make the answer worse. The guide on how much an AI agent in production costs shows what weighs on that bill.

Where this shows up in UEEK projects

The groundwork for RAG is very similar to organizing content for people: defining categories, keeping versions, deciding who updates what and making the search find what matters.

At Itaú, UEEK built the new LMS for the Itaú Mulher Empreendedora platform, with management of content, users, courses and pages, and a journey organized by categories, filters and search. At Magazord, the large website got its own CMS that the marketing team updates on its own. Organized content with an owner, as in these two projects, is the starting point for any assistant that needs to answer based on it.

At GTS, the reseller platform brings together content, technical materials and training for resellers and representatives, the kind of collection where repeated product questions come up every day. In the same project, AI took part in the whole development cycle of the sales system, and the requirements stage became up to 80% faster.

At Wellu, a group challenge app UEEK built end to end, an assistant answers support first and hands sensitive cases to a person, and AI models chosen per task summarize the day for the team based on real data.

Frequently asked questions

Does RAG end AI hallucinations?

It can reduce errors when retrieval finds relevant, up-to-date passages. The model can still misread an excerpt or combine two pieces of information the wrong way. Citing the source, instructing the model to say when it did not find the answer and testing with real questions are the measures that help most.

Is RAG the same as training AI on company data?

No. With RAG the model does not change: the documents stay in an index and only the excerpts needed go with each question. Training or adjusting the model with company data is fine-tuning, explained above.

Does it work with PDFs, spreadsheets and scanned documents?

It works with almost any text format. PDFs and scanned documents need their text extracted first, and the quality of that extraction affects the answer. Spreadsheets with numbers that change every day usually work better with a direct query to the source system.

Do I need a special database?

The search index can live in a database built to search by meaning, known as a vector database, or in search features that many regular databases already offer. The choice depends on the volume of documents, the permissions and the infrastructure the company already has.

How long does it take to put RAG into use?

It depends on how organized the documents are. With the sources defined, a first rollout, with a small group and tests with real questions, fits within the same timeframe as an agent in production at UEEK, up to 4 weeks. Organizing scattered documents is usually the part that takes longest.

Where should I start?

With the question the team repeats most and that already has a written answer in some document. The AI Map is free, takes about 10 minutes and shows the opportunities ordered by effort and impact.

How UEEK can help

UEEK organizes the sources with the company's team, builds the document search, chooses and tests the models and puts AI agents in production in up to 4 weeks, with sources cited in the answers, permissions per profile, human approval at sensitive points and tests with real questions. Afterwards, agent operations tracks hits, errors, unanswered questions and usage cost month by month. To find out where an assistant that answers from your documents would make a difference, start with the AI Map. UEEK has 14 years in the market, more than 200 clients in 6 countries and more than 500 projects delivered, from local businesses to Itaú.

Other terms and guides on systems, AI and security are in the UEEK glossary.

Topics

  • RAG
  • what is RAG
  • retrieval-augmented generation
  • RAG vs fine-tuning
  • glossary

Want this in production?

UEEK does this kind of work in Agent in production.

See the solution