Frontier Foundry

Long context vs RAG

37 sourced facts · updated

Long context or RAG: do you still need retrieval?

Often yes, and the sources do not treat it as one or the other. A big window lets you put everything in, but the model uses the start and the end of a long input better than the middle, quality can fall well inside the advertised limit, and every token is sent again with every request. Retrieval fetches only what the question needs and can show where each answer came from. Agents that read whole environments over many rounds are the case the sources give for a very large window. [1][2][3][4][5]

In the knowledge graph: Put everything in the window, or fetch only what the question needs.

The difference between Long context and RAG

Long contextRAG
How it worksThe whole input goes in: every token is read once in prefill, and a key and a value for every token are parked in fast memory for later. [6][7]Only a few pieces go in: the question is embedded, vector and keyword search run in parallel, the lists are fused and optionally reranked, and the top chunks go to the model. [8]
Where the cost goesInto every request: attention computation grows quadratically with context length, and Amp notes that every token is sent with every request, so long threads cost more than the token price shows. [9][3]Into setup and the answer step: parsing and embedding a codebase is a one-time cost. In NVIDIA's RAG Blueprint the LLM is the largest contributor to latency, followed by the reranker. [10][11]
What the model actually readsAll of it, but unevenly: models take in the start of the input and the end, but the in-between context is largely dropped. Schmid says the effective window is often under 256k tokens for most models. [1][2]A short list: one builder fetched the top 50 from each search, kept 30 after fusion and gave 10 to the agent. The limit is that an index may find the right document but cannot open it. [12][13]
Very large inputsOne model lists a 1 million token window, but in Codex GPT-5.4's 1M window is experimental and opt-in, and requests past the standard 272K window use up the plan's usage limits at twice the normal rate. [14][15]The index grows instead of the prompt: one rulebook assistant indexed about 270 PDFs and 6,000 pages as around 4,000 chunks, and a rulebook above roughly 100k tokens is not dumped into the context. [16][17]
How agents use itOne lab built a 1 million token window because agents that take in every tool response and many rounds of work need more than a short context. But when a tool returns a large amount of data, the window overflows and the agent starts to hallucinate. [18][19]Retrieval becomes a tool the agent calls many times: instead of one call up front, an agent fires many parallel queries. One builder's questions needed 2 to 4 search calls, and the median answer took 38 seconds. [20][21][22]
How it goes wrongLost in the middle: a code-review team gave one agent a large context and four tasks at once. It focused on two, and the other two were lost in the middle. [23]The wrong page or the wrong number: retrieval can pull the wrong source, or the right source and the wrong number, and attaching sources afterwards does not help. [24]
How to check itWith recall tests over long inputs and a token threshold: Anthropic reported 76% vs 18.5% for Opus 4.6 against Sonnet 4.5 on the 8-needle, 1M-token variant of MRCR v2. Schmid's rule is to set a pre-rot threshold, watch the token count and compact before reaching it. [25][2]Measure the retriever on its own, so a retrieval problem is not mistaken for a generation problem. [26]

When to use Long context

  • Your agent reads whole environments and many rounds of tool replies, and cannot do complex tasks in a shorter context. [5][18]
  • Shrinking the context by summary would drop what you need: summarising to shrink the context can drop the very facts the answer needs. [27]

When to use RAG

  • Answers have to be checkable: under each answer the assistant can list the rulebook and section it used, and a filter can refuse citations that cannot be verified. [4][28]
  • You want to keep the prompt short: short threads can give better results and cost less than one mega-thread, and quality can fall as the window fills even well inside the advertised limit. [29][2]
  • The material is far bigger than any window you can afford to fill on every request: in a 450-fold scaling study BM25 overtook a file-system agent at about 10 million tokens. [30][3]

Using Long context and RAG together

The retrieval sources already mix them. One assistant gives its agent four tools from narrow to wide: search chunks, retrieve a whole section, retrieve a whole small rulebook, and list the rulebooks. A rulebook above roughly 100k tokens is not dumped into the context; the tool returns a section list instead. A recursive-language-model harness goes further and avoids loading a huge input at all: the agent writes code that dispatches subagents over chunks, so no single context holds everything. [31][17][32]

Do agents need a million-token window, or is frequent compaction enough?

The sources disagree. One side says agents that read whole environments and many rounds of tool replies cannot do complex tasks in a shorter context. Another says that with frequent compaction, frontier models lose little or no task accuracy, so long context may be unnecessary. A third, an Opus user, finds quality degrades past about 50% of a 1M window and restarts with markdown docs that tell the model where to look. [5][33][34]

Does an agent that greps files replace the ranked index?

The sources disagree. On about 20 bug tasks, agentic search matched vector search in accuracy at a quarter of the cost, because lone chunks lacked the surrounding logic. But BM25 overtakes a file-system agent around 10 million tokens, and Mistral's agent builds on an existing search index rather than replacing it. [35][36][37]

Each one on its own

from their concept pages

What is Long context?

Long context means a model can read very long inputs in one go, from hundreds of thousands to millions of tokens. Whole codebases or stacks of documents fit in a single prompt. Reading that much costs more and takes longer, and filling the window does not mean every part of it is used well.

Long context means a model can take in hundreds of thousands to millions of tokens at once. Each token is read in prefill and parked as keys and values, every new word rereads that cache, and the cost, the memory and the uneven use of the middle all grow with the length.

1 million tokens
The context window of one model, as listed in the developer notes of its release; a tokenizer change in the same release gave about 30% more tokens for the same text Simon Willison
7x
How much dearer a later token can be to generate than an earlier one on frontier open-weight models; reported by the paper's authors Hugging Face

Long context, explained in full: how it works as a machine, every part and its sources.

What is RAG?

Retrieval-augmented generation looks up relevant documents when a question arrives and places them in the prompt. The model then answers from that text and not from memory alone. It gives a model current and private facts without retraining, and the answer is only as good as what was fetched.

Retrieval-augmented generation fetches relevant pieces of a document set at question time and puts them in front of the model. The sources describe a pipeline: documents are cut into chunks and filed by meaning and by exact words; a question fetches a short list, merged and reranked; the model answers from it and a check can refuse figures it cannot trace. Its limits are a short desk, a chunk size no one gets right for every query, and answers that can come from the wrong page.

about 2,000 characters
Size a chunk is packed to before it is cut, in one rulebook assistant (reported by the builders) Nina Žižakić
top 50 + top 50 to 30 to 10
Candidates per list, kept after fusion, and given to the agent (reported by the builders) Eleonora Drykina
2 to 4 calls
Search calls most questions need; the prompt asks the agent to reconsider before the sixth (reported by the builders) Eleonora Drykina

RAG, explained in full: how it works as a machine, every part and its sources.

In AI coverage over the last four weeks, Long context took 1.9% and RAG 0.81%. Long context, week by week

The facts behind this page

37 facts from the two knowledge packs
  1. Models take in the start of the input and the end, but the in-between context is largely dropped, like a U-curve. Nupur Sharma, AI Engineer · 2026-04-08 · Long context
  2. Context rot is when quality falls as the window fills even well inside the advertised limit; Schmid says the effective window is often under 256k tokens for most models. His rule: set a pre-rot threshold below that, watch the token count, and run compaction or summarisation before reaching it, instead of waiting for an API error. philschmid · 2025-12-04 · Long context
  3. Amp says long threads cost more than the token price shows: every token is sent with every request, some providers charge more for long-context requests, and long threads are likelier to sit idle past the cache window, which Amp names as a major contributor to runaway threads. amp · 2025-12-09 · Long context
  4. Under each answer the assistant lists the sources it used, naming rulebook and section, so that the user can open the rulebook. Nina Žižakić, AI Engineer · 2026-10-12 · RAG
  5. Do agents need a million-token window, or is frequent compaction enough? Agents that read whole environments and many rounds of tool replies cannot do complex tasks in a shorter context, so the window itself has to grow. Olive Song, AI Engineer · 2026-09-04 · Long context
  6. Prefill starts when a request arrives and ends when the first token is written; it computes a key and a value vector for every prompt token. Daniel Kim, AI Engineer · 2026-06-29 · Long context
  7. Prefill is compute-bound and can be parallelised heavily, unlike decode, which is bound by memory. Daniel Kim, AI Engineer · 2026-06-29 · Long context
  8. In a managed RAG pipeline the query is optionally rewritten and embedded, vector and keyword search run in parallel, the lists are fused and optionally reranked, and the top chunks are either returned or passed to a generation model. cloudflare · 2026-10-01 · RAG
  9. Standard attention compares every element of the sequence with every other, so computation grows quadratically with the length of the context. Max Ryabinin, AI Engineer · 2026-04-08 · Long context
  10. An embedding is cached compute: parsing and embedding a codebase is a one-time cost, and at run time the agent queries it and saves tokens, time and money. AI Engineer · 2026-04-10 · RAG
  11. In NVIDIA's RAG Blueprint the LLM is the largest contributor to latency, followed by the reranker; the team scales the LLM service on time to first token (p90 above 2 seconds) and the reranker when its GPU use passes 75%. nvidia · 2025-12-12 · RAG
  12. top 50 + top 50 to 30 to 10: Candidates per list, kept after fusion, and given to the agent (reported by the builders) Eleonora Drykina, AI Engineer · 2026-10-12 · RAG
  13. The limit of one-shot chunk retrieval: an index may find the right document but cannot open it, go to the table, read the surrounding context or verify the answer, so the model must answer from whatever the first retrieval selected. mistral · 2026-08-20 · RAG
  14. One model's release notes list a 1 million token context window and 128,000 maximum output tokens, at $3 per million input tokens. Simon Willison, Simon Willison · 2026-06-30 · Long context
  15. In Codex, GPT-5.4's 1M window is experimental and opt-in through two settings, a context window size and an auto-compact token limit; requests that go past the standard 272K window use up the plan's usage limits at twice the normal rate. OpenAI · 2026-03-05 · Long context
  16. around 4,000 chunks: Chunks in the index built from about 270 PDFs and 6,000 pages (reported by the builders) Nina Žižakić, AI Engineer · 2026-10-12 · RAG
  17. A rulebook above roughly 100k tokens is not dumped into the context: the tool hands back a section list, and a section name that does not match returns the available names so the agent retries. Eleonora Drykina, AI Engineer · 2026-10-12 · RAG
  18. One lab built a 1 million token window because agents that take in every tool response and many rounds of work need more than a short context. Olive Song, AI Engineer · 2026-09-04 · Long context
  19. When a tool returns a large amount of data, the context window overflows, the agent starts to hallucinate and its reasoning degrades. Elizabeth Fuentes Leone, AI Engineer · 2026-06-29 · Long context
  20. Agents change the load on the search desk: the old pattern was one retrieval call up front, the new one is an agent firing many parallel queries at once, so search becomes a highly concurrent tool call and query pricing falls. Latent Space · 2026-03-12 · RAG
  21. 2 to 4 calls: Search calls most questions need; the prompt asks the agent to reconsider before the sixth (reported by the builders) Eleonora Drykina, AI Engineer · 2026-10-12 · RAG
  22. 38 seconds: Median time to answer, the cost of letting the agent search more than once (reported by the builders) Eleonora Drykina, AI Engineer · 2026-10-12 · RAG
  23. Four tasks in, two lost in the middle. A code-review team gave one agent a large context and several tasks at once. It focused on two of the four; those came out well, and the other two were lost in the middle of the context. Nupur Sharma, AI Engineer · 2026-04-08 · Long context
  24. The wrong source, the wrong number. Attaching sources after the fact does not help when retrieval pulled the wrong source (a blog with a wild price), or the right source and the wrong number: a 17 in a filing may be millions, billions or yen, or an earlier year. Vinoo Ganesh, AI Engineer · 2026-10-25 · RAG
  25. 76% vs 18.5%: Score on the 8-needle, 1M-token variant of MRCR v2 for Opus 4.6 against Sonnet 4.5; reported by Anthropic, which calls context rot the common complaint it targets Anthropic · 2026-02-05 · Long context
  26. To tell a retrieval problem from a generation problem, measure the retriever on its own: most teams tweak prompts, chunking and models without knowing whether the retriever surfaced the right context in the first place. mistral · 2026-05-28 · RAG
  27. Summarising to shrink the context can drop the very facts the answer needs. Elizabeth Fuentes Leone, AI Engineer · 2026-06-29 · Long context
  28. A post-processing filter refuses citations that cannot be verified, so a number that is not cited cannot appear in the output. Vinoo Ganesh, AI Engineer · 2026-10-25 · RAG
  29. Do agents need a million-token window, or is frequent compaction enough? Short threads beat long ones even when the window allows long: the Amp team works one change per thread and shares context by reference, because short threads give better results and cost less than one mega-thread. amp · 2025-12-09 · Long context
  30. about 10 million tokens: Corpus size around which BM25 overtakes a file-system agent in a 450-fold scaling study (reported by the authors) Hugging Face · 2026-07-31 · RAG
  31. The agent has four tools from narrow to wide: search chunks, retrieve a whole section in order of section path, retrieve a whole small rulebook, and list the rulebooks. Eleonora Drykina, AI Engineer · 2026-10-12 · RAG
  32. A recursive-language-model harness avoids loading a huge input at all: the agent writes code in a lightweight interpreter that dispatches subagents over chunks of the input (grep, map, reduce), so no single context holds everything. LangChain ships this in Deep Agents with a different model allowed for orchestrator and subagents. langchain · 2026-07-01 · Long context
  33. Do agents need a million-token window, or is frequent compaction enough? With frequent compaction, frontier models lose little or no task accuracy on long-horizon and long-input tasks while keeping short contexts, so long context may be unnecessary. Hugging Face · 2026-11-04 · Long context
  34. Do agents need a million-token window, or is frequent compaction enough? Window size is not the limit: this Opus user finds quality degrades past about 50% of a 1M window, clears at 30 to 40%, finds compaction does little, and restarts with markdown docs that tell the model where to look. throwatdem12311, Hacker News · 2026-07-19 · Long context
  35. Does an agent that greps files replace the ranked index? On about 20 bug tasks agentic search matched vector search in accuracy at a quarter of the cost, because lone chunks lacked the surrounding logic. Jess Wang, AI Engineer · 2026-10-05 · RAG
  36. Does an agent that greps files replace the ranked index? At scale ranking wins: BM25 overtakes a file-system agent around 10 million tokens, and agentic reasoning works best after ranked discovery, not in place of it. Hugging Face · 2026-07-31 · RAG
  37. Does an agent that greps files replace the ranked index? Agentic search does not replace the index but sits on it: Mistral's agent builds on an existing search index and adds tools to open, navigate, read and grep the documents the index finds. mistral · 2026-08-20 · RAG

Cite this page

the version of 2026-12-02
APA
Han, R. (2026, December 2). Long context vs RAG: what is the difference?. Frontier Foundry. https://www.ryanhan.ai/compare/long-context-vs-rag
BibTeX
@misc{han2026-compare-long-context-vs-rag,
  author       = {Han, Ryan},
  title        = {{Long context vs RAG: what is the difference?}},
  howpublished = {Frontier Foundry},
  year         = {2026},
  month        = dec,
  url          = {https://www.ryanhan.ai/compare/long-context-vs-rag}
}

More comparisons

all of them