See It Flow

Retrieval Augmented Generation · Module 1

Why RAG Exists

Why runtime retrieval became a practical way to connect language models to current, private, and traceable knowledge.

Mangesh MandlikLast updated:

Visual Experience

What Standalone LLMs Miss

Watch how a normal workplace question exposes the gap between a model's training data and the information a real system needs at answer time.

Retrieval Augmented Generation · Module 1

Why RAG Exists

Why runtime retrieval became a practical way to connect language models to current, private, and traceable knowledge.

Mute narration
1 / 20

01 ·A Real Question

A simple enterprise question: "What is our company's latest leave policy?"

🧑What is our company's latest leave policy?
🧠

LLM has never seen this

A normal enterprise question becomes a problem for an ungrounded model

The company-specific answer is not inside public training data.

"A real enterprise question — one that any employee might ask."

Previous scene
Play
Next scene
Mute narration
Replay from Scene 1

Why Retrieval-Augmented Generation (RAG) Exists

Retrieval-augmented generation (RAG) exists because a language model cannot be trusted to recall facts that change, that are private, or that must be traceable to a source. A RAG system looks up relevant evidence at question time, places that evidence in the model's input, and asks the model to answer from it. The model still does the language work; the lookup supplies the facts.

So why use RAG instead of fine-tuning an LLM? Use RAG when the answer depends on private or frequently updated factual knowledge that must be cited, because the documents can change without retraining anything. Use fine-tuning when you need to change behavior, such as tone, output format, or a narrow skill. RAG is the right tool when the answer lives in a body of documents that changes, is too large to paste into every prompt, and has to be attributable. It is the wrong one for live account data or for a short, stable set of rules.

A Support Answer That Sounds Right and Is Not

A payments company runs an internal support assistant. A customer writes: "I was charged twice for order 8472. Am I eligible for a refund, and what should support do?" The assistant is a general-purpose model with a polite system prompt and nothing else. It answers:

Answer from the model's weights alone
Yes. Duplicate charges are refundable. Ask the customer to submit a refund
request form, and refunds are issued within 10 business days.

Fluent, confident, specific. It is also a description of an older policy.

The refund policy was revised on 2026-10-01. Version 4 (POL-REF-004) says confirmed duplicate captures are refunded automatically within 5 business days, with no request form, and adds an exception for customers covered by EU consumer rules. Version 3 (POL-REF-003), with the form and the 10 days, is what the model's training data happened to contain, or what it reconstructed as the typical shape of a refund policy. An agent who follows the answer tells the customer to fill in a form that no longer exists and quotes a deadline that is twice as long as the commitment the company now makes.

Nothing was malfunctioning. The model produced the most plausible continuation of a refund question, and plausible text carries no information about whether it is current. Eloquence is a property of the writing; evidence is a property of the source. A system that needs the second cannot be built by improving the first.

Two different questions are hiding in the request
"Am I eligible for a refund?" is a question about policy, which lives in documents. "Was I charged twice for order 8472?" is a question about a fact in a payments system. No amount of reading policy documents can establish the second. We will keep returning to this distinction because it decides what belongs in retrieval and what does not.

What a Standalone Model Actually Has Access To

When a model answers, it can draw on exactly three things. The first is its parameters: billions of weights adjusted during training. These encode statistical regularities of the training text, and some facts can be recovered from them, but the weights are not a database. They do not store a verbatim copy of every source, they cannot be queried for provenance, and a fact that appeared rarely or inconsistently may come back blurred or wrong. The second is the current input: the system prompt, the conversation, and anything pasted in, bounded by the context window. The third is any tool results that the application deliberately returns into that input, such as the output of an API call.

Your enterprise knowledge base is none of these by default. Training finished before your latest policy existed, and your private documents were never in the training set. The knowledge cutoff gives you stale knowledge, not merely missing knowledge: an older version of your policy, or a public document that looks similar, can be absorbed and reproduced with the same confidence as a current one. There is also no source attached. When the model says "10 business days", you cannot ask which document or which version that came from, because it did not look anything up. This lack of attribution is a core reason these answers are hard to audit, and it is the root of the failures described in the Hallucinations lesson.

The figure below shows the three channels and where a RAG system and a tool attach.

The three channels a model answers from, and where RAG plugs inThe language model can use its parameters, its current input, and tool results returned into that input. The enterprise knowledge base is none of these by default. RAG retrieval reads the knowledge base at question time and writes the evidence into the current input; a tool call reads a system of record and returns its result. The weights are not changed.Parametersfixed at training, no sourcesCurrent inputprompt + historyLanguage modelTool resultsreturned into inputRAG retrievalat question timeKnowledge basenever in the weightsSystem of recordlive valuesevidenceAPI call
The three channels a model answers from, and where RAG plugs in. RAG leaves the weights alone and delivers documents through the input channel; live values arrive through the tool channel. Nothing connects the knowledge base to the model unless one of these steps does it.

Everything RAG does follows from these three channels. It does not change the weights. It uses the second channel, the input, to deliver the right facts at the right moment.

Why Not Just Paste All the Documents?

The obvious alternative is to skip retrieval and include every policy document in every prompt. It is worth taking seriously, because for small corpora it is the correct answer, and understanding where it breaks tells you what retrieval is for.

Suppose the support knowledge base has 600 documents averaging 3,000 tokens: 1.8 million tokens. That does not fit in most context windows today, so you would have to choose what to include, and choosing is retrieval. Even if a corpus does fit, you pay for every input token on every request, and processing a long prompt adds latency before the first output token appears. A question that needs two paragraphs of evidence would be billed and delayed as if it needed the whole library. Models also do not use all positions in a long input equally well; relevant text surrounded by thousands of tokens of unrelated policy can be overlooked.

Slide the corpus size to see what each request would carry.

600
Input tokens per request: paste everything versus retrieve three passagesWith 600 documents averaging 3,000 tokens, pasting everything sends 1,800,000 tokens on every request. Retrieving three passages of about 350 tokens (illustrative) sends about 1,050, which is 1714 times fewer.Paste all1,800,000 tokensRetrieve 31,050 tokens
Input tokens per request: paste everything versus retrieve three passages. Document count and 3,000 tokens per document follow the lesson's example; 3 passages × 350 tokens is an illustrative retrieval size. Whether the pasted corpus fits at all depends on the model's context window.
Pasted per request
1,800,000
600 × 3,000
Retrieved per request
1,050
3 × 350, illustrative
Ratio
1714×
input tokens billed

Version conflicts are a quieter problem. A knowledge base usually contains several revisions of the same policy, drafts, regional addenda, and superseded pages. If everything is pasted in, the model must decide which statement wins, and nothing in the raw text tells it that POL-REF-003 is retired. Finally, there is authorization. A prompt that contains every document gives every user whatever the model chooses to reveal. Access control must be enforced before text reaches the model, which means somebody has to select, per user, which documents are even eligible. That selection step is again retrieval.

So the honest boundary is this: when the whole relevant corpus is small, stable, and visible to every user, put it in the prompt (ideally with prompt caching if your provider supports it) and stop. When it is large, changing, or permissioned, you need a step that chooses what goes in.

Retrieval Augmentation as a Design Response

RAG separates two jobs the model is bad at combining: knowing and writing. Knowledge moves into a store you control, where it can be updated, versioned, permissioned, and cited. At query time the system retrieves the few passages relevant to this question, supplies them as evidence, and instructs the model to answer from that evidence and to say so when it is insufficient.

Retrieval-augmented generation in three movesA user question goes to a retrieval step that searches a knowledge store. The retrieved passages and the question are assembled into a prompt. The language model generates an answer that cites the passages. The knowledge store is updated independently of the model.QuestionRetrieveat query timeAssembleevidence + questionLLMgenerate + citeAnswerKnowledge storeversioned, permissioned
Retrieval-augmented generation in three moves. A user question goes to a retrieval step that searches a knowledge store. The retrieved passages and the question are assembled into a prompt. The language model generates an answer that cites the passages. The knowledge store is updated independently of the model.

Notice what this definition does not say. It does not say the store is a vector database, and it does not say embeddings are involved. The evidence might come from keyword search over an inverted index, a SQL query, a vector similarity search, or a combination. In practice many systems use dense vector search together with lexical search because each catches things the other misses. The RAG Pipeline lesson draws the whole system, and later lessons explain each part. For now, "retrieval" means any mechanism that chooses evidence for this question.

The First Grounded Answer

Here is the same support request with retrieval in front of the model. The system searches the policy collection and finds one passage that matches the question about duplicate charges. It arrives with metadata that the application, not the model, attached at indexing time:

Retrieved evidence (illustrative record)
[E1] source_id: POL-REF-004   version: 4   effective: 2026-10-01
     heading: "Refunds > Duplicate charges"
     text: "When two settled captures exist for the same order reference,
            the second capture is refunded automatically within 5 business
            days. No refund request form is required. Customers covered by
            EU consumer rules may additionally request a written
            confirmation of the refund."

The assembled prompt tells the model to answer only from the numbered evidence and to cite it. The response becomes:

Grounded response
Under the current refund policy, a confirmed duplicate capture on the same
order is refunded automatically within 5 business days, and no request form
is needed [E1]. Support should therefore not ask the customer to fill in a
form.

I cannot tell from the available documents whether order 8472 was actually
charged twice. That needs a lookup in the payments system. If two settled
captures are confirmed, the policy above applies.

Three things changed. The deadline and the missing form match version 4, because that is the text the model was shown. The claim carries a marker, so a reviewer can open POL-REF-004 and check. And the answer separates what the documents establish from what they cannot: nothing retrieved says anything about order 8472, so the model was told to state that gap rather than infer it. That last behavior does not appear by itself; the instruction to abstain, and a test that confirms it holds, are part of the system. The Context Injection lesson covers how to build it.

What RAG Fixes, and What It Leaves Open

Four problems motivate RAG. Each is improved by retrieval, and each leaves a residual failure that you have to engineer for.

Freshness

If the index contains version 4, the answer can reflect version 4 without retraining anything. But a model is not automatically current: the index is only as fresh as the ingestion job that last ran. If the policy is edited at 09:00 and the nightly sync runs at 02:00, the answer is wrong for 17 hours even though the system is "RAG-based". Freshness in RAG is measured as lag between a source change and the moment queries can see it, and it needs a number and an alert.

Freshness lag after a policy editThe policy is edited at 09:00. The nightly sync runs at 02:00 the next day, 17 hours later. For those 17 hours the index still holds the old version and answers use it; after the sync the index holds the new version.06121724hours after the 09:00 edit; the 02:00 sync lands at hour 17Source of truth: newedited 09:00Index: old version17 h lagIndex: new version
Freshness lag after a policy edit. Freshness is the gap between the two bars. It needs a measured number and an alert, not an assumption that a RAG system is current.

Private and domain-specific knowledge

Internal policies, tickets, and runbooks can be searched without ever being used for training. The residual risk is access: a retriever that finds a document the user may not read has leaked it into the prompt, and possibly into the answer. Permissions have to be enforced in the retrieval layer against a trusted identity, not requested politely in the prompt.

Traceability

Because evidence has an identifier, an answer can point to it. The residual risk is that a citation marker proves only that the model wrote a marker. It does not prove that the cited passage supports the sentence. A careful system checks claims against the cited text rather than trusting the marker.

Selective context use

Sending two or three relevant passages instead of a whole library reduces cost and distraction. The residual risk is that the right passage may not be selected at all. If retrieval misses the one clause that contains the exception, the model sees a plausible but incomplete picture and answers confidently from it. Retrieval relevance is also not truth: a retrieved passage can be outdated, wrong, or contradicted elsewhere.

What RAG does not do
RAG reduces unsupported answers by giving the model something to be supported by. It does not eliminate hallucination, and it does not make a system real-time. Real-time behavior comes from how quickly your ingestion reflects changes, and from tools that read live systems.

Choosing Between Direct Prompting, Long Context, Tools, Fine-Tuning, and RAG

These approaches are often presented as competitors, but they answer different questions. A useful way to choose is to ask, for the information the answer depends on: how big is it, how often does it change, does it need to be exact, and who may see it?

Decision flow for choosing an approachStart with what the answer depends on. If it is general public knowledge and the risk is low, call the model directly. If it is an exact live value such as a payment status, call a deterministic tool or database query. If it is a small, stable, shared document set, place it in the prompt. If it is a large or changing document collection that needs citations or per-user access, use retrieval. If you need a stable style or format rather than new facts, consider fine-tuning. Real applications often combine retrieval and tools.What does the answer need?General knowledgelow riskExact live valuepayment statusSmall, stable docssame for everyoneLarge or changing docscite, permissionsDirect LLM callSQL / API toolLong-context promptRAGcombine
Decision flow for choosing an approach. Start with what the answer depends on. If it is general public knowledge and the risk is low, call the model directly. If it is an exact live value such as a payment status, call a deterministic tool or database query. If it is a small, stable, shared document set, place it in the prompt. If it is a large or changing document collection that needs citations or per-user access, use retrieval. If you need a stable style or format rather than new facts, consider fine-tuning. Real applications often combine retrieval and tools.

A direct call is fine for general explanations, drafting, and tasks where being slightly off is cheap. Long-context prompting suits a bounded, stable, non-sensitive set such as one product manual. Deterministic tools are required whenever the answer is an exact value held by a system of record: a balance, an order status, whether two captures exist. A model asked to guess these will guess, and a document store cannot tell it. Fine-tuning, covered in the Fine-Tuning lesson, shapes behavior such as tone, format, or a narrow skill. It is a poor way to carry facts that change monthly, because every update becomes a training run and the result still has no citations. RAG is for locating and grounding answers in documents that evolve.

These combine well. In our running case, the policy passage about duplicate captures belongs in retrieval, and the question of whether order 8472 has two settled captures belongs in an authorized payments lookup that returns structured data. The best answer uses both: the tool result establishes the fact, the retrieved policy establishes the consequence, and the model composes them. Neither alone can answer the original request.

Figure: the running case as one request that combines a tool call and retrieval.

Answering the running case with a tool and retrieval togetherThe support agent's question reaches trusted application code. The code calls the payments API for order 8472 and, independently, searches the policy index with tenant and access filters. The tool result and the retrieved passage E1 are assembled with the question into the prompt; the model answers with a citation and the answer returns to the agent.Support agentApp codetrustedPayments APIlive factsPolicy indexdocumentsLLM1. charged twice on 8472?2. get_order_payments3. 2 settled captures4. search + ACL filter5. [E1] POL-REF-004 v46. question + fact + [E1]7. answer citing [E1]8. answer + citation
Answering the running case with a tool and retrieval together. The tool result establishes the fact, the retrieved policy establishes the consequence, and the model composes them. The two lookups do not depend on each other, so the application can run them concurrently.
ScenarioBest fitWhy
General explanation, low riskDirect promptNo private or changing facts are needed.
One small, stable, shared manualLong-context promptThe whole source fits; no selection step is required.
Exact live value such as a payment statusTool or SQL lookupA system of record holds the answer; documents cannot.
Large or changing documents that need citationsRAGUpdate the store, not the model; evidence is attributable and permissionable.
Consistent tone, format, or narrow skillFine-tuningIt changes behavior, not the facts available at question time.

What You Take On When You Adopt RAG

RAG replaces one problem with an engineering system, and it is better to anticipate its parts as consequences than to meet them as surprises. Documents must be brought in from where they live, so you need connectors and an ingestion job. Files must be parsed, and a badly parsed PDF puts garbled text into your index. Text must be split into retrievable units, and where you cut changes what can be found (see Chunking Strategies). If you use semantic search, text must be converted to vectors by an embedding model that you must version and eventually migrate (see Embeddings Explained). Every unit needs metadata that records its source, version, and who may read it, because updates, deletes, and permission checks all depend on it.

Then there is the quality of retrieval itself, which you must measure rather than assume, and the observability to tell, when an answer is wrong, whether retrieval missed, the evidence was stale, the prompt dropped it, or the model ignored it. Each of those is a different bug with a different fix. There is also ongoing cost: indexing compute, storage, per-query search, and the extra input tokens on every generation. None of this is unreasonable, but it is real, and it is the reason RAG should be chosen deliberately.

When RAG Is the Wrong Choice

If the application has a handful of fixed rules, write them in the system prompt or in code. A retrieval pipeline that finds three static sentences is overhead with failure modes. If the authoritative answer is in structured data, such as an inventory count or a price, query the database; embedding a table of prices and asking a model to read them back is slower, costlier, and less reliable than a SELECT. If the entire task concerns one short document the user just uploaded, include that document in the prompt.

Retrieval is also risky when the content is highly sensitive and you cannot enforce document-level access in the search layer. A single shared index with no permission metadata turns every user's question into an unbounded read over everything. In that case the right move is to fix access control first or to not build the feature. And if you cannot show that retrieval improves outcomes on real questions, the added complexity has no justification yet. The Similarity Search and Retrieval Pipeline lessons explain how to measure that.

Three Decisions to Reason Through

An internal engineering handbook assistant

The handbook is 4,000 pages across a wiki, changes weekly, and some pages are restricted to managers. Employees ask "How do I request production access?" Pasting everything is impossible and would ignore restrictions. This is a RAG case: chunk and index the pages with their ACLs, retrieve only what the asking employee may read, and cite pages. Freshness lag and permission tests become first-class requirements.

A live bank balance

A customer asks "What is my balance?" The answer is one number in a system of record that changes by the second. Retrieval over documents cannot produce it and an embedding of last night's statement is wrong. Use an authenticated API call executed by trusted code, return the value to the model as a tool result, and have the model phrase it. If the customer also asks what overdraft fees apply, that part can come from retrieved fee policy.

Summarizing one uploaded report

A user uploads a 30-page report and asks for a summary. The report fits in the context window, belongs to one user, and is needed whole. Put it in the prompt. Retrieval would only risk dropping the paragraphs that matter for a summary, because a summary needs coverage, not the top few matches. If the report were 3,000 pages, you would summarize in stages or retrieve per section, but that is a different problem.

  1. 1

    Is the needed fact an exact value in a live system?

    Use a deterministic tool. Do not ask a model or a document index to guess it.
  2. 2

    Does everything relevant fit comfortably, for every user?

    Put it in the prompt and keep the system simple.
  3. 3

    Is it large, changing, permissioned, or must it be cited?

    Use retrieval, and budget for ingestion, evaluation, and access control.
  4. 4

    Do you need a style or skill rather than facts?

    Consider fine-tuning, possibly on top of the above.

What's Next

You now have the reasons for RAG and the boundaries of where it applies. The next lesson draws the full system: how documents are prepared offline, how a question is answered online, and where each failure can occur.

Up Next · Retrieval Augmented Generation (RAG)

RAG Architecture

Next, move from motivation to mechanism: ingestion, retrieval, optional reranking, prompt assembly, and generation.