Sub topic 1
Why models need outside knowledge
Prerequisites
This chapter assumes you can read basic Python and have prompted a large language model (LLM) through an API. You should also be comfortable with JSON. Later chapters use vectors and the dot product, but this one does not.
What a model knows, and what it doesn't
An LLM stores what it learned during training as numeric weights. That gives it three limits that matter for applications.
- Knowledge cutoff. The model has no information about events after its training data ended. It will not know about last week's policy change.
- No access to private data. Your wiki, tickets, contracts, and databases were not in the training set, so the model cannot recall them.
- Unreliable recall. Even for facts it saw, the model may produce a fluent but wrong answer. This is called a hallucination. It happens because the model predicts likely text and does not look facts up.
A fourth limit is the context window, the maximum amount of text the model can read in one request. A company's documents are usually far larger than any window.
Pasting knowledge into the prompt
The model can use information that appears in its prompt, even if it never saw that information in training. This suggests a fix: find the few passages relevant to a question and place them in the prompt. This idea is retrieval-augmented generation (RAG).
The sketch below shows the difference. It builds two prompts and does not call a model.
question = "What is our refund window for annual plans?"
bare_prompt = f"Question: {question}\nAnswer:"
passage = "Annual plans may be refunded within 30 days of purchase."
grounded_prompt = (
"Answer using only the context below.\n\n"
f"Context:\n{passage}\n\n"
f"Question: {question}\nAnswer:"
)
print(bare_prompt)
print("---")
print(grounded_prompt)With bare_prompt, the model can only guess. With grounded_prompt, the answer is in front of it, and you can check the answer against the passage.
Why not paste everything?
Sending all your documents every time fails for practical reasons.
| Problem | Effect |
|---|---|
| Corpus larger than the context window | The request is rejected or truncated |
| Cost scales with input size | Every query pays for text it does not need |
| Irrelevant text in the prompt | Answer quality can drop as noise increases |
| Latency grows with input size | Responses get slower |
Retrieval solves this by selecting only a small, relevant slice per question.
Common mistakes at this stage
- Assuming a larger context window removes the need for retrieval. Cost, latency, and noise still apply.
- Treating the model's answer as correct because it sounds confident.
- Expecting the model to know private or recent facts without supplying them.
The next chapter walks through the full RAG pipeline that supplies those facts.
Exercise
Name two limits of an LLM that RAG addresses, and one reason you cannot simply put your entire document collection in every prompt.
Show answer
RAG addresses the knowledge cutoff (the model lacks recent information) and the lack of access to private data (your documents were not in training). You cannot paste everything because the collection usually exceeds the context window, and even when it fits, it raises cost and latency and adds irrelevant text that can reduce answer quality.