Retrieval-Augmented Generation
In this article
- Explain what retrieval-augmented generation adds to the request a model reads, and why the model's parameters stay the same.
- Tell a tool that only reads information from a tool that changes something.
- Decide from what a failing answer lacks whether the fix is retrieval, the prompt or structured output, application code, or a tool that acts.
- Name the cost and the limits of adding retrieval to an application.
- Terms defined here: retrieval, corpus, retrieval-augmented generation.
Overview
A customer writes to a support assistant: "My router arrived 20 days ago. Can I still get a refund?" The assistant answers that refunds are possible for 30 days. Brightline's refund rule allows 14. The customer now holds a confident, polite, wrong promise.
The assistant belongs to Brightline, a home-internet provider that runs a support assistant on its website. The assistant answers customers, can look up an order, can issue a refund of at most $50 and can hand a conversation to a person on the support team. It answers from about 400 Brightline help pages. For that work it has tools, functions the application runs when the model asks for them: search_help, lookup_order and issue_refund, plus one that passes the conversation to a person. Brightline, its pages, its orders and every number here are invented.
Where did 30 come from, and what would have produced 14? Once you see that, you can look at any failing answer and tell whether a lookup fixes it or something else does.
What the model has on one call
The assistant is built on a large language model, a program shaped by training on huge amounts of text that writes a reply to the text it is given. When it writes, it draws on two things. One is its parameters, the internal numbers that training set and that stay fixed while it reads your request. The other is the request on this call. A model's replies are limited to the context it receives and what it took from training. [1] It sees only what is in the request on this call and keeps nothing from one call to the next. Anything else does not exist for it.
So the refund question arrived alone. Nothing in the request said that Brightline's current page, help-refunds, updated in 2025, allows 14 days after delivery. The model did not misremember Brightline's rule; it never had it. It wrote the kind of answer that refund questions in general make likely.
Information goes missing from a model in three ways, and Brightline has one of each:
- Fresh. Training stops at a cutoff, so the model knows nothing that happened after it. [1] Brightline's refund page changed after the text the model learned from; an archived 2023 version allowed 30 days.
- Private. Training data leaves out confidential material. [1] Customer C-204's order 8841, a BL-R7 Wi-Fi 7 router priced $129.00 and delivered 20 days ago, exists only in Brightline's order system, and only that customer's own session may read it.
- Specific to the business. Public training text does not hold one company's own rules, such as Brightline's rule that a refund above $50 needs a person's approval. The model does not already know data like this, and no wording of the question can supply it. [2,3]
Looking it up at answer time
All three gaps close the same way: when the question arrives, fetch what is missing and put it into the request. That step is retrieval. Its source can be anything the system can read: a search over the help pages, a query to the order database, a call to another service's API.
The set of documents a system searches is its corpus. Brightline's corpus is its 400 help pages, each with an id and an updated date.
Retrieval-augmented generation, or RAG, builds this lookup into answering. The application runs a search, packs the best results together with the question into the prompt and sends that to the model, which writes from it. [2,3] The parameters never change. Only the request does.
Notice what makes a tool count as retrieval: what it does, not who calls it. search_help and lookup_order only read, so calling them is retrieval. issue_refund moves money, and passing the conversation to a person changes who handles it. Those are actions. A model can describe an action with side effects, but only a tool can carry it out. [4]
Here is the refund question both ways, as the application sends it.
On the right, the evidence arrives through a tool round trip. In Claude's API, the model never runs a tool itself: its response asks for one, your code runs it, and the output goes back on the next request. [4] Here is that trace for the refund question:
| Step | Who | What travels |
|---|---|---|
| 1 | Application to model | The question and the list of tools |
| 2 | Model to application | A tool_use block asking for search_help with the question as its argument |
| 3 | Application | Runs the search over the help pages |
| 4 | Application to model | Earlier messages plus a tool_result block: 3 sections, among them help-refunds#2, updated 2025 |
| 5 | Model to application | "Twenty days is past the 14-day window; I can pass you to a person." |
Steps 2 and 4 use the tool_use and tool_result blocks the API defines. [4] help-refunds#2 holds the 14-day rule and the rule that a refund above $50 needs a person's approval. With the 14-day rule in front of it, the same model gives the right answer: 20 days is 6 days past the window.
The id help-refunds#2 (the second section of help-refunds) and the page date are the evidence's provenance: where it came from and where it can be loaded again. Open the request trace, the saved record of the exact request and the response, and you see which retrieved evidence the model received and how old it was. If the reply is wrong, that record is the first place to look.
What retrieval does not fix
A lookup gives the model better material. It does not make the answer right. Grounding in data you can check reduces made-up answers [1], and models can still write inaccurate replies with the right content in front of them. [3] So a RAG answer can still contain a hallucination, a false or made-up statement in text a model wrote.
The retrieved text brings its own risks:
- It can be out of date. A stale page quoted with a source id looks trustworthy. The date travels with the evidence so that someone can tell.
- It can belong to someone else. Only data the asking user is authorized to see may become evidence, so the check happens on every retrieval. [5] Order 8841 is for C-204's session only.
- It is data, not instructions. A document in the corpus can carry planted instructions that steer the reply when a query returns it, and RAG does not fully prevent that. [6]
When a RAG answer is wrong, the fault can lie in what was looked up or in how the model used it. The search can bring back the wrong page, or the right page can sit in the request while the reply ignores it. Expect to check both halves.
What a lookup costs
A tool call always adds one more model request and reply. [4] In Brightline's assistant, a search_help call costs steps 2 to 4 above, and its 3 results add about 1,500 tokens to the request, roughly 500 per section. Those tokens are billed as input and take space in the context window, the most one request can hold, counting what goes in and what comes back.
The third cost does not show on any bill: someone must keep the corpus current, and Brightline edits a few pages a week. So add retrieval because information is missing, not because the application happens to use a model.
Five failures, five levers
Retrieval fixes one kind of failure. For each failing answer, ask what it lacks. Missing, stale or proprietary knowledge calls for changing what the request carries; a wrong format or inconsistent behavior calls for changing how the model behaves. [7,8] Five Brightline failures, each shown as it happened. Try to name the fix before you read it.
Case 1. The refund question with no search_help call; the reply says 30 days. The answer lacks a fact that sits on a help page. Retrieve it, as the trace above does.
Case 2. A customer asks, "Is my order 8841 still in the refund window?" The reply says it cannot see the order. What is missing? Two facts, from two places: the delivery date, in C-204's private order record, and the 14-day rule, on help-refunds#2. Neither alone answers the question. Both are retrieval: lookup_order for the record, search_help for the rule. And because $129.00 is above $50, any refund would also need a person's approval.
Case 3. The order-status reply comes back with the right facts in the wrong shape: it breaks the JSON schema the application's code expects, the fixed set of named fields the code reads. More help pages cannot fix a shape. Change the prompt first, or turn on structured output, an API setting that makes replies follow a JSON Schema you give, as the Gemini API offers. [9] Even then, check the values in your code: a reply can match the schema and still be wrong. [9] If a stable, repeated behavior still fails, fine-tuning, further training of a model on examples for one task, is the next step; unlike the other levers, it changes the model's parameters. [7,8] It takes expertise, and prompting is the baseline to beat first. [8] Choosing among these for a real system takes more evidence than five small cases give.
Now two at once. Before you read on, name the lever for each.
Case 4. A customer is owed a credit for 3 days of outage. The assistant writes an amount, and it must be exact. Case 5. A customer writes, "Cancel my technician visit." The assistant replies that the visit is cancelled. None of its four tools touches a technician visit, so nothing was cancelled.
Neither lacks a fact or a format. Case 4 lacks an exact computation: application code must compute the credit. The code may read the credit rule through a lookup, but the code does the arithmetic, and the model only reports the result. Case 5 lacks an action. A change in another system needs a tool that acts on it, the way issue_refund acts on payments. [4] No help page about visits can cancel one, however well it is retrieved.
When the answer lacks information the system can read at answer time, retrieve it into the request with its source. For the other three kinds, a longer request does not supply the missing computation, format or action.
| Case | What the answer lacks | Lever |
|---|---|---|
| 1. 30-day window | A fresh fact on a help page | Retrieve with search_help |
| 2. Order 8841 | A private record and a business rule | Retrieve with lookup_order and search_help |
| 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 |
Sources
- Microsoft Generative AI for Beginners: RAG and Vector Databases. Microsoft. Checked 24 Oct 2026.
- Design and Develop a RAG Solution on Azure. Microsoft (Azure Architecture Center). Checked 21 Nov 2026.
- Microsoft Learn: RAG and indexes in Microsoft Foundry. Microsoft. Checked 24 Oct 2026.
- How tool use works. Anthropic. 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.
- OpenAI API docs: Optimizing LLM accuracy. OpenAI. Checked 24 Oct 2026.
- Microsoft Generative AI for Beginners: Fine-Tuning Your LLM. Microsoft. Checked 24 Oct 2026.
- Structured outputs (Gemini API). Google. 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.