Raphael Friedmann
← Understanding AI

Long context or RAG: when to hand the model the whole document

Context windows now hold a million tokens, so you can often paste the whole document instead of retrieving pieces. What that costs per call, where quality drops, and a decision table for when retrieval still wins.

As of November 2026, every current Claude model accepts 1M tokens of context, and Google states that many Gemini models come with “1 million or more tokens”. On Anthropic’s current tokenizer, 1M tokens is roughly 555,000 words: a contract with all its annexes, a year of meeting minutes, a mid-sized codebase. That gives the RAG pattern a serious alternative: instead of building an index and fetching the right snippets, you send the model everything with every call.

Both approaches work. They fail in different places and cost different amounts, and a handful of measurable properties of your documents and your traffic decide between them.

Two ways to put your text in front of the model#

Long context: the whole document, or the whole set, goes into the prompt with every question. There is no search step, so no search can miss anything.

RAG: documents are split into chunks and indexed once, using embeddings. For each question, a search pulls the few chunks closest to it, and only those go into the prompt.

The difference to keep in mind: RAG can miss, because a chunk that retrieval didn’t find never reaches the model. Long context can’t miss in that sense, but it can overlook: the passage is in the prompt and the model still ignores it.

Cost per call#

Input is billed per token, and with long context you send the whole document every time. Prices for Claude Sonnet 5.5 from Anthropic’s pricing page, as of November 2026: $2 per million input tokens, $2.50 for a 5-minute cache write, $0.10 for a cache read. Anthropic bills the full window at the standard rate (“A 900k-token request is billed at the same per-token rate as a 9k-token request”), but not every model works that way: the same page lists higher prices for Claude Haiku 5.5 prompts over 100,000 tokens. Check your provider’s price list for length tiers before doing the arithmetic.

Take a document set of 400,000 tokens (about 222,000 words at the ratio above) and a 500-token question. For RAG, assume the instructions, the question and five retrieved chunks add up to 5,000 tokens.

  • Long context, no caching: 400,500 × $2 / 1M = $0.801 per question
  • Long context, first call writing the cache: 400,000 × $2.50 / 1M + 500 × $2 / 1M = $1.001
  • Long context, cache hit: 400,000 × $0.10 / 1M + $0.001 = $0.041
  • RAG: 5,000 × $2 / 1M = $0.010
Input cost per question, 400,000-token document set on Claude Sonnet 5.5
whole set, cache write$1.001whole set, no caching$0.801whole set, cache hit$0.041RAG, 5,000-token prompt$0.010
Input only, output costs the same in both setups. Prices: $2 input, $2.50 5-minute cache write, $0.10 cache read per million tokens (Anthropic pricing page, November 2026). The RAG prompt size is an assumption; embedding and index costs are not included.

At 100 questions a day, the gap is large. Without caching, long context costs 100 × $0.801 = $80.10 in input. If every question after the first hits the cache, the total is $1.001 + 99 × $0.041 = $5.06. RAG costs 100 × $0.010 = $1.00, plus embedding and storage. The cached figure depends on timing: the 5-minute cache stays warm only if no more than 5 minutes pass between questions, and every miss costs another write at $1.001, more than a call without caching. Prompt caching covers the lifetimes and the 1-hour option.

Latency#

Before it emits the first output token, the model has to process the whole prompt (prefill), and that work grows with prompt length. Google’s long-context page puts it plainly: “Generally longer queries will have higher latency (time to first token).” A cache hit skips most of that work for the cached prefix, which is the second reason to cache long documents.

On your own hardware, long context is above all a memory problem. The KV cache for a representative 30B model takes about 256 KB per token at FP16. For 400,000 tokens that is 400,000 × 262,144 bytes = about 105 GB, for a single request, on top of the weights. No 32 GB card holds that; RAG with a 5,000-token prompt needs about 1.3 GB of cache by the same arithmetic.

Quality as the prompt grows#

A model that accepts a million tokens does not use all of them equally well.

  • Position. Liu et al. (TACL) found that “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”. The context window lesson describes the same effect for long chats.
  • Length alone. Chroma’s Context Rot report (July 2025) tested 18 models and concluded that they “do not maintain consistent performance across input lengths”, “even on simple tasks”.
  • Several facts at once. Google’s own page separates the easy case from the hard one: with a single fact to find you “can get ~99%”, but with multiple pieces of information “the model does not perform with the same accuracy”.

These studies tested models that are a year or more old, and current models handle long inputs better. The trend has not reversed, though: more text means more chances to overlook the one passage that matters. Anthropic’s prompting guide recommends two countermeasures for prompts of 20k tokens or more: put long documents at the top, above the question and instructions, and ask the model to quote the relevant parts before it answers.

RAG has its own quality problem, covered in the RAG lesson: if chunking cut a table in half or the search ranked the wrong section first, the model answers from the wrong text or not at all.

Limits besides the window#

  • Size. 555,000 words is a lot of contract and very little intranet. A wiki with thousands of pages, a ticket history or a file share does not fit, and some windows are shared with the output: for Gemini 4 models Google states the “1M-token context window is shared across input, thinking, and output tokens”.
  • Selection. Once you have more documents than fit, something has to choose which ones go in. That choice is retrieval, whatever you call it.
  • Freshness. A cached prefix must match exactly, so a changed document invalidates the cache from that point onward, and the next call pays for the write again. RAG only re-indexes the changed file.
  • Access control. Whatever is in the prompt can come out in the answer. With long context, the person asking must be allowed to read the entire set. Users with different rights need different document sets, and different prefixes don’t share a cache. RAG can filter per user at retrieval time, if it is built for that.
  • Citations. Both can cite. With long context the model points into the full documents, for example to page numbers in a PDF; with RAG it cites the retrieved chunk, and that citation is only as useful as the chunk’s link back to its source.

Decision table#

Situation Better fit Why
One document or a small set that fits, the question needs all of it (summarise, compare clauses, find contradictions) Long context Retrieval would supply fragments of an answer that spans the whole text
Many questions on the same documents within minutes Long context with prompt caching Cache hits cost a fraction of normal input
Corpus larger than the window, or growing RAG The window cannot hold it
A few questions a day over a large set RAG The cache goes cold between calls, so each pays full price or a cache write
One fact, ID or ticket number across thousands of pages RAG with keyword search Cheaper, faster, exact match on IDs
Users with different permissions RAG with a per-user filter Long context shows every user the whole set
Documents change several times a day RAG Re-index one file instead of rewriting the cache
Counting or aggregating across all documents Neither alone Extract the data into a table or database first
Low latency required RAG Short prompt, short prefill

You can also combine the two: let retrieval pick the three most relevant documents, not chunks, and pass those in full. The search narrows the set, and the model reads whole documents instead of fragments.

What to do#

  1. Count the tokens of your corpus with your provider’s token counter, not by guessing from page counts. Tokenizers differ between models.
  2. Estimate calls per hour and compare the gaps between them with the cache lifetime. Questions that arrive in bursts favour long context with caching; scattered ones favour RAG.
  3. Check the price list for length tiers and for how cache reads are billed.
  4. Build 20 test questions with known answers, including some whose answer sits in the middle of a long document and some that need two passages. Run both setups and grade them as described in testing a model on your own work.
  5. Settle permissions before content. If users may not all read everything, plan for retrieval with a filter, or separate document sets per group.
  6. If you choose long context, order the prompt: stable documents first, question last.

Bottom line#

A million-token window makes “just send the whole thing” a real option for one document or a small set, especially when many questions arrive close together and prompt caching cuts the input price. The trade-off: a higher cost per call, a longer wait for the first token, and accuracy that drops as the prompt grows, most for facts in the middle and for questions that need several facts at once. RAG stays the better fit for large or changing corpora, per-user permissions, scattered traffic and lookups of exact IDs. Measure your corpus in tokens and your traffic in calls per hour, then test both on your own questions.