Sub topic 1
Why Models Need Outside Knowledge
This chapter explains the limits of a language model's built-in knowledge and why those limits lead to retrieval-augmented generation (RAG). It sets up the rest of the tutorial. Later chapters build the pipeline.
Prerequisites
This chapter assumes you have:
- Basic Python, enough to read short functions.
- A working idea of how large language models (LLMs) are prompted: you send text in, and the model returns text.
- Some familiarity with vectors and the dot product. You need these from the embeddings chapter onward, not here.
- Basic use of APIs and JSON.
What a model knows, and where it comes from
An LLM learns from a large text collection during training. The result is a set of numeric weights. When you prompt the model, it predicts likely next tokens from those weights and from the text you supplied.
This gives the model two sources of information:
- Parametric knowledge is what the weights absorbed during training. It is implicit and cannot be inspected or edited directly.
- Context is the text in the current prompt. It is explicit and exists only for that request.
RAG works because the model can use the second source well. If you place a relevant passage in the context, the model can read it and answer from it, even if it never saw that passage in training.
Five limits of parametric knowledge
1. A knowledge cutoff
Training data stops at a date. Anything after that date is missing, including new product versions, changed policies, and recent events. The model has no built-in way to notice that its information is out of date, so it may describe an old state of the world as current.
2. No access to private data
Your wiki, tickets, contracts, and code were not in the training set, and you would not want them to be. The model cannot answer "What is our refund window for enterprise customers?" from weights alone.
3. Uneven recall of rare facts
Models tend to recall common facts reliably and rare ones poorly. Obscure details, such as an internal part number or a niche API parameter, are often missing or blurred together with similar facts.
4. Confident wrong answers
A model produces fluent text whether or not it holds the fact. When the fact is missing, the output can be a plausible invention. These errors are often called hallucinations. The fluent tone gives the reader no signal about reliability.
5. No sources
Parametric knowledge cannot point to where a claim came from. For work that needs auditing, such as legal, medical, or support answers, an answer you cannot trace to a document is hard to trust or correct.
Why not just paste everything into the prompt?
The context window is the maximum number of tokens a model can read in one request. It is large in modern models but finite. Putting all your documents in every prompt runs into several problems:
- Size. A company knowledge base can be millions of tokens or more, which exceeds any window.
- Cost. Providers typically charge per input token, so a large prompt makes every request expensive.
- Latency. More input tokens take longer to process.
- Attention quality. Models can miss details buried in a long context, especially in the middle. Relevant text diluted by irrelevant text often gives worse answers than a short, focused prompt.
The conclusion is that you should give the model only the few passages relevant to the current question. Choosing those passages is the retrieval problem.
The idea behind RAG
Retrieval-augmented generation splits the work in two:
- Retrieve. Search an external knowledge source for passages relevant to the question.
- Generate. Put those passages in the prompt and ask the model to answer from them.
The model's job shifts from remembering to reading. The knowledge lives in a store you control, so you can update it, restrict it, and cite from it.
A small demonstration of the gap
The following example shows the difference between an ungrounded and a grounded prompt. It builds both as strings, so it runs without any API key.
question = "What is the refund window for enterprise plans?"
passage = (
"Enterprise plans can be refunded within 45 days of purchase. "
"Standard plans can be refunded within 14 days."
)
ungrounded = f"Question: {question}\nAnswer:"
grounded = (
"Answer using only the context below. "
"If the context does not contain the answer, say you don't know.\n\n"
f"Context:\n{passage}\n\n"
f"Question: {question}\nAnswer:"
)
print("--- ungrounded ---")
print(ungrounded)
print()
print("--- grounded ---")
print(grounded)Sent to a model, the ungrounded prompt forces a guess, because the 45-day figure exists nowhere in the weights. The grounded prompt carries the fact, so the model only needs to read it. Later chapters replace the hard-coded passage with the output of a real retrieval step.
What RAG fixes and what it does not
| Limit | Does RAG help? | How |
|---|---|---|
| Knowledge cutoff | Yes | Update the store, not the model |
| Private data | Yes | Index your own documents |
| Rare facts | Mostly | The fact is supplied in context, if retrieval finds it |
| Confident wrong answers | Partly | Grounding and refusal instructions reduce them, but do not remove them |
| No sources | Yes | Passages can be numbered and cited |
| Finite context window | Yes | Only a few passages are sent |
Edge cases to keep in mind
- The answer is not in the store. The model should say so. Without an explicit instruction to refuse, it often falls back on parametric knowledge or invents something.
- The store contradicts the model. If a passage says 45 days and the model "remembers" 30, the prompt must make clear that the context wins.
- Stale or duplicated documents. The store is only as current as its last update. Two versions of one policy can both be retrieved.
- Questions that need the whole corpus. "Summarize all complaints this year" needs aggregation across many documents. Retrieving a handful of passages does not cover that.
- Access control. The store may hold documents some users must not see. Retrieval has to respect permissions, because the model will repeat whatever it is given.
Where this chapter fits
The remaining chapters follow the order in which data moves through a RAG system:
- Load and clean documents, then split them into chunks.
- Turn chunks into embeddings and store them.
- Search by similarity, and improve search with hybrid retrieval, reranking, and query rewriting.
- Build the augmented prompt and generate cited answers.
- Evaluate, diagnose failures, and run the system in production.
Exercises
Exercise
A support bot built on a plain LLM tells a customer that a product feature exists. The feature was released after the model's training data ended, and the model has no knowledge of it. Which limit of parametric knowledge is this, and how does RAG address it?
Show answer
This is the knowledge cutoff. RAG addresses it by keeping current documents, such as release notes, in an external store. At query time the retriever fetches the relevant passage and places it in the prompt, so the model reads the current information. You update the store when things change, and the model needs no retraining.
Exercise
Your whole knowledge base fits within the model's context window. Give two reasons you might still prefer retrieving a few passages over sending everything on every request.
Show answer
Any two of these: cost, because input tokens are billed on every request; latency, because longer inputs take longer to process; answer quality, because relevant details can get lost among large amounts of irrelevant text; and access control, because retrieval lets you send only documents the current user is allowed to see.
Exercise
A RAG system retrieves the wrong passage, and the model answers fluently and cites it. Which part of the system failed, and why is the answer still dangerous?
Show answer
Retrieval failed, not generation. The model faithfully used what it was given. The answer is dangerous because the citation makes it look verified, so readers are less likely to question it. This is why retrieval and answer quality are measured separately.