Concepts · Humans and machines
RAG helps a model check outside sources before it answers. Learn how retrieval augmented generation works and why it is not memory.
What Is Retrieval Augmented Generation and How It Works
Retrieval augmented generation, usually called RAG, is a simple idea.
Before a model answers, it looks something up.
That is the core of it. Instead of asking a model to answer only from what it learned during training, a RAG system gives it fresh information at the moment of the question. The model searches a document collection, pulls back the most useful passages, and writes an answer using those passages.
The easiest way to picture it is an open-book test. A closed-book test asks you to answer from memory. An open-book test lets you check the page first. RAG gives the model the page first.
This matters because fluent answers can still be wrong. A support bot can sound confident and still quote a refund policy that no longer exists. The problem is not always the model. Often the problem is that the model was never given the right evidence.
RAG tries to fix that by adding a search step before the writing step.
How RAG Works
A RAG system has three main steps.
First, it makes documents searchable. A team might take help center articles, product docs, tickets, PDFs, or wiki pages and split them into smaller pieces. Those pieces go into a search index. Some systems search by keywords. Some search by meaning. Many use both. This search-and-ranking step is the information retrieval part of RAG.
Second, it retrieves. When a user asks a question, the system looks for the pieces that seem most relevant. This is the most important step. If the search brings back the wrong material, the model starts from the wrong place.
Third, it generates. The model reads the retrieved passages and writes an answer. If the passages are good, the answer has a better chance of being grounded. If the passages are weak, stale, or incomplete, the answer can still go wrong.
So RAG is not magic dust sprinkled on a model. It is a pipeline:
- Find the right material.
- Give it to the model.
- Ask the model to answer from it.
A useful short version is: search first, then write.
Common RAG Setups
Most RAG systems use the same basic pattern, but teams add more steps as the work gets harder.
A simple setup has one index, one search step, and one answer. This can work well when the documents are clean and the questions are predictable. A small help center is often fine this way.
A stronger setup may rewrite the user's question before searching, search more than one way, rank the results again, or trim noisy passages before they reach the model. These steps add complexity, but they solve real problems.
For example, a person may ask, "Can I get my money back?" The policy may use the word "refund" instead of "money back." A better RAG system understands that these are related and searches accordingly.
Some systems go further and let the model search more than once. That helps when the task has several parts. It also creates more places for the system to wander, so it needs tighter checks.
The rule is simple: add machinery only when the documents or questions require it.
Why Retrieval Matters Most
People often blame the model when a RAG answer is bad. Sometimes they are right. But in many systems, the first failure happens earlier.
The model cannot use a document it never sees.
Think of someone cooking dinner from whatever is on the counter. If the right ingredients are missing, a better cook can only help so much. The meal may still be disappointing because the shopping step failed.
RAG has the same problem. The generator can only work with the evidence the retriever brings back.
That is why teams measure retrieval and generation separately. Retrieval asks, "Did we find the right evidence?" Generation asks, "Did the model use that evidence faithfully?"
Those are different questions. Mixing them together hides the problem.
If the right source never appears, improve retrieval. If the right source appears but the answer still drifts, improve generation, prompting, or evaluation.
Where RAG Breaks
RAG usually breaks in ordinary ways.
Sometimes the document was split badly. The answer sits across two chunks, and neither chunk makes sense alone. Sometimes the index is stale. The source document changed, but the search system still has yesterday's version. Sometimes permissions are wrong, and the system retrieves something the user should not see.
There is also a quieter failure. The system may retrieve something close to the answer, but not quite right. The model then writes a confident answer from partial evidence. That can be worse than an obvious failure, because it looks finished.
This is why bigger context windows do not remove the need for retrieval. You can stuff more text into the prompt, but that does not mean the model will focus on the right part. It can also become slow and expensive. More paper on the desk does not help if nobody knows which page matters.
Good RAG is less about having a huge pile of documents and more about putting the right page in front of the model at the right time.
RAG Versus Long Context
Another way to help a model is to paste a lot of material into the prompt and let the model sort through it. This is long-context prompting. It is useful, but it is still different from AI memory.
Long context can be useful. If the task depends on one large document, giving the whole document to the model may be the simplest answer.
But long context is not a replacement for retrieval. It can be slower and more expensive, and it can still bury the useful part under too much surrounding text. Putting every paper on the desk is not the same as opening the right page.
RAG is usually better when the source material is large, changing, or split across many systems. Long context is usually better when the source material is small enough, stable enough, and worth reading as one piece.
The practical question is not which method sounds more advanced. The question is which method gives the model the right evidence with the least waste.
RAG Is Not Memory
RAG and memory are related, but they are not the same. The shorter comparison is covered in RAG versus AI memory.
RAG retrieves information for the current answer. It is mostly about the present question.
Memory carries useful information forward. It is about what should remain true, useful, and available after this interaction ends.
A notes app is a useful everyday comparison. Searching your notes can help you answer a question right now. But memory is not just storage or search. Memory also means deciding what deserves to stay in the notes, when something should be updated, and when an old note should stop shaping future decisions.
In AI systems, that difference matters.
A RAG system might retrieve the current refund policy and help answer a customer. A memory system might remember that this customer has an open exception, a verified preference, or a history that changes how the next conversation should be handled.
The first is document grounding. The second is continuity.
If a system forgets everything after the answer, it may still be useful. But it is not memory. It is retrieval.
How to Choose a RAG Setup
Start with the documents, not the model.
Ask what belongs in the index. Ask what should stay out. Ask how fresh the index needs to be. Ask which permissions must be enforced before a passage reaches the model. If this sits inside a product, the Memory API boundary matters too: what can be retrieved, written back, updated, or removed?
Then look at chunking. A good chunk should preserve meaning, not just fit a token limit. If a person would need the next paragraph to understand the current one, the model probably will too.
Then test retrieval directly. Give the system real questions and check whether the right evidence appears near the top. Do this before judging answer quality. Otherwise you will keep tuning the writer when the search step is the real problem.
Finally, keep measuring it. RAG systems drift. Documents change. User questions change. The index gets stale. A system that worked in a demo can fail quietly under real work.
The practical checklist is short:
- Does the index contain the right material?
- Are the chunks meaningful?
- Does retrieval find the right evidence?
- Does the answer stay faithful to that evidence?
- Are freshness, permissions, and latency acceptable?
If the system will be used inside a company, add two more questions:
- Who is allowed to see each source?
- What happens when a source changes?
Those questions are not decoration. They decide whether the system can be trusted in real work.
The Main Idea
RAG means the model checks its sources before it speaks.
That makes it useful for support bots, research assistants, internal search, and any workflow where the answer depends on information outside the model's weights. But RAG does not solve every problem in AI memory. It can ground an answer now. It does not, by itself, decide what should persist, change, or fade over time.
Search before writing is powerful.
Remembering is a bigger job.
Sources
- Lewis et al., Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks
- Gao et al., Retrieval-Augmented Generation for Large Language Models: A Survey
- A Systematic Review of Retrieval-Augmented Generation Evaluation