Long-Context Models vs RAG

When to put everything in the context window and when retrieval still wins.

Last Updated: 27, Nov 2026

Search Tutorials

--Ads--

Module 12 · Lesson 7 of 8 · Advanced

Long-Context Models vs RAG

When to put everything in the context window and when retrieval still wins.

Current Claude models accept up to one million tokens of input: thousands of pages. That raises a fair question: why build retrieval at all, instead of putting all the documents in the prompt? The answer depends on the size of your data, how often it changes, how many questions you serve, and who is allowed to see what. This lesson compares the two approaches with concrete numbers and shows how to combine them.

Head-to-head

Long context (send everything)RAG (send relevant chunks)
Engineering effortMinimalA pipeline to build and maintain
Data size limitThe context window (about 750,000 words at 1M tokens)Practically unlimited
Cost per questionProportional to corpus size (much lower with caching)Proportional to a few chunks
LatencyHigher; large inputs take time to processLower
Cross-document reasoningStrong: the model sees everything at onceLimited to what was retrieved
Missing informationNothing is missed by retrievalRetrieval misses are possible
FreshnessRebuild the promptRe-index changed documents
Per-user permissionsA different prompt per permission setFilters at retrieval time

Running the numbers

Take a corpus of 500,000 tokens (roughly 1,500 pages). At the time of writing, Claude Opus 5.5 input costs $4 per million tokens and cache reads cost $0.20 per million tokens. Ignoring output tokens:

ApproachInput tokens per questionApproximate input cost per questionPer 10,000 questions
Long context, no caching500,000$2.00$20,000
Long context, corpus cached500,000 (cached)about $0.10about $1,000 plus cache writes
RAG, 8 chunksabout 5,000$0.02$200

Prices change; check the current price list before deciding. The pattern holds: caching makes long context viable for moderate traffic, but RAG stays an order of magnitude cheaper per question, and the gap grows with corpus size. Latency follows the same pattern.

When long context is the right choice

  • The data is small (a few hundred pages), fixed for a while and the same for every user.
  • Questions need the whole picture: "summarise the differences between these five contracts", "find inconsistencies in this specification".
  • You are prototyping and want a quality baseline before investing in a pipeline.
  • Traffic is low, so per-question cost does not matter much.

Combining them

The best systems often use both:

  • Retrieve documents, not chunks. Use retrieval to pick the 3 to 10 most relevant documents, then give the model those documents in full. Retrieval handles scale; long context handles reasoning within documents.
  • Generous context. Send 20 to 50 reranked chunks instead of 5. Current models handle that well, and recall improves.
  • Route by size. If the relevant material fits a budget, send it all; otherwise fall back to chunk retrieval.
route_by_size.py
import anthropic

client = anthropic.Anthropic()

def count(text: str) -> int:
    return client.messages.count_tokens(
        model="claude-opus-5-5", messages=[{"role": "user", "content": text}]).input_tokens

def build_context(question: str, doc_retriever, chunk_retriever, budget: int = 60_000) -> str:
    """Send whole documents when they fit the budget, otherwise the best chunks."""
    docs = doc_retriever.search(question, k=5)             # document-level search
    full = "\n\n".join(f'<document title="{d.metadata.get("title", d.id)}">\n{d.text}\n</document>'
                       for d in docs)
    if count(full) <= budget:
        return full
    chunks = chunk_retriever.search(question, k=20)
    return "\n\n".join(f'<chunk id="{c.id}">\n{c.text}\n</chunk>' for c in chunks)
Evaluate both

If your corpus fits in the context window, run your evaluation set through both a long-context baseline and your RAG pipeline. If RAG is not clearly better on quality, its advantage has to come from cost, latency, freshness or permissions, and you should know which.

Key takeaways

  • Long context is simplest and strongest for small, stable corpora and whole-picture questions.
  • RAG wins on cost, latency, scale, freshness and per-user permissions.
  • Prompt caching narrows the cost gap for long context but does not close it at scale.
  • Combine them: retrieve documents or many chunks and let the model read them in full.