esc
  • WorkflowsPages
  • Case studiesPages
  • Machine Learning FoundationsLearn
  • AI EngineeringLearn
  • AI Guardrails & Red TeamingLearn
  • UI/UXLearn
  • Design SystemsLearn
  • Production System DesignLearn
  • AI papersPages
  • Interview KitPages
  • Book a callContact
  • Download ResumeContact
Let’s talk

I’ll build the agent for it.

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.

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

  1. 1The question goes in with the whole text attached.
  2. 2The question goes to the search first, not the prompt.
  3. 3The whole text reaches the model at once.
  4. 4Only the matching parts reach the model.
  5. 5The model writes the answer for the reader.
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.

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

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

  1. 1The whole library goes in with the question.
  2. 2The question alone goes to the search index.
  3. 3The best matches come back, each with its file ID.
  4. 4The full prompt reaches the model, clause in the middle.
  5. 5Only the eight clauses reach the model.
  6. 6The model writes one reply and cites the file IDs.
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.

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

    Measure the real fit

    Count the documents your users will really ask about, not a small demo folder.

  2. 2

    Name the access rule

    Who may see which file? Enforce that before the model reads anything.

  3. 3

    Price one question

    Multiply the prompt size by the questions per day, then compare it with a search step.

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

1 / 6

What will they ask next?

  1. Q140How do you enforce access control in RAG?11 min
  2. Q139How do you keep the index fresh?11 min
  3. Q146How do you pick top-k?11 min
  4. Q135How do you add citations?11 min
  5. Q134How do you reduce hallucinations in RAG?13 min

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.