Long context vs RAG
37 sourced facts · updatedLong 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 context | RAG | |
|---|---|---|
| How it works | The 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 goes | Into 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 reads | All 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 inputs | One 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 it | 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. 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 wrong | Lost 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 it | With 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
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]