Book a free call

Context Window Best Practices That Keep Answers Accurate

A context window is the text a model can hold at once, and filling it badly costs accuracy. These practices help you send less, keep what matters, and test results.

Hertiv engineering teamReviewed by a senior engineer
6 min read
Context Window Best Practices That Keep Answers Accurate
On this page

Short answer

Context window best practices are the habits that keep a language model accurate when it works with long inputs: budget tokens before you send anything, retrieve only the passages that matter, summarise what is already settled, and test the result on real examples. The aim is to give the model the smallest context that still contains the answer.

What is a context window?

A context window is the amount of text a language model can hold in memory at once while it works on a request. Everything the model sees, including the instructions, the conversation so far and any documents you attach, counts against that limit.

When the window fills up, the oldest content drops out first, so the model forgets the start of a long conversation or document. That is why long inputs often produce answers that miss facts the model was given at the start.

The window is measured in tokens, which are small chunks of text: a word is usually one or two tokens. A window of 8,000 tokens holds roughly 6,000 words, which sounds generous until you attach a few long documents. For the basics, see what a context window is.

How do you budget tokens before you send a request?

You budget tokens by deciding how much of the window each part of the request may use, before anything is sent. Without a budget, one long document can eat the whole window and leave no room for the instructions or the answer.

A workable budget splits the window into named parts, so each part has a limit and the total stays under the model's maximum.

Part of the requestShare of the windowWhy it matters
Instructions5-10%Must stay visible or the model drifts
Retrieved passages40-50%Where the facts come from
Conversation history20-30%Keeps follow-up questions in context
Room for the answer20-30%Too little room cuts the reply short

Measure the budget in tokens, not characters, and count the tokens before you send. Most teams set the budget at 80% of the window, keeping a margin for the answer to grow.

What should go into the context window?

Only the text the model needs for this one request should go into the context window. Everything else is noise that costs money and makes the answer worse, because the model must weigh every token it sees.

Start with the instructions, then add the passages that answer the question, then the recent conversation that the question depends on. Leave out full documents when a section will do, and leave out old conversation that no longer matters.

Put the most important facts near the start and the end of the context, because models pay more attention to the edges of a long input than to the middle. If a fact must not be missed, repeat it in the instructions rather than burying it in the middle of a document.

When should you retrieve instead of stuffing documents in?

You should retrieve when the documents are longer than the window, or when only a small part of them matters for the question. Retrieval searches the documents first and sends only the matching passages, which keeps the context small and focused.

Stuffing whole documents into the window works for short files, but it breaks down fast. A 50-page manual cannot fit, and even when it does, the model must sift through pages of unrelated text to find one fact.

Retrieval also makes the answer easier to check, because each passage has a source you can open. It also lets you update the source documents without changing the prompt, since the search finds the latest version each time.

For the retrieval pattern in full, see RAG best practices.

For the harder cases, see advanced RAG techniques.

How do you summarise long conversations without losing the facts?

You summarise long conversations by replacing settled turns with a short record of what was decided, keeping the facts and dropping the wording. A good summary keeps names, numbers, dates and decisions, and drops greetings, repetition and dead ends.

Run the summary as its own step, with instructions that list exactly what to keep. Then check the summary against the original conversation before you use it, because a summary that drops a key fact is worse than no summary at all.

Keep the summary short, usually a few hundred tokens, and keep the last few turns in full. Recent turns carry the tone and the open questions, while the summary carries the history. Write the summary in the same plain style as the original, so a new reader can follow it without opening the full conversation.

How do you test whether your context setup works?

You test a context setup by running the same questions through different context sizes and comparing the answers. If a short context gives the same answer as a long one, the extra text was not needed, and you can cut it.

Build a test set of real questions with known good answers, then check each answer for the facts it must contain. Track how often the answer is right, how many tokens each request uses, and how often the model says it cannot find something that is in the documents.

Watch for the middle-of-context problem: answers get worse when the key fact sits in the middle of a long input. If your tests show that pattern, move key facts to the start or end, or split the request into smaller pieces.

Example (hypothetical): a support bot that stopped forgetting

Example (hypothetical): a support team runs a bot that answers from 40 help articles and a ticket history. At first it sends the whole ticket, the last 20 messages and five full articles, about 12,000 tokens per question, and it still misses facts from the start of long tickets.

The team sets a budget: 1,000 tokens for instructions, 4,000 for retrieved passages, 2,000 for the last six messages, and 3,000 left for the answer, a total of 10,000 tokens. It replaces full articles with the two best-matching sections, and replaces old messages with a 300-token summary of what was decided.

The result is 10,000 tokens per question instead of 12,000, a saving of 2,000 tokens, or about one sixth of the cost. More importantly, correct answers rise from 62 of 100 test questions to 84 of 100, because the model now sees the facts instead of drowning in them.

What are the common mistakes?

The most common context window mistakes are filling the window with whole documents, trusting the middle of a long input, and never measuring token use.

  • Sending whole documents. A full manual buries the one fact that matters and costs tokens on every request.
  • Trusting the middle. Facts in the middle of a long context are the ones the model is most likely to miss.
  • No token budget. Without a budget, one part of the request quietly eats the room meant for the answer.
  • Forgetting the answer room. A full window leaves no space for the reply, so answers get cut short.
  • Never testing short contexts. If you never compare short and long contexts, you never learn how much text you can cut.
  • Stale summaries. A summary written once and reused for weeks goes out of date as the conversation moves on.

Keep the context as small as the question allows, and prove it works with a test set. For how token counts shape cost, see tokenization in NLP best practices.

Key takeaways

  • Budget tokens before you send: instructions, retrieved passages, history and room for the answer
  • Send only the passages the question needs, not whole documents
  • Put key facts at the start or end of the context, not in the middle
  • Summarise settled conversation, keeping names, numbers, dates and decisions
  • Test short against long contexts on real questions to find what you can cut

Frequently asked questions

What is a context window?

A context window is the amount of text a language model can hold in memory at once while it works on a request. Everything the model sees, including instructions, conversation and attached documents, counts against that limit.

How many words fit in a context window?

It depends on the model, from a few thousand tokens to far more. A token is roughly three quarters of a word, so an 8,000-token window holds about 6,000 words. Check the model you use, and budget in tokens, not words.

What happens when the context window fills up?

The oldest content drops out first, so the model forgets the start of a long conversation or document. The request may also be cut short, or the model may stop writing. Budgeting tokens and summarising old turns avoids this.

Is a bigger context window always better?

No. Bigger windows cost more per request and make the model less accurate on facts buried in the middle of a long input. A smaller, well-chosen context often gives better answers than a huge one filled with everything.

How do I reduce tokens without losing accuracy?

Retrieve only the passages that match the question, summarise settled conversation, and cut repetition. Then test the shorter context against the longer one on real questions to confirm the answers stay right.

What is the middle-of-context problem?

Models pay more attention to the start and end of a long input than to the middle, so facts placed in the middle are more likely to be missed. Move key facts to the edges, or split the request into smaller pieces.

Found this useful? Share it.
Hertiv engineering team

Written from projects we build for clients: AI and agent systems in production. Every post is reviewed by a senior engineer before publishing and updated when practice changes.

About HertivHow we work

Building an LLM app that handles long documents? Talk to Hertiv.

A senior engineer replies within one business day. Or see our LLM Development service.

Book a free call

Keep reading

All posts

Tell us what you want to build

A senior engineer reads every request and replies within one business day with questions, a rough range, or a call link.

  • NDA on request before any details
  • You own all code, models and IP
  • US, UK and EU time-zone overlap

Your email app should open with your message ready to send. If it does not, write to contact@hertiv.com.

Prefer email? Write to contact@hertiv.com
Estimate costBook a call