# 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.

AI and LLM interview question Q138, Retrieval-augmented generation (RAG). Intermediate, very common (our estimate). From Venkat R. Murty's free Interview Kit: https://designervenkat.online/interview/ai/rag-vs-long-context

## Say it in 30 seconds

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.

## Say it in 2 minutes

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.

- **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.

*Diagram, Which way the text reaches the model: Two ways to get text to the model. Small, fixed text that every reader may see can go in whole. Large, changing or restricted libraries are searched first, and only the matching parts go in. Both paths end at the same model, which writes the answer.*
1. The question goes in with the whole text attached.
2. The question goes to the search first, not the prompt.
3. The whole text reaches the model at once.
4. Only the matching parts reach the model.
5. The 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.

```python
# 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:

```text
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.

*Diagram, Paste everything, or search first: Same question, two set-ups. Pasting the whole library risks losing a clause in the middle, and it costs more on every question. Searching first sends eight matching clauses, each with its file ID, so the answer can cite them.*
1. The whole library goes in with the question.
2. The question alone goes to the search index.
3. The best matches come back, each with its file ID.
4. The full prompt reaches the model, clause in the middle.
5. Only the eight clauses reach the model.
6. The 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." Better: It 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." Better: RAG answers only as well as its search. Test retrieval on its own before blaming the model.
- Trap: "Just paste all the documents in." Better: Check 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?

A. Index the contracts nightly, so answers use the latest terms.
B. Send only the eight best matching clauses to the model, each with its contract ID.
C. Paste all 40,000 contracts into every prompt, so nothing can be missed.
D. Filter search results by each lawyer's matters before the model reads them.

**Answer:** C. Pasting the whole library breaks the cost budget, puts the key clause at risk of being lost in the middle, and sends contracts the lawyer may not be allowed to see. Search first, filter by access, then send a few clauses.

**Quick check:** A team has one 90-page supplier contract and asks about its exit terms once a week. Which first step fits best?

A. Set up a vector database and RAG
B. Put the whole contract in the prompt
C. Fine-tune a model on the contract
D. Build a multi-agent pipeline for it

**Answer:** B. It fits in one prompt, and the exit terms may depend on a definition far from the clause. Search, fine-tuning or agents add moving parts for a single file that already fits.

## Can you answer these from memory?

**Flash cards**

- **What is RAG?** Search your documents first, then send only the matching parts to the model.
- **What is long context?** The whole text in one prompt, so the model can read all of it.
- **When is long context better?** The material is small and fixed, and the answer needs all of it.
- **When is RAG better?** The library is too big, changes often, or access differs per user.
- **What is context rot?** Recall drops as the context grows, per Anthropic's engineering team.
- **Are the two either or?** No. Many systems search first, then send a larger set of matches.

## Likely follow-up questions

- Q140 How do you enforce access control in RAG? https://designervenkat.online/interview/ai/how-do-you-enforce-access-control-in-rag
- Q139 How do you keep the index fresh? https://designervenkat.online/interview/ai/how-do-you-keep-the-index-fresh
- Q146 How do you pick top-k? https://designervenkat.online/interview/ai/how-do-you-pick-top-k
- Q135 How do you add citations? https://designervenkat.online/interview/ai/how-do-you-add-citations
- Q134 How do you reduce hallucinations in RAG? https://designervenkat.online/interview/ai/how-to-reduce-hallucinations-in-rag

## Learn it in depth

- [Retrieval-augmented generation](https://designervenkat.online/learn/ai-engineering/rags)
- [Long-Context Processing](https://designervenkat.online/learn/ai-engineering/long-context-processing)
- [Where RAG fits, and where not](https://designervenkat.online/learn/ai-engineering/rag-usecases)
