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.

Long-Context vs RAGDiagram with these labels, in reading order: Load Full Document; Query for Passages; Pass Retrieved Data; Generate Output; Input Document; (Full Corpus); Long-Context; Model Processing; Retrieve Relevant; Passages; RAG Model; Processing; Output Generation; (With Context).Load Full DocumentQuery for PassagesPass Retrieved DataGenerate OutputGenerate OutputInput Document(Full Corpus)Long-ContextModel ProcessingRetrieve RelevantPassagesRAG ModelProcessingOutput Generation(With Context)
Long-Context vs RAG Mechanism

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

SituationApproach
Small, bounded source such as one contract or one codebase file, needing whole-document reasoningLong context
Large, dynamic or multi-tenant corpus, or high-volume traffic where cost mattersRAG
Both patterns presentHybrid: retrieve passages, then fill a long context window
Common misconception Long context is not always better. With larger datasets it brings token costs and attention degradation.

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.

Long-Context vs RAGDiagram with these labels, in reading order: Accuracy Drop; Context Size > 100k tokens; Context Quality Low; Switch to RAG; Increase Context Window; Improve Retrieval; Algorithm.Accuracy DropContext Size > 100k tokensContext Quality LowSwitch to RAGIncrease Context WindowImprove RetrievalAlgorithm
Debugging knowledge retrieval methods

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.

  1. Measure answer relevance at different context sizes, for example 10K, 50K, 100K and 128K.
  2. Log where the relevant information sits within the context.
  3. 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.

Back to the knowledge baseRequest an assessment