The context window is the maximum number of tokens a model can attend to at once, covering system prompt, history, retrieved documents, user input and output, and it ranges from about 8K to over 1M. Nothing outside it exists to the model.

The context window & context managementDiagram with these labels, in reading order: Send full context; Process context; Generate response; Manage context; Update context; User Input; (Question/Prompt); Context Window; (History + Docs); Model Processing; (Stateless); Output; (Response); Context Management; (Truncate/Summarize/RAG).Send full contextProcess contextGenerate responseManage contextUpdate contextUser Input(Question/Prompt)Context Window(History + Docs)Model Processing(Stateless)Output(Response)Context Management(Truncate/Summarize/RAG)
Context Management Flow

What fills the window on each request

The model keeps no state between calls, so every request must carry the whole context. When history and prompt grow past the limit, you have to decide what to drop. Depending on the API, tokens past the limit are truncated or the request is rejected. With an 8,192-token window, a long conversation plus the current prompt can push the oldest turns out, and any detail in them is gone.

Three techniques keep the context inside the limit:

  • Truncation drops the oldest parts of the conversation.
  • Rolling summaries condense history, trading nuance for space.
  • Retrieval-augmented generation (RAG) fetches only the relevant chunks for each query.

Each technique shifts the balance. Summarizing previous turns loses some detail but keeps the context inside the limit. Retrieving specific chunks gives the model grounded facts for the current query, which tends to improve accuracy. Because the window is fixed during a call, you cannot swap older data back in: you decide in advance which information is essential for the task.

RAM versus disk: an analogy with a hard edge

The window behaves like RAM and a database or RAG store behaves like disk. The analogy breaks at the edge. A computer pages data in and out of RAM. In an LLM call the window is fixed, and anything outside it is absent from the model's view until you send it again in the next request.

Why a bigger window does not remove the problem

A 1M-token model looks like the simple fix. Larger contexts cost more in compute and latency, and recall can drop for facts buried deep in the context, a pattern called "lost in the middle" (Liu et al., 2023, published in TACL). A tighter, more relevant context often gives better answers at lower cost.

ApproachFits whenCost
Long windowWhole-document reasoning, many few-shot examplesHigher cost and latency, weaker recall for buried facts
Retrieval and summariesScale, cost controlDetail lost in summaries, relevance depends on retrieval
Truncation pitfall Over-truncating loses critical information and lowers accuracy.

Example scenario: 40% accuracy after truncation

Suppose a model answers only 40% of user queries correctly (an illustrative figure). Oldest tokens are being cut, so earlier turns disappear and replies lose coherence. Sending excess tokens also raises processing time and cost.

The context window & context managementDiagram with these labels, in reading order: Context window size; Token overflow; Insufficient history; length; Retrieval strategy; mismatch; Adjust context window; Expand history length; Optimize retrieval method.Context window sizeToken overflowInsufficient historylengthRetrieval strategymismatchAdjust context windowExpand history lengthOptimize retrieval method
Context window management diagnostics
  • Measure the average token count per call.
  • Log output relevance over time, focusing on coherence with the user query.
  • A/B test strategies such as summarizing old turns and deduplicating retrieved chunks.
The call Trim and compress the context so that only relevant tokens go in. You lose some history, and quality and cost usually improve. Watch the average token count and relevance metrics.

Back to the knowledge baseRequest an assessment