Context windows have grown from a few thousand tokens to over a million in the space of a couple of years, and the marketing implication has been that this solves the 'AI forgets things' problem: just put everything in the context and let the model figure it out. It doesn't work that way in practice. Larger context windows expand what's technically possible to include, but they don't fix how well a model actually uses everything that's in there, and the evidence is now well documented that model performance on information buried in the middle of a long context degrades measurably compared to information near the start or end. Managing context well is a design problem, not a capacity problem, and it's one of the highest-leverage things a team building long-context AI applications can get right.
Why a bigger context window doesn't fix the actual problem
The intuition that a larger context window solves the 'remembering things' problem treats an LLM's context like a database: put the fact in, retrieve the fact later, done. That's not how attention works inside a transformer. As context length grows, the model has to spread its attention across proportionally more tokens to find what's relevant to any given part of the output, and empirical testing across long-context models consistently shows a real degradation in how reliably information is used based on where in the context it sits, not just whether it's present at all. This is often called the 'lost in the middle' effect: information placed near the beginning or end of a long context tends to be used more reliably than functionally identical information placed in the middle, even though the model technically 'saw' all of it. Practically, this means a 200-page document stuffed into a million-token context window will often produce worse answers about a fact on page 100 than about a fact on page 1 or page 200, purely because of where it landed, not because the information itself was unclear.
The cost and latency you pay for not managing it
Beyond the quality problem, unmanaged context has a direct, ongoing operational cost that compounds with every single request. Most providers price API calls proportional to token count, input and output both, so a system that stuffs 50,000 tokens of mostly-irrelevant history into every call is paying for all 50,000 tokens every time, whether or not the answer depended on more than a few hundred of them. Latency scales with context length too, longer inputs take measurably longer to process before the model produces a first token, which matters directly for any user-facing, real-time application. Teams that solve context 'by just including everything, we have the window for it now' are quietly paying a permanent tax in both dollars and response time for a strategy that, per the point above, doesn't even reliably improve output quality in return.
Chunking and retrieval: the default for large, mostly-irrelevant document sets
When the underlying knowledge base is large and any given query only needs a small, specific slice of it, retrieval-augmented generation is the right default: break the corpus into chunks, index them for semantic search, and at query time retrieve only the chunks relevant to the current question rather than including the whole corpus in context. This keeps the active context small, focused, and squarely in the range where models perform most reliably, while the full knowledge base can be arbitrarily large in storage without ever needing to fit in a single context window. The design decisions that matter here, chunk size, overlap between chunks, and retrieval quality, matter more than context window size ever will for this class of application; a well-tuned retrieval system feeding a modest context window reliably outperforms a poorly-chunked system dumping everything into a huge one.
Summarization and compaction: for long, evolving conversations
Retrieval works well when the knowledge base is static and queries are specific. It works less well for long, evolving conversations or multi-step agent processes, where what matters isn't a specific fact buried in a document, it's the accumulated state of a conversation: decisions already made, constraints already established, context the user assumes the system remembers. For this pattern, the right strategy is periodic summarization or compaction: as a conversation or agent run grows past a manageable length, compress the older portion into a dense summary that preserves decisions and key facts while discarding the turn-by-turn detail that doesn't change the outcome. This trades some fidelity (an edge-case detail from message 3 of a 200-message conversation might genuinely get lost) for keeping the active context small, cheap, and within the range where the model reliably attends to everything in it. The practical failure mode to watch for is summarizing too aggressively, dropping a constraint the user stated early on ('never mention competitor X') that still matters at message 150; good compaction strategies explicitly flag and preserve standing constraints separately from routine conversational detail.
Sliding window with key-fact extraction
A related but distinct strategy for long-running agent processes is a sliding window: keep the most recent N turns or steps in full detail (since recent context is usually most relevant to the immediate next action), while extracting and separately tracking key facts from everything older, structured data points, not prose summaries, that get pulled back into context if and when they become relevant again. This differs from pure summarization in that the older detail isn't just compressed into a paragraph, specific facts are extracted into a structured form (a running list of decisions, entities, and constraints) that can be selectively re-injected rather than always carried forward. This works particularly well for agents executing long multi-step tasks, a coding agent working through a large refactor, a research agent working through a multi-hour investigation, where the immediate next step depends heavily on recent actions but only occasionally needs to reference something from much earlier.
Hierarchical memory: the pattern that scales furthest
For agents operating over genuinely long time horizons, across sessions, over days or weeks, none of the above fully solves the problem alone, because even a well-summarized single conversation eventually needs to interact with information from entirely separate past sessions. Hierarchical memory addresses this by splitting state into layers: a small, fast working context (the current task's immediate detail, kept lean via summarization or sliding-window techniques), and a larger, retrievable long-term store (a searchable memory of past sessions, decisions, and facts) that gets queried and pulled into working context only when relevant, the same way a person doesn't consciously hold their entire life history in active thought but can recall a specific relevant memory when something triggers it. This is architecturally similar to combining retrieval-augmented generation with compaction: the long-term store is retrieved like a knowledge base, and the working context is managed like a compacted conversation. It's more engineering investment than either strategy alone, and it's the pattern that actually scales to agents genuinely meant to operate as persistent, ongoing systems rather than single-session tools.
Which strategy fits which application
| Application type | Primary strategy | Why |
|---|---|---|
| Chatbot with long conversation history | Summarization/compaction of older turns | Recent turns matter most; older detail compresses into decisions/facts that still apply |
| Document analysis over a large corpus | Chunking and retrieval (RAG) | Any given query needs a small, specific slice, not the whole corpus |
| Multi-step agent executing a long task | Sliding window plus key-fact extraction | Recent steps matter most in detail; older facts need selective, structured recall |
| Agent operating across sessions/days | Hierarchical memory (working context plus retrievable long-term store) | No single-session strategy scales to state that must persist and be recalled across time |
| One-shot Q&A over a short, fixed document | Just include the document in context directly | Short enough that chunking or compaction adds complexity without benefit |
