LLM Kitchen
Explanations

Part VII ยท Harnesses

Ch 24. Managing the context

The prompt keeps growing

Every message and every reply is added to the prompt, and the model re-reads all of it on every call. But a model can only read so much at once: its . Long prompts are also slower and cost more. So the harness has to choose what the model sees.

Every message and every reply is added to the prompt, and the model re-reads all of it on every call (Ch 23). But a model can only read so much at once: its (Ch 8). Long before that limit, long prompts also get slower and more expensive. So the harness has to choose what the model sees.

Below is a long chat with the model from Ch 23. You shared six nursery rhymes, each loved by a different child in your class, and asked what happens in each. Then you ask about the first one. To make the problem visible we set a small budget of 600 tokens; the model itself can read far more. Pick what the harness does when the conversation doesnโ€™t fit:

Try it

The context budget

Recorded ยท Qwen2.5-1.5B-Instruct

In a long chat, you shared six nursery rhymes, each loved by a different child in your class, and asked what happens in each. Then you ask: โ€œWhich child in my class loves the rhyme about the cat?โ€

When the conversation doesnโ€™t fit

633 tokens ยท budget 600 ยท Over budget. A real harness canโ€™t send this.

If it could all be sent, the model would answer Lily loves the nursery rhyme about the cat.

Three ways to make room

  • Drop the oldest. Simple, but here the first rhyme was the one you asked about. Without it, the model couldnโ€™t say which child loves it.
  • Summarize. The harness asks the model to shrink old turns into a short note. The note kept โ€œLilyโ€, so the answer was right, but summaries can lose details that turn out to matter.
  • Retrieve. The harness stores old turns outside the prompt and puts back the ones closest in meaning to the question.[1] The cat rhyme came back, and the answer was right.
  • Drop the oldest. Simple, and often fine. But here the first rhyme was the one you asked about. With it gone, the model said the conversation didnโ€™t mention it. Here it admitted the gap; a model can just as easily fill one with a confident guess (Ch 16).
  • Summarize. The harness asks the model to condense the old turns into a short note, then keeps the note instead. The summary kept โ€œLilyโ€, so the answer was right. Summaries lose detail, though, and you canโ€™t always tell in advance which details will matter.
  • Retrieve. The harness keeps the old turns stored outside the prompt, and when a question comes in, finds the ones most similar in meaning, using embeddings like the map in Ch 5, and puts them back.[1][1] The cat rhyme was the closest match to the question, so it came back and the model answered correctly.

Picking by similarity

The harness turned the question and each stored exchange into 384 numbers with MiniLM, the embedding model from Ch 5, and scored each exchange by the cosine of the angle between its vector v and the questionโ€™s vector u:

cosโกฮธ=uโ‹…vโ€–uโ€–โ€–vโ€–

The cat rhyme scored 0.49 and the other five 0.35 to 0.45, so it came first. None scored very low, because every exchange shares โ€œnursery rhymeโ€ and โ€œlovesโ€: close in meaning isnโ€™t always the same as useful. The summary was cheaper still, shrinking the 149-token first exchange to a 30-token note, but it only worked because the note happened to keep the name you later asked about. It also kept a mistake: the modelโ€™s first reply said a cat catches a mouse, which the rhyme never says, and the summary repeated it.

This is , the same idea behind assistants that search your documents: they donโ€™t read everything, they look up what seems relevant and copy it into the prompt. Memory features work the same way: notes saved outside the model and put back into the prompt later.

Smaller than it looks

The window isnโ€™t all room for the prompt: the reply has to fit in it too, so the harness leaves space for it. And models donโ€™t use a full window well. In one test, only half of the models that claimed to read 32,000 tokens still did well at that length on harder tasks.[2] So a shorter prompt can be better even when everything fits.

The window isnโ€™t all room for the prompt. The reply is written into the same window, and so is any thinking the model does first, so the harness has to leave space for them. Anthropicโ€™s API, for example, counts the system prompt, every message, the tool definitions and results, and the output. If the prompt alone is too long, the API refuses it with an error, โ€œprompt is too longโ€; chat apps instead drop the oldest turns for you, the first of the three ways above.[2][2] The 600-token budget here counts only the prompt, to keep the example small.

A window that fits everything isnโ€™t always used well, either. RULER tested 17 models that each claimed to read at least 32,000 tokens. Nearly all of them found a single fact hidden in a long text, but on harder tasks, such as following a chain of references or counting things across the text, only half still did well at 32,000.[3][3] Anthropic calls this decline โ€œcontext rotโ€: as the token count grows, accuracy and recall get worse.[2][2] So trimming the context can help even when everything fits.

Recipe card

Recap

  • The model only knows whatโ€™s in its prompt, and the prompt has a limit.
  • When it fills up, the harness drops, summarizes, or retrieves text.
  • Whatever is left out is simply gone for the model: it may say it doesnโ€™t know, or fill the gap with a guess.
  • The reply has to fit in the window too, and models use long contexts less well than short ones.
  • Retrieval ranks stored text by the cosine similarity of embeddings; close in meaning isnโ€™t always useful.

Next question: retrieval found the cat rhyme by its meaning. Is meaning always the best way to search, and what can the harness keep once the chat is over?

Sources

  1. Patrick Lewis et al. (2020). Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks. NeurIPS 2020.
  2. Cheng-Ping Hsieh et al. (2024). RULER: What's the Real Context Size of Your Long-Context Language Models?. COLM 2024.

Sources

  1. Patrick Lewis et al. (2020). Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks. NeurIPS 2020.
  2. Anthropic (2026). Context windows. Claude Developer Platform documentation. Accessed October 25, 2026.
  3. Cheng-Ping Hsieh et al. (2024). RULER: What's the Real Context Size of Your Long-Context Language Models?. COLM 2024.

Sources

  1. Patrick Lewis et al. (2020). Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks. NeurIPS 2020.
  2. Anthropic (2026). Context windows. Claude Developer Platform documentation. Accessed October 25, 2026.
  3. Cheng-Ping Hsieh et al. (2024). RULER: What's the Real Context Size of Your Long-Context Language Models?. COLM 2024.