RAG vs Long Context: Which to Use?
When to put your documents in the prompt, when to search them first with RAG, and how to explain the choice, simply, for your AI interview.
In short
Use long context when the material is small enough to fit and the answer needs all of it. Use RAG when the library is too big, changes often, or each user may only see part of it. RAG searches first and sends only the matching parts, and the search can drop what a user may not see.
12 min readIntermediateVery common · estimateFacts checked 26 November 2026
Say it out loud
Read it once, then say it without looking. Start with the short one; use the long one when they ask you to go deeper.
RAG means search first, then send only the matching parts to the model. Long context means putting the whole text in one prompt. I use long context when the material is small, fixed and needed whole, like one supplier contract. I use RAG when the library is too big to fit, changes often, or each user may only see some of it. Many real systems use both: search to choose, then send a bigger set of parts.
Both methods answer questions about your own documents, and they solve different limits. Long context puts the whole text in the prompt, so the model can read all of it at once. RAG, short for retrieval-augmented generation, first searches an index for the matching parts and sends only those. Microsoft describes RAG as a pattern that grounds responses in your own content.
Long context wins for a small, fixed set of text where the answer may depend on everything. Take one 90-page supplier contract and a question about how the deal ends. It fits, and an exit clause may depend on a definition from page three, so I would paste the whole contract in. RAG wins when the library is too big, changes often, or has access rules. A legal team with 40,000 contracts cannot paste them all, and each lawyer may only see certain matters.
A bigger prompt is not automatically better. Anthropic's engineering team describes context rot, where recall drops as the context grows, and a 2023 study found that performance is often highest when the key text sits at the start or end of the prompt, and drops when it sits in the middle. Pasting everything also tends to cost more on every question. So I search first, send the best matches with their IDs, and make the answer cite them.
In an interview, say the choice depends on four things: fit, whether the answer needs all the text, how often it changes, and who may see which part. Then name the cost and the test you would run.
What are RAG and long context, in plain words?
A language model only works from what is in its prompt when it writes a reply. Long context puts your whole document in that prompt. RAG (retrieval-augmented generation) first searches your documents for the parts that match the question, then puts only those parts in the prompt.
Microsoft describes RAG as a pattern that extends LLM capabilities by grounding responses in your proprietary content. The model itself is not retrained. The documents are read at the moment of the question.
Think of a paralegal with a big case file. One option is to carry the whole file into the meeting. The other is to check the index, pull the three tabs that matter, and bring only those. An AI app faces the same choice: 40,000 contracts and one question about which ones let a buyer walk away.
Key words
- Token
- A small piece of text the model counts. A word can be one token or several.
- Context window
- All the text the model can read in one go, including its own reply.
- Chunk
- A small piece of a document, stored and searched on its own.
- Index
- A searchable store of your chunks. Each chunk is stored as embeddings, lists of numbers that stand for its meaning.
- Grounding
- Making the answer rest on the text you supplied, not on memory alone.
How do you choose between them?
Four tests decide it: does the material fit, does the answer need all of it, does it change, and who may see which part. Here is the choice as a picture.
Which way the text reaches the model
The question
Someone asks about the documents
Small, fixed, open to all
Long context
Whole text in one prompt
Large, changing or restricted
RAG
Search, then send the matches
The model
Reads what it is given
A usable answer
Can cite the parts it used
- 1The question goes in with the whole text attached.
- 2The question goes to the search first, not the prompt.
- 3The whole text reaches the model at once.
- 4Only the matching parts reach the model.
- 5The model writes the answer for the reader.
Two cases from one legal team show the difference.
- Case A
One supplier contract
90 pages, one matter. It fits, and the exit terms may depend on a definition far from the clause. Paste the whole contract in and ask.
- Case B
40,000 contracts
Which ones let a buyer end the deal if control changes? Too big to fit, and each lawyer may see only their own matters. Search first, filter by access, then send the matching clauses.
The hard part in Case B is access. The search has to drop any contract the lawyer may not see before the model reads it. A filter that runs after the model has read the file comes too late.
A team can write a first rule as a few lines of code. This sketch uses size, file count and change, leaves out access, and uses made-up numbers.
# A simplified rule a team might write. The budget and the cases are made up.
PROMPT_BUDGET = 100_000 # tokens we allow in one prompt
def choose(case, tokens, files, changes_often):
reasons = []
if tokens > PROMPT_BUDGET:
reasons.append("too big to fit")
if files > 5:
reasons.append("many separate files")
if changes_often:
reasons.append("changes often")
if reasons:
return f"{case}: RAG ({'; '.join(reasons)})"
return f"{case}: long context (fits, reads whole)"
print(choose("Supplier contract, 90 pages", 60_000, 1, False))
print(choose("Claims policy library", 90_000_000, 40_000, False))
print(choose("HR handbook, updated monthly", 40_000, 1, True))Output
Supplier contract, 90 pages: long context (fits, reads whole) Claims policy library: RAG (too big to fit; many separate files) HR handbook, updated monthly: RAG (changes often)
Tip
Name the case you are in before you name a tool. Interviewers listen for the reasons more than the product.
Why not put everything in the prompt?
Because a bigger prompt often gives a weaker answer. Anthropic's documentation says more context is not automatically better, and that accuracy and recall fall as the token count grows. Recall means how reliably the model finds a fact that is in its prompt. Here are the three sources behind that idea.
“Studies on needle-in-a-haystack style benchmarking have uncovered the concept of context rot: as the number of tokens in the context window increases, the model's ability to accurately recall information from that context decreases.”
Anthropic, 2025
“performance is often highest when relevant information occurs at the beginning or end of the input context, and significantly degrades when models must access relevant information in the middle of long contexts, even for explicitly long-context models.”
Research paper, 2023
“Sending everything wastes tokens and degrades quality.”
Microsoft, Foundry IQ (Azure AI Search) docs
A claims team at a mid-size insurer pastes its whole policy library into every question. A flood-damage question then depends on one exclusion buried in the middle of a long prompt. The model may miss it, and every question pays for the full library again.
Paste everything, or search first
The question
Needs one clause from 40,000 files
Paste everything
Every contract
Whole library, on every question
Key clause in the middle
Recall drops for mid-prompt text
Search first
Search the index
Finds the matching clauses
Eight best clauses
Each with its file ID
The model
Writes one reply
Answer with sources
Cites the file IDs it used
- 1The whole library goes in with the question.
- 2The question alone goes to the search index.
- 3The best matches come back, each with its file ID.
- 4The full prompt reaches the model, clause in the middle.
- 5Only the eight clauses reach the model.
- 6The model writes one reply and cites the file IDs.
Where does RAG go wrong?
RAG is only as good as its search. Anthropic notes that traditional RAG often destroys context, because a piece cut from its page can lose what it refers to. Four common failures:
Search misses the clause
The right clause may use other words than the question, so a search can skip it. Test the search on its own, with real questions.
Chunks lose their context
A clause cut from its page can read as if it binds the wrong party. Keep the contract title and section with each chunk.
The index goes stale
A changed contract still shows its old clause until the index updates. Microsoft says incremental indexing keeps content fresh, so plan the update schedule.
Access leaks
Microsoft says users and agents must only retrieve authorized content. If the filter runs after the model reads a file, the file has already leaked into the answer.
Anthropic's 2024 guidance was that a knowledge base under 200,000 tokens could simply go in the prompt. That number changes as models change, so check the current docs before you quote it.
How would you answer: should we just use a bigger model?
Start with fit and access. A model with a bigger context window still cannot enforce a per-user access rule, and it still costs more on every question. If the library is small and fixed, a larger prompt may be the simplest answer. If it is large or changes often, search is still needed.
- 1
Measure the real fit
Count the documents your users will really ask about, not a small demo folder.
- 2
Name the access rule
Who may see which file? Enforce that before the model reads anything.
- 3
Price one question
Multiply the prompt size by the questions per day, then compare it with a search step.
- 4
Test both
Run the same 50 real questions both ways, and score which answers cite the right part.
What does the interviewer want to hear?
A strong answer covers
- The one-line rule: long context for small fixed text, RAG for large or changing text.
- The four tests: fit, need for the whole text, change, and access.
- Why more text is not automatically better: context rot and the middle problem.
- RAG's own failure points: missed search, chunks that lose context, stale indexes.
- Access checked before the model reads, not after.
- Cost: a long prompt tends to be paid for on every question.
Common traps
Trap"Long context makes RAG obsolete."
BetterIt suits small, fixed sets. Large or changing libraries still need search, access rules and a way to cite sources.
Trap"RAG always gives the right answer."
BetterRAG answers only as well as its search. Test retrieval on its own before blaming the model.
Trap"Just paste all the documents in."
BetterCheck the size, the cost per question, and whether each user may see every file first.
Can you spot the mistake?
Spot the mistake
A team building a contract assistant writes this in its design doc. Which line is the mistake?
Quick check
A team has one 90-page supplier contract and asks about its exit terms once a week. Which first step fits best?
Can you answer these from memory?
Flash cards · tap a card to flip it
What will they ask next?
Learn it in depth
Last updated on 26 November 2026
Choosing between RAG and a long prompt for your documents?
I design and build AI assistants on your own documents, including how they search, what each user may see, and how they cite sources. Book a short call and tell me what your documents are and who reads them.