Skip to content
mentoor

Topic 1 of 5 · 4 min read

Retrieval versus stuffing the context window

Goal: Given a corpus size, query volume and latency budget, estimate per-query cost and pick retrieval or full-context loading with a stated reason.

If the whole corpus fits in the context window and you will ask many questions about it, load it once and cache it; if it does not fit, changes often or is queried at high volume, retrieve only the pieces you need. This is a cost and accuracy decision, and you can estimate both before you build anything.

Check yourself · 1 of 3

A 50,000-token policy document gets about 15 questions a day. Which approach is the best first version?

Choose one answer

Why it matters

Windows of hundreds of thousands of tokens make "just paste everything" a real option for Claude, Gemini and several open-weight models. It is simple: no index, no chunking, no retrieval bugs. But you pay for every input token on every call, and the model has to find the answer inside all of it.

How to decide

  1. Measure the corpus in tokens, not pages. Use the provider's token counter. If it is larger than the window, or close to it, full-context loading is out.
  2. Multiply by query volume. Cost per day is tokens per call times calls per day times your input price.
  3. Check the cache. Prompt caching bills a repeated prefix at a reduced rate, so a stable corpus loaded first and questions added after can be affordable. Read the current cached-read price and the cache lifetime in the provider docs. If your traffic is bursty, the cache may expire between calls.
  4. Check accuracy. Long prompts have a known weakness: models use information at the start and end better than information in the middle. Test with your own questions, not a demo.
  5. Check freshness. A cached prefix must be rebuilt whenever a document changes.

Before and after

A team has 400,000 tokens of product manuals and expects 2,000 questions a day. They assume an input price of $3 per million tokens (a placeholder; use your own).

Full context, no cache:  0.4M tokens x $3 = $1.20 per query -> $2,400 per day
Retrieval, 6 chunks:     ~3,500 tokens x $3/M = $0.0105     -> about $21 per day

Caching would cut the first line sharply, but it would still send 400,000 tokens on every call and still depend on the model finding one paragraph among them. Retrieval wins at this volume. With 20 questions a day on a 60,000-token handbook, full context is cheaper to build and cheaper in engineering time.

What goes wrong

  • Comparing price per page. Only tokens per call times calls matter.
  • Assuming a big window means perfect recall. Accuracy can fall as the prompt grows, and it varies by model and task.
  • Ignoring latency. Reading a very large prompt takes seconds before the first word appears.
  • Forgetting growth. A corpus that fits today may not fit after next quarter's documents.

A study that compared the two approaches on the same tasks found long context often scored higher, while RAG cost far less. That gap is why many systems route easy questions to retrieval and keep full context for the hard ones.

Examples

Small handbook, few questions

An HR handbook is 60,000 tokens and gets about 20 questions a day. Putting it all in the prompt costs a few cents per day and needs no index. Build the simple version and add retrieval only if the handbook grows or traffic does.

Support archive at scale

A support archive is 8 million tokens and gets 5,000 questions a day. It does not fit in any window, and even a 1 million token slice would cost far more than six retrieved chunks per question. Retrieval is the only workable choice.

Key points

  • Measure the corpus in tokens and multiply by queries per day before choosing; page counts and window size are not the decision.
  • Full-context loading is simplest when the corpus fits comfortably and the question volume is low or the prefix can be cached.
  • Prompt caching reduces the cost of a repeated prefix but does not remove the work of reading it or the need to rebuild it when documents change.
  • Models can miss information in the middle of a long prompt, so test accuracy on your own questions.
  • Retrieval sends a few thousand tokens per query, which is why it wins at high volume or on corpora larger than the window.

Common mistakes

  • Choosing by window size alone without computing tokens per call times calls per day.
  • Assuming the model reads every part of a long prompt equally well.
  • Counting on prompt caching without checking its lifetime against real traffic gaps.
  • Pricing the corpus once and forgetting it grows.

Check yourself · 2 of 3

What does prompt caching change about full-context loading?

Choose one answer

Check yourself · 3 of 3

A team loads a 700,000-token archive into every call and 4,000 users ask questions daily. Which is the strongest reason to move to retrieval?

Choose one answer

Practice items, not counted towards your mastery.

Start here

More for this topic