AI agents

Context Window Budget: How Many Chunks to Send and When to Stop

Antonio Evans8 min read

A left-to-right budget bar on a wall whiteboard, marked in 1,000 token segments up to 12,000.
Key points

Key points

  1. 1After you fix chunk size, the number of retrieved chunks is the dial that sets recall, and the token budget is the dial that caps cost and latency.
  2. 2Measure marginal recall, the gain in correctly answered questions from adding one more chunk, and stop when it goes flat.
  3. 3Size the token budget from your latency target first, then divide by chunk size plus per-chunk overhead to get a hard ceiling on chunk count.
  4. 4Reranking a wide candidate pool and sending only the top few chunks usually beats sending many raw chunks, at lower token cost.

The two dials that follow chunk size

Chunk size is the decision everyone argues about, and rightly so: retrieval quality is sensitive to how documents are split, and the gap between a good and a bad strategy can be several points of recall on the same corpus, as Chroma found when it scored retrieval at the token level rather than the document level Chroma's chunking evaluation. But once chunk size is fixed at, say, 800 tokens, two further dials are still open and they are the ones that actually ship in the request:

  1. How many chunks to retrieve. Call this K. It controls how much of the answer-bearing text you even have a chance of sending.
  2. How many tokens of context to send to the generator. This is the budget, bounded by the model's context window and, more tightly, by your latency and cost targets.

These dials interact. Every chunk you retrieve costs retrieval-side work (cheap) and, if you send it, prompt tokens (not cheap, especially on input-side pricing). The practical question is not "what is the best K" but "what is the smallest K that answers nearly as many questions correctly as a much larger K."

Retrieval quality and answer quality are not the same axis. NVIDIA's chunking study measured end-to-end RAG accuracy across multiple datasets and found page-level chunking the most consistent strategy at an average of 0.648 accuracy with the lowest variance, while extreme chunk sizes of 128 and 2,048 tokens generally underperformed NVIDIA's chunking study. That tells you chunk size matters, but it does not tell you how many chunks to send. That is a separate experiment you have to run on your own data.

Why the context window is the wrong ceiling

The first instinct is to send as much as the context window allows. That is usually a mistake for three reasons.

First, cost scales with input tokens. Every query pays for the full prompt, including instructions, the user question, conversation history, and every chunk. A prompt that is three times larger costs roughly three times more on the input side, per query, at scale.

Second, latency scales with prompt length. More tokens to read before the first output token means a slower start, and larger budgets make the slowest requests slower still. Anthropic observed that prompt caching reduced latency by more than 2x and costs by up to 90 percent for repeatedly used prompts, which is a signal of how much day-to-day cost and time sit in the prompt itself Anthropic on contextual retrieval. A generous budget is a tax on every request.

Third, more context is not monotonically better for quality. Relevant information buried in long prompts can be missed, the lost-in-the-middle problem, which is one reason to pass only the optimal amount of information rather than everything that fits Pinecone's chunking guide. Anthropic notes that for knowledge bases under about 200,000 tokens you can consider sending the whole thing with prompt caching, but that approach stops scaling as the corpus grows, which is exactly when retrieval and a deliberate budget matter Anthropic on contextual retrieval.

So the context window is an upper bound, not a target. Your target is a budget derived from latency and cost, and the chunk count is derived from that budget.

A worked example: 800-token chunks, 12,000-token budget

Suppose chunk size is fixed at 800 tokens with 10 percent overlap, so 80 tokens repeat at each boundary and you should count them once. You have a latency target that lets you afford about 12,000 tokens of context per request. Here is the arithmetic.

Per-chunk overhead is not zero. Each chunk arrives with a metadata header (source, section, page), separators, and the occasional citation marker. Budget 50 tokens per chunk for that. So the effective cost per chunk is:

effective_chunk_tokens = chunk_size + overhead
                       = 800 + 50
                       = 850 tokens

max_chunks = floor(budget / effective_chunk_tokens)
           = floor(12000 / 850)
           = 14 chunks

Fourteen is the hard ceiling. It is not the answer. The answer is the K where marginal recall flattens, and that is almost always well below the ceiling. To find it, run an offline evaluation on a labeled set of, say, 300 questions, each with a known correct answer, and record whether the system answered correctly at K = 1, 2, 3, and so on.

A realistic result looks like this (illustrative numbers, replace with your own):

KContext tokens (incl. 50/chunk)Correct answers out of 300Marginal gainAdded latency
1850168n/abaseline
21,700219+51small
32,550243+24small
43,400255+12small
54,250261+6small
65,100264+3small
86,800266+1 per added chunkgrowing
108,500267+0.5growing
1411,9002670large

Three things jump out. First, the steep part of the curve is K = 1 to 4; each additional chunk there buys double-digit answers. Second, from K = 4 onward the curve is flat: going from 4 chunks (3,400 tokens) to 14 chunks (11,900 tokens) adds 12 correct answers at the cost of about 3.5 times the input tokens. Third, the marginal token cost per extra correct answer explodes. At K = 4 you spend 3,400 tokens to answer 255 questions; at K = 14 you spend 11,900 tokens to answer 267. You paid about 8,500 extra tokens per query for 12 more answers.

The stop rule falls out of the table: send the smallest K after which the next chunk adds less than, say, one percentage point of additional correct answers, or costs more in added latency and tokens than it returns. In this example that is K = 4 or K = 5, not the ceiling of 14.

Two caveats. First, the numbers are illustrative; your curve will differ by corpus and question mix. NVIDIA found that factoid queries favored smaller chunks of 256 to 512 tokens while complex analytical queries benefited from larger chunks or page boundaries NVIDIA's chunking study, so segregate your evaluation by query type. Second, recall here means "the correct answer was produced," which is not purely a retrieval measurement. If you want to measure retrieval recall separately, track whether the golden chunk was present in the top K. That is the Pass@k metric Anthropic uses, where contextual embeddings improved Pass@10 from about 87 percent to about 95 percent on a dataset of codebases Anthropic's contextual retrieval cookbook.

Retrieve wide, send narrow: the reranking move

The worked example assumed the K you retrieve is the K you send. The better pattern decouples them: retrieve a wider pool (say 40 to 50 candidates), rerank them with a stronger but more expensive model, then send only the top few. Reranking applies the expensive model to a small candidate set rather than the whole corpus, keeping latency low while surfacing the most relevant results Qdrant's hybrid search with reranking tutorial.

This directly changes your budget arithmetic. You can widen the candidate pool (cheap, since retrieval-only candidates do not enter the prompt) without inflating the token budget (only the reranked top K enters the prompt). Hybrid search, combining dense embeddings with BM25 keyword matching, is a good way to widen the net, because BM25 catches exact identifiers and technical terms that embeddings miss, such as an error code like TS-999 Anthropic on contextual retrieval. Reranking a hybrid result set is a well-trodden production pattern hybrid search and re-ranking in production RAG.

The budget decision after you add reranking becomes: retrieve 40 to 50 candidates, rerank, then send the top K you found in your marginal-recall experiment. You keep the wide recall net without paying prompt tokens for it.

When to lower the budget on purpose

A flat marginal-recall curve is not the only reason to cut K. Lower the budget deliberately in these cases.

  • The query is a lookup, not a synthesis. "What is the refund window?" needs one passage. Send 2 chunks. "Compare the refund policy across three regions" may need 6.
  • Your latency target is tight and interactive. Time to first token dominates perceived speed, and prefill scales with prompt length. If p95 time to first token is your SLA, the context budget is where you claw back milliseconds MLflow on latency trade-offs.
  • Chunks are semantically coherent and context-rich. Parent-child chunking retrieves small child chunks but returns the enclosing parent, typically 500 to 2,000 tokens, which can carry the context without needing many separate chunks parent-child chunking in LangChain. If you use hierarchical retrieval, fewer sends may suffice.
  • Your corpus is small. If the whole knowledge base fits comfortably with prompt caching, retrieve-and-send logic is overhead you may not need yet Anthropic on contextual retrieval.

A decision rule that covers most cases: set the ceiling from the budget, set the working K from marginal recall, split K by query intent (lookup vs. synthesis), and let reranking decouple how wide you retrieve from how narrow you send.

Instrumenting the budget in production

You cannot tune a dial you do not measure. Log four numbers per request: chunks retrieved, chunks sent, prompt tokens, and time to first token. Then compute a token cost per answered question and watch it against your marginal-recall curve offline. If production token cost per answer drifts upward while correct-answer rate holds, your K or your prompt template has grown without justification.

A minimal logging sketch, wired once and reused for evaluation:

record = {
    "query": q,
    "chunks_retrieved": len(candidates),
    "chunks_sent": len(sent),
    "prompt_tokens": prompt_tokens,
    "ttft_ms": ttft_ms,
    "answered_correctly": None,  # filled by evaluation harness
}

The answered-correctly field is blank in production but populated in your offline run, which is what lets you reproduce the marginal-recall table. Unstructured makes the same point from the operations side: retrieval latency covers vector search, document fetch, and any processing that must happen before the model can start generating, and you only optimize it when you can see every stage that contributes time and variation Unstructured on retrieval latency. Without per-stage measurement you will tune the wrong component. Latency budget work starts with measuring end-to-end percentiles and mapping the real request path with shared timestamps MLflow on latency trade-offs.

One lower-level point: a context budget is only as good as what it contains. If chunks genuinely lack the surrounding context needed to interpret them, and a chunk does not make sense to a human without its neighbors, it will not make sense to the model either Pinecone's chunking guide. In that case the fix is contextual preprocessing, not a bigger budget. Contextual retrieval adds chunk-specific context before embedding and reduced retrieval failures by 49 percent, or 67 percent when combined with reranking, on the Anthropic evaluation Anthropic on contextual retrieval. Spending tokens on better chunks beats spending them on more chunks.

If you are running this across several models and want one key for text, embedding, and rerank models, Quanta Inference provides OpenAI-compatible access to those model types through a single prepaid API Quanta Inference, which keeps the budget arithmetic in one place rather than spread across providers.

FAQ

FAQ

What is the difference between the number of chunks and the token budget?

The number of chunks is how many passages you retrieve and send. The token budget is the total room those passages and all other prompt content may occupy. The chunk count is derived from the budget divided by chunk size plus overhead, then trimmed down using marginal-recall measurement.

How do I know when to stop increasing the chunk count?

Run an offline evaluation that records correct-answer rate at K = 1, 2, 3, and so on. Stop at the smallest K after which the next chunk adds little (under about one percentage point, in the worked example) or costs more in tokens and latency than it returns. The steep part of the curve usually ends well below the ceiling.

Should I retrieve many chunks but send only a few?

Yes, when you can rerank. Retrieval-only candidates are cheap because they do not enter the prompt. Rerank a wide pool with a stronger model and send only the top few, keeping prompt tokens low while preserving a wide recall net Qdrant's reranking tutorial.

Does a bigger context window mean I should send more context?

No. Larger budgets raise cost and time to first token, and very long prompts can bury the relevant passage. For knowledge bases under about 200,000 tokens you can consider sending the whole thing with prompt caching, but for larger corpora a measured budget beats a maximal one Anthropic on contextual retrieval.

How much margin should I leave for prompt overhead?

Budget roughly 50 tokens per chunk for metadata headers, separators, and citation markers, plus room for the system prompt, the user question, and conversation history. If you use parent-child chunking, count the parent size of 500 to 2,000 tokens instead of the child size, since the parent is what enters the prompt parent-child chunking.

Sources

Sources

  1. Evaluating Chunking Strategies for Retrieval - Chroma
  2. Finding the Best Chunking Strategy for Accurate AI Responses
  3. Contextual Retrieval in AI Systems - Anthropic
  4. Chunking Strategies for LLM Applications - Pinecone
  5. Enhancing RAG with contextual retrieval | Claude Cookbook
  6. Qdrant Hybrid Search with Reranking
  7. Hybrid Search and Re-Ranking in Production RAG
  8. One post tagged with "latency trade-offs"
  9. Parent-Child Chunking in LangChain for Advanced RAG - Medium
  10. Retrieval Latency Optimization for Production RAG Systems
  11. Parent-Child Chunking: Creating Hierarchical Document Segments ...
About the author

About the author

Antonio Evans
Antonio Evans

Antonio Evans is the founder of Quanta Intelligence and a fractional CTO who builds HIPAA-ready AI systems for health and life-science companies. Before that he was technical co-founder of FriendsEAT for twenty years, CEO of Socialdraft, and a data engineer at IBM. Antonio lives with his dog Santino in Lisbon, Portugal.

All articles