A large context window of 100k to 1M or more tokens lets you place a whole corpus in the prompt, while RAG retrieves only the relevant slice, and the choice sets your cost, latency and recall.
Whole corpus in the window, or a retrieved slice
A long-context model loads entire documents so it can attend to all of the information at once and relate passages across the document. Retrieval-Augmented Generation (RAG) first selects a focused set of passages from a larger corpus based on the query, which keeps the prompt small.
The two combine. After RAG selects chunks, a long context window can include surrounding material, with a prompt cache storing stable prompt prefixes. For a legal question, RAG might retrieve the key documents on a case and the window then carries the surrounding legal text.
Each method has a failure when used alone. Long context without retrieval hits token limits on extensive corpora. Retrieval without long context can miss connections between retrieved passages.
Token cost, latency and lost-in-the-middle recall
The tempting shortcut is to paste all relevant documents into the input, since that avoids building a retrieval pipeline. It has three costs:
- It consumes a full token budget on every request, and input tokens are billed on every call (a prompt cache can discount a repeated prefix).
- It adds latency because the model processes more data.
- It caps out on corpora larger than the window, so relevant information beyond the limit is ignored.
Recall can also sag in the middle of long inputs. Researchers found that models use information at the start and end of a long input best and lose accuracy on information in the middle (Liu et al., 2023, "Lost in the Middle").
RAG keeps prompts small and cheap and handles data that changes, though it adds a retrieval stack that can miss relevant information. Loading everything resembles holding all records in RAM, while RAG resembles querying an index for the rows you need.
Choosing by corpus size and traffic
| Situation | Approach |
|---|---|
| Small, bounded source such as one contract or one codebase file, needing whole-document reasoning | Long context |
| Large, dynamic or multi-tenant corpus, or high-volume traffic where cost matters | RAG |
| Both patterns present | Hybrid: retrieve passages, then fill a long context window |
Example scenario: quality falls past 50K tokens
Example scenario: a model supports 128K tokens, but answer quality drops sharply past about 50K, with relevance scores down 40%. These numbers are illustrative.
The model cannot attend well to everything in the extended context. Irrelevant and redundant documents dilute the relevant signal, and they add attention cost and latency without improving answers.
- Measure answer relevance at different context sizes, for example 10K, 50K, 100K and 128K.
- Log where the relevant information sits within the context.
- A/B test full context against targeted retrieval.
The fix is targeted retrieval that drops redundant chunks and summarizes older context. This increases retrieval complexity. Monitor relevance scores and latency.