Skip to content
AI-Native PM

Context budgets: fit the right facts into a finite window

Chapter 5 of 8 in Context & Memory · 17 min

The support assistant answered well at launch, so the team kept adding to what it was given. Someone added the full product wiki to every request, then the customer's complete ticket history, then all twenty retrieved passages instead of the top three. Each addition seemed like a safe way to make answers better. One afternoon a customer asks how long the warranty runs, and the reply quotes terms retired a year ago, taken from deep in the pasted wiki, while the current terms sit unused in the middle of the request. The quality score on the dashboard held steady for months and has been falling for three weeks, and the bill for the same month is triple the usual amount. The team cannot say which addition caused the problem, because every one of them was added to help and none was ever removed.

The model processes every token you send, and you pay for all of it

Every request your product makes is one block of text: the system rules, whatever the product adds from its stored memory, the retrieved passages, and the conversation so far. That block goes into the context window, or window for short: the space that holds everything the model is given on one call. The model processes the whole block on every call, and the provider bills the whole block on every call, whether or not a given passage had anything to do with the answer. The provider does not charge less for the parts that turn out not to matter, and it gives no refund for them.

That pricing would matter little if more context reliably produced better answers, but it does not. Context helps until the facts the answer needs are present, and after that point every additional token is more text the model has to process and more money you have to spend. In Give the model the facts it wasn't trained on we argued for giving the model what its training never covered. This chapter argues for leaving out everything else.

Treat the window as a budget, not a place to store everything: once the right facts are in it, every extra token costs you money and lowers answer quality.

Why a full window produces worse answers

Published research explains why the quality score in the opening scene was falling.

  • Models handle the middle of a long input worst. In a widely replicated 2023 finding, models answered most accurately when the relevant passage sat at the very start or very end of a long input, and markedly worse when it sat in the middle. If you paste a whole wiki into the window, the fact you need usually ends up in exactly that middle region.
  • Filler that is nearly relevant lowers accuracy. A 2025 study measured what practitioners had been reporting: as a window fills with material related to the topic but not needed for the question, accuracy falls even on simple lookups that the same model gets right with a short input. The industry calls this context rot, meaning that answers get worse because of how much text is in the window, not because anything is wrong with the facts themselves.

This leads to a practical rule: a retrieval step that selects the right passages works better than a window filled with everything. You built the lookup in Retrieval: let the product look things up before it answers so the window can hold the three passages a question needs instead of the three hundred that might matter someday, and the version with three passages gives better answers at a fraction of the cost.

Compaction: replace old history with a summary of what mattered

Even with careful retrieval, long sessions fill the window on their own, because every turn (one message and its reply) adds to the conversation history, and old turns stay unless you build something that removes them. Compaction is the standard fix: the product summarizes the older turns into a short digest, puts the digest in the request in place of the full transcript, and keeps only the recent turns word for word.

A model call writes the digest, but what the digest keeps should be set by you, not left to the model's default behavior. Write it down as a product requirement:

  • Keep decisions. "The customer chose the annual plan" must stay in the digest after the twelve turns that led to it are gone.
  • Keep constraints. "This account tier includes no phone support" is a fact every later turn depends on.
  • Keep open questions. If the digest keeps "Still waiting on the invoice number", the product can continue the thread instead of asking the customer again.
  • Drop chit-chat, dead ends, and resolved back-and-forth. They were worth paying for once, and they are not worth paying for again.

What compaction keeps is a product decision: keep decisions, constraints, and open questions, and drop the conversation that produced them.

For timing, a rough rule is enough. Compacting after every turn pays for a summary call each time and throws away detail too early, while waiting until the window is nearly full means answers have already gotten worse. A workable default is to compact once the history fills about half of the space you set aside for it in the budget split (described in the next section), and to cut it to roughly a tenth of its size when you do. Compaction works within a single session. You decided what the product keeps across sessions in Memory: decide what your product remembers.

Write the budget down as a per-request split

Everything above becomes something your team can act on once you write it as numbers. Give every request a total token budget and split it across the four things competing for the window: system rules, memory, retrieved facts, and history. A sensible starting split gives system rules a small fixed share, memory a small share, retrieved facts the largest share (which can grow or shrink from request to request), and history whatever remains.

The diagram shows the four shares filling the window, and answer quality falling once the tokens spent go past the budget. The exact percentages matter less than the decisions you make around them. First, decide the squeeze order, meaning which share gets cut first when a request runs over the budget: compact the history first, then cut the retrieved passages from many to few, then trim memory, and never cut the system rules at runtime, because rules that no longer fit are a design problem to fix, not a share to cut without anyone noticing. Second, write the split down where the team can inspect it, in the repo next to the prompt, so that when quality drops you can see which share grew last month instead of guessing.

You pay for every unneeded token on every call

The cost of extra context is easy to miss because you pay it again on every call. The product re-sends the context with every message, so in a forty-turn conversation with an overfilled window, you pay for the extra material forty times. That is how the bill in the opening scene tripled without any increase in traffic.

Providers reduce the cost of this repetition with prompt caching, a discount on the opening part of a request when it has not changed since the last call, usually the system rules and other stable context. At high volume the discount adds up to real money, and the current rates and caching rules are in the Retrieval Stack Sheet because they change too often to describe here. Caching lowers the price of an overfilled window, but it does nothing about the loss in quality. A token you never send costs nothing and does no harm to answer quality, and if your product runs fleets of agents, the same cost multiplies again for every agent, which is worked out in Economics: what a fleet costs and when it pays.

Try it now

In this drill, which takes about 30 minutes, you produce your own before-and-after evidence for the budget.

Choose a long thread. Pick one long transcript or document thread you own: an exported project discussion, a long-running support ticket, a working doc with weeks of edits. A few thousand words is enough.

Ask five questions about the full thread. Write five questions the thread can answer and note your own answers first. Then paste the entire thread into a model, ask each question, save the answers, and record the request size or cost from your usage dashboard.

Compact it by hand. Write a half-page summary that keeps only decisions, constraints, and open questions (drafting it with the model and editing the draft is fine). Then pick the two excerpts from the thread most relevant to your questions.

Ask the same five questions about the compact version. Use the same model and the same questions, but give it your summary plus the two excerpts as the input. Save the answers and the cost again.

Score both sets blind. Shuffle the ten answers so you cannot tell which run produced which, grade them against your own answers, then unshuffle them and put the two scores next to the two costs. Whichever way the comparison comes out, you now have your own evidence instead of a claim from us.

Scale it down: two questions and one excerpt give you the same comparison in about ten minutes.

Chapter Summary

  • Every request is one block of text, the model processes all of it, and you are billed for all of it on every call.
  • More context helps only until the facts the answer needs are present. After that point, every extra token costs money and lowers answer quality.
  • Models handle the middle of long inputs worst, and filling a window with material that is related but not needed makes answers worse, which the industry calls context rot.
  • A retrieval step that selects a few relevant passages works better than a window filled with everything that might matter someday.
  • Compaction replaces old history with a short digest, and what the digest keeps is a product decision: keep decisions, constraints, and open questions, and drop the small talk.
  • Give every request a written budget split across system rules, memory, retrieved facts, and history, decide in advance which share gets cut first, and keep the split where the team can inspect it.
  • Prompt caching gives a discount on repeated context but does nothing about the loss in quality, and the cheapest token is still the one you never send.
  • A budget keeps the right facts in the window, but those facts also have to be current, which is the subject of Freshness and conflicts: govern the knowledge you answer from.

Sources

  • Liu, N. F. et al. (2023). Lost in the Middle: How Language Models Use Long Contexts. Transactions of the Association for Computational Linguistics.
  • Chroma (2025). Context Rot: How Increasing Input Tokens Impacts LLM Performance. Chroma technical report.
  • Anthropic and OpenAI prompt caching and long-context documentation (last verified July 2026).