Retrieval-Augmented Generation
In this article
- Explain what retrieval-augmented generation changes in the request a model reads, and what it leaves alone.
- Tell a tool that looks information up from a tool that changes something.
- Decide from what a failing answer lacks whether the fix is a lookup, the prompt or structured output, application code, or a tool that acts.
- Name the evidence a request must carry before the model can answer a question that depends on it.
- Terms defined here: retrieval, corpus, retrieval-augmented generation.
Overview
A customer asks a support assistant whether a router that arrived 20 days ago can still be refunded. The assistant says yes, within 30 days; the company’s refund page allows 14.
In an invented example, Brightline, a home-internet provider, runs a support assistant on its website that answers customers. It answers from about 400 Brightline help pages.
The fix is retrieval-augmented generation (RAG): look the right page up when the question arrives and hand it to the model together with the question. Once you see what that adds to the request the model reads, you can tell from any failing answer whether a lookup fixes it or another lever does.
What the model has on one call
A large language model, a program shaped by training on huge amounts of text that writes a reply to the text it is given, answers from two places. One is its parameters, the internal numbers, set by training, that decide what it writes. The other place is the request itself. Replies are limited to those two: what the call carries and what training left behind. [2] Nothing else exists for the model on that call.
So where did 30 come from? The question arrived with no refund page beside it, so the model wrote the kind of reply its training makes likely for a refund question. Nothing in the request said that the current page, help-refunds, updated in 2025, allows 14 days. It never had Brightline's page to misremember.
Information can be missing from both places for three reasons, and Brightline has one of each:
- Fresh. Training stops at a cutoff, so later changes never reach the parameters. The refund page changed after the text the model learned from. [2]
- Private. Training text leaves out confidential records. Customer C-204's order 8841, a BL-R7 Wi-Fi 7 router delivered 20 days ago, lives in Brightline's order system and nowhere else. [2]
- Specific to the business. One company's own rules, such as Brightline's rule that a refund above $50 needs a person's approval, are data the model does not already know. [1]
Looking it up at answer time
All three gaps close the same way: fetch the missing information while the question is answered and put it in the request. That fetching is retrieval, and its source can be anything the system can read: a search over help pages, a database query, a call to another service. [2,4]
The documents a system searches make up its corpus. Brightline's corpus is its 400 help pages. [2]
Retrieval-augmented generation, or RAG, makes this lookup part of answering, for data the model does not already know: the application takes the question, runs a search, adds what it found to the request and calls the model. The parameters stay as they were; only the request changes. [1,3]
Here is the refund question both ways. On the right, the application has searched the help pages with search_help and got back help-refunds#2, and the request carries that retrieved evidence next to the question, with its source id (a label for one section of one page, here the second section of help-refunds) and page date.
With the 14-day rule in front of it, the assistant says 20 days is outside the window and offers a person.
The id and date record the provenance of the evidence: where it came from and where it can be loaded again. Anyone who opens the request trace, the saved record of the exact request and its reply, sees which page the model got and how old it was.
Five failures, five levers
Brightline's assistant has four tools, functions the application runs: search_help, lookup_order, issue_refund for a refund of at most $50, and one that hands the conversation to a person on the support team. The application runs search_help on every question; the model asks for the other three. [4] A tool counts by what it does. search_help and lookup_order only read, so calling them is retrieval. issue_refund moves money, so it is an action, and so is handing the conversation to a person.
Retrieval fixes one kind of failure. For each of five failures, ask what the failing answer lacks. Case 1 is the figure: fresh information on a help page, so retrieve it.
Case 2. "Is my order 8841 still in the refund window?" The reply lacks the delivery date, which sits in the customer's private order record that only their own session may read. Retrieve it with lookup_order, a tool that only reads. On the Claude API, such a lookup is a round trip, and each step travels as a block, a labelled part of a message. [4]
- The model's response contains a
tool_useblock that names the tool,lookup_order, and its argument, order number 8841. [4] - Your application runs the lookup against the order database. The model never runs anything itself. [4]
- The next request carries the earlier messages plus a
tool_resultblock holding the order record. [4]
Before the model writes, the request must hold two pieces of evidence: the order record with the delivery date, from the order system, and the 14-day rule in help-refunds#2. Neither alone answers the question.
Case 3. An order-status reply breaks the JSON schema the application expects, the fixed list of named fields its code reads from each reply. The facts are right and the shape is wrong, so more help pages would not help. Fix the prompt, or turn on structured output, an API setting that makes replies follow a schema you provide; Gemini offers it for JSON Schema. Even then, check the values in your code. [5]
Only if a stable, repeated behavior still fails do you reach for fine-tuning, further training of a trained model on examples for one task. Unlike the other levers, it changes the model's parameters, not the request. It costs data, compute and expertise, and prompting is the baseline to beat first. [3] Choosing among all the levers for a real system takes more evidence than five small cases.
Now two more. Before reading on, name the lever for each. Case 4: a customer is owed a credit for 3 days of outage, and the amount must be exact. Case 5: a customer writes, "Cancel my technician visit."
Neither lacks information or a format. Case 4 lacks an exact computation. In this made-up assistant, the team will not take an exact amount from a written reply, as it would not take 30 days from one, so application code computes the credit; the code may read the credit rule through a lookup, but the code does the arithmetic, and the model reports the result. Case 5 lacks an action, and only a tool can carry out a change with side effects. [4] The assistant needs a tool that acts on the booking system, as issue_refund acts and search_help does not; a help page about visits cannot cancel one.
Side by side:
| Case | What the answer lacks | Lever |
|---|---|---|
| 1. 30-day window | Fresh information on a help page | Retrieve with search_help |
| 2. Order 8841 | A private order record | Retrieve with lookup_order |
| 3. Broken JSON | A format | Prompt or structured output, then fine-tuning |
| 4. Outage credit | An exact computation | Application code |
| 5. Cancel a visit | An action | A tool that acts |
When the answer lacks information the system can read at answer time, retrieve it into the request with its source; for the other three rows, a longer request only costs more.
What retrieval does not fix
A lookup gives the model better material, and RAG reduces made-up answers by grounding them in data you can check. [2] Reducing is not removing: a reply can still hold a hallucination, a false or made-up statement in text a model wrote.
Retrieved text brings its own risks. A page can be out of date, and unless the request carries its date, the model cannot tell. A record can belong to another customer: only data the asking user may see should become evidence. And retrieved text is data, not instructions; if someone plants instructions in a document of the corpus, a query that returns it can steer the reply, and RAG does not fully prevent that. [7,8]
So when a RAG answer is wrong, the fault can lie in what was looked up or in how the model used it. Expect to check both.
What a lookup costs
The two kinds of lookup cost different things. A search the application runs adds tokens to the request: in Brightline's case, a search_help result of the top 3 chunks, the three best-matching passages, adds about 1,500 tokens (a token is a word or part of a word, the unit models read and bill by). A tool the model asks for adds a round trip: the model asks, the application runs the tool, and a new request follows. [4] Gemini File Search, for one, bills retrieved text at its normal rate for context tokens. [6] The context window, the most a single request can hold, sets the ceiling. [2,3]
Then someone has to keep the corpus current, or the assistant quotes old rules behind a source id that makes them look trustworthy. Add retrieval because information is missing, not because the application uses a model.
Sources
- Design and Develop a RAG Solution on Azure. Microsoft (Azure Architecture Center). Checked 21 Nov 2026.
- Microsoft Generative AI for Beginners: RAG and Vector Databases. Microsoft. Checked 24 Oct 2026.
- Microsoft Generative AI for Beginners: Fine-Tuning Your LLM. Microsoft. Checked 24 Oct 2026.
- How tool use works. Anthropic. Checked 24 Oct 2026.
- Structured outputs (Gemini API). Google. Checked 24 Oct 2026.
- Gemini API: File Search tool. Google. Checked 24 Oct 2026.
- Design a Secure Multitenant RAG Inferencing Solution (Azure Architecture Center). Microsoft. Checked 21 Nov 2026.
- LLM01:2025 Prompt Injection. OWASP GenAI Security Project. Checked 24 Oct 2026.
Check yourself
Check yourself
Question 1 of 13
What does retrieval-augmented generation change in a call to a language model?
Your first check counts towards your result.