When Retrieval Beats Fine-Tuning or Long Context
Choose how a model gets the knowledge it needs (prompting alone, the whole source in a long context, retrieval or fine-tuning) from the size, freshness and access rules of the knowledge source, and from what each option costs per question in money and waiting time.
Contentsand lesson path
On this page
- Why it matters
- Four ways to give a model knowledge
- Three questions about the knowledge source
- What long context costs per question
- Check your understanding
- Apply it
- Review prompt
Lessons of RAG Foundations
- When Retrieval Beats Fine-Tuning or Long Context Concept · 15 min
- A Minimal RAG Pipeline End to End Worked example · 25 min
- Assembling Context for Generation Concept · 15 min
- Lab: Query Rewriting and Reranking Lab · 25 min
- Common RAG Failure Modes Concept · 15 min
- Check: Trace a Wrong Answer to Its Cause Knowledge check · 6 questions
What you will learn
- Explain when RAG is preferable to prompting alone, long context or fine-tuning, given a knowledge source's size, freshness and access rules.
Prerequisites: Vector Search Foundations, Chunking, LLM API Integration
01. Why it matters
A model can answer from two places only: what it learnt in training, stored in its weights, and what you put into the request. Training data stops at a cutoff date, is mostly public, and leaves no trace of where a fact came from. A question about your product documentation, a customer contract or last week's incident report needs knowledge from the second place, or a change to the first.
There are four ways to get that knowledge in front of the model, and the wrong choice is expensive in either direction. Teams fine-tune a model to teach it facts and find that it still invents details, or paste a whole wiki into every request and pay for it on every call.
This lesson describes the four options, then gives you three questions about the knowledge source and one calculation that decide between them. The rest of the skill builds the option that most often wins: retrieval-augmented generation, or RAG.
02. Four ways to give a model knowledge
- Prompting alone. Send the question and nothing else. This works when the model already knows enough, as with general questions about a popular programming language, or when the user brings the material, as in summarise this email. It is the cheapest option and has no pipeline to break. It fails quietly on private or recent facts: the model still answers, fluently and wrongly.
- Long context. Send the whole knowledge source with every request. Current Claude models accept up to 1 million tokens of input, so a sizeable manual fits. Nothing can be missed by a search step, and the model can combine facts from distant parts of the source. Every request pays for every token and waits while the model reads them, and material in the middle of a long input is used least reliably, as the Tokens and Context skill showed.
- Retrieval-augmented generation (RAG). Cut the source into chunks and index them in advance (the Chunking, Embeddings and Vector Search skills). For each question, retrieve the few chunks most related to it and send only those, with an instruction to answer from them. Lewis et al. named the approach in 2020 for a model paired with a search index over Wikipedia; today the term covers any pipeline that retrieves before it generates. RAG scales to sources of any size, reflects an edited page as soon as it is re-indexed, can filter per user and can cite. Its cost is a pipeline with its own failure modes: when retrieval misses, the model never sees the evidence.
- Fine-tuning. Continue training a model on your own examples, so the weights change. It is good at behaviour: a fixed output format, a house style, a narrow classification task, or shorter prompts because the instructions are learnt. It is poor at facts. Ovadia et al. (2023) compared the two for injecting knowledge and found that RAG beat unsupervised fine-tuning, for facts the model had seen before and for new ones. A fine-tuned model cannot point to a source, needs another training run for every change, and offers whatever it learnt to every user.
The options combine: a common design uses the prompt, or fine-tuning if the prompt is not enough, for format and tone, and RAG for facts.
03. Three questions about the knowledge source
Ask these about the knowledge, before you think about tools:
- Size. How many tokens is it, counted with the model's tokenizer? If it fits in the context window with room for instructions, history and the answer, long context is possible. A documentation site of several thousand pages, a ticket archive or a shared drive does not fit in any window, and retrieval is no longer optional.
- Freshness. How often does it change, and how soon must answers reflect a change? RAG re-embeds only the chunks of an edited page, which the stable IDs from the Chunking skill make cheap, so an edit can be live within minutes. Long context reads the current text on every request, so it is fresh too, but each change invalidates a cached prompt. Fine-tuning reflects a change only after the next training run.
- Access rules. Does every user see everything? If permissions differ per customer, team or role, content a user may not see must never reach the model on that user's behalf. RAG applies the user's permissions as a filter inside the search. With long context you would need a separate prompt per permission set. Weights cannot forget something for one user, and an instruction such as do not reveal other clients' data is a request to the model, not access control.
Two questions about use complete the picture: what each question may cost, and whether answers must show their sources.
Some typical outcomes:
- A lawyer analyses one 300-page contract this afternoon: long context, because it is one document, used once, and a search step could miss a clause.
- A help centre answers from 4,000 articles, about 3 million tokens, edited every day: RAG, because of both size and freshness.
- An internal assistant answers from HR cases, and managers may see only their own team's cases: RAG with a permission filter at retrieval.
- Support replies must follow a fixed structure across tens of thousands of tickets a day: instructions and structured output first, fine-tuning only if they fall short, and the facts still come from retrieval.
04. What long context costs per question
Suppose the docs fit: 800,000 tokens, inside a 1M-token window. Should you send all of them with each question? Price it. The script below compares the input cost of three designs at 5,000 questions a day, using the list prices of claude-sonnet-5-5 on the Claude pricing page (checked on 17 November 2026): $2 per million input tokens, and $0.10 per million for tokens read from the prompt cache. Output tokens cost the same in all three designs, so they are left out.
"""Daily input cost of three ways to answer from an 800,000-token docs set."""
# US$ per million tokens, claude-sonnet-5-5 list prices on 17 November 2026
PRICE = {"input": 2.00, "cache_hit": 0.10}
QUESTIONS_PER_DAY = 5_000
options = {
"whole corpus, no caching": (800_000, PRICE["input"]),
"whole corpus, cache hits": (800_000, PRICE["cache_hit"]),
"RAG: rules + 5 chunks": (3_500, PRICE["input"]),
}
for name, (tokens, price) in options.items():
per_question = tokens * price / 1_000_000
print(f"{name:<26} {tokens:>7,} tokens ${per_question:.4f} per question"
f" ${per_question * QUESTIONS_PER_DAY:>6,.0f} per day")python cost.pywhole corpus, no caching 800,000 tokens $1.6000 per question $ 8,000 per day
whole corpus, cache hits 800,000 tokens $0.0800 per question $ 400 per day
RAG: rules + 5 chunks 3,500 tokens $0.0070 per question $ 35 per dayMoney. Sending the whole corpus costs about 230 times as much as RAG. Prompt caching narrows the gap a lot, because cached tokens are billed at a fraction of the input price, but it does not close it: the cache expires after 5 minutes without use (or 1 hour, at a higher write price), every docs change means writing 800,000 tokens to the cache again, and the cache belongs to one model. Prices change, so check the current pricing page before you decide.
Waiting time. The model processes every input token before it writes the first token of the answer, so the time to first token grows with the input. Caching removes much of that work for the cached part. Measure it with your own prompt sizes rather than trusting a rule of thumb.
Quality is not one-sided. Li et al. (2024) found that long-context models answered better on average than RAG when cost was no object, and that RAG was far cheaper. Their Self-Route method tries RAG first, lets the model judge whether the retrieved text can answer, and sends only the remaining questions to long context. Treat long context as the quality ceiling for a source that fits, and RAG as the practical default once size, cost, waiting time, freshness or access rules weigh in.
05. Check your understanding
06. Apply it
The practice project for this skill is a command-line question-answering tool over the documentation corpus from your Chunking practice. Before you build it, write the decision record that justifies RAG, or argues against it:
- Size: count the tokens of the whole corpus with tiktoken, as in the Tokens and Context skill, and compare them with your model's context window.
- Freshness: run
git log --since="6 months ago" --oneline -- docs/(adjust the path) in the source repository and count how often the docs changed. - Access rules: write down who may read the docs. For public docs the answer is everyone; say what would change if a private section were added.
- Cost: copy
cost.py, put in your token count, a realistic number of questions per day and current prices, and add a line for your planned RAG prompt size.
Save it as DECISION.md in the tool's folder. You will add measured numbers to it after the lab in lesson 4.
07. Review prompt
Without looking back, answer in your own words:
- What are the four ways to give a model knowledge, and what is each one good and bad at?
- Which three properties of the knowledge source decide between them, and how does each one push the decision?
- Why is an instruction to the model not a way to enforce per-user permissions?
- How does prompt caching change the cost of long context, and what does it leave unchanged?
References
- Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks (Lewis et al., 2020)
- Retrieval-Augmented Generation for Large Language Models: A Survey (Gao et al., 2023)
- Fine-Tuning or Retrieval? Comparing Knowledge Injection in LLMs (Ovadia et al., 2023)
- Retrieval Augmented Generation or Long-Context LLMs? A Comprehensive Study and Hybrid Approach (Li et al., 2024)
- Claude docs: Pricing
- Claude docs: Prompt caching
- Claude docs: Context windows
Your progress
Reading state
Sign in to save that you finished reading this lesson.
Prove this skill
6 questions · about 5 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.