Context Window Limitations in LLMs: Research and Fixes (2026)

11 min read

Why LLMs get worse as the context window fills (lost in the middle, RULER, NoLiMa, context rot), what long prompts cost, and when retrieval or memory beats full context, with October 2026 results.

Context window limitations are the ways an LLM falls short as its prompt grows: it misses facts buried in the middle, its accuracy drops long before the advertised limit, and every extra token adds cost and latency. The fixes all do the same thing: keep the window small and relevant through retrieval, summarization and external memory.

A 1M-token window, now standard on frontier APIs as of October 2026, doesn’t remove these problems. It moves them. This page covers what the research shows and which fixes work for which problem.

What are context window limitations?

Context window limitations are the constraints on how much text an LLM can use well in one request: a hard token cap, plus accuracy, cost and latency penalties that grow with prompt length. The cap is the advertised size. The penalties start much earlier, which is why a model that accepts 1M tokens can still miss a fact at 50K.

Anthropic’s documentation names the core issue directly: “more context isn’t automatically better. As token count grows, accuracy and recall degrade, a phenomenon known as context rot” (Anthropic, context windows). For the basics of how the window works, see the context window of an LLM.

Lost in the middle: position matters

The best-known finding comes from “Lost in the Middle: How Language Models Use Long Contexts” by Liu et al., published in TACL (arXiv 2307.03172). The authors placed one relevant document among many distractors and moved it around.

Their result: “performance is often highest when relevant information occurs at the beginning or end of the input context,” and it drops when the model has to use information in the middle. The effect showed up even in models built for long contexts. Plotted by position, accuracy forms a U shape.

What this means in practice:

  • Order your prompt. Put instructions and the question at the end, with key material near the start or end. Google’s long-context guide also says placing the query at the end of the prompt generally helps.
  • Don’t trust a single needle test. A model that finds one fact anywhere may still miss facts that need combining across the middle.

Effective vs advertised context window

The advertised window is the most tokens the API accepts. The effective context window is how far the model can go before quality falls apart. Four studies are worth knowing:

StudyWhat it testedKey result
Lost in the Middle (Liu et al., 2023)Multi-document QA and key-value retrieval with the answer at different positionsBest when the fact is at the start or end, worse in the middle
RULER (Hsieh et al., 2024)17 models on 13 tasks beyond needle-in-a-haystackAll claim 32K+, but “only half of them can maintain satisfactory performance at the length of 32K”
NoLiMa (Modarressi et al., ICML 2025)13 models claiming 128K+, needles with no word overlap with the questionAt 32K, 11 models fell below 50% of their short-context baseline; GPT-4o dropped from 99.3% to 69.7%
Context Rot (Chroma, 2025)18 models including GPT-4.1, Claude 4, Gemini 2.5 and Qwen3“LLMs do not maintain consistent performance across input lengths,” even on simple tasks

Why simple needle tests mislead

Nearly every model aced the classic needle-in-a-haystack test in RULER, then dropped sharply on harder tasks such as multi-hop tracing and aggregation. NoLiMa showed why: when the question and the answer share words, attention finds the match easily. Remove the literal overlap and the model has to reason, which gets much harder as the context grows.

Chroma’s report adds two details. A single distractor lowered accuracy, and four lowered it further. And on the LongMemEval benchmark, models scored significantly higher with a focused prompt of about 300 tokens than with the full prompt of about 113K tokens.

What changed since these studies

These benchmarks tested 2023 to 2025 models. Current models with 1M-token windows do better at length, and their providers say so. None of them claim the problem is gone: Anthropic’s current docs still describe context rot, and Google’s long-context guide says that with multiple needles “the model does not perform with the same accuracy.” The safe assumption is that your effective window is smaller than the advertised one until you measure it.

Cost and latency grow with every token

A long context costs money and time on every call, not once.

The model is stateless. The whole conversation is resent on each turn, so an agent with a 300K-token history pays for 300K input tokens per step. Prompt caching lowers the price of repeated prefixes, but cached tokens still take up window space.

Some providers charge more past a threshold. As of October 2026:

  • OpenAI GPT-6.1 Sol: prompts over 272K input tokens cost 2× on input and 1.5× on output, for the whole request.
  • Google Gemini 3.1 Pro (preview): $2 / $12 per million tokens up to 200K, then $4 / $18.
  • xAI grok-4.3: prices double at or above 200K tokens.
  • Anthropic: standard pricing across the 1M window on current models, except Claude Haiku 5.5 above 100K tokens.

A 500K-token prompt to GPT-6.1 Sol costs $2.00 in input alone at the long-context rate ($4 per million). Twenty agent steps at that size is $40 of input. Current figures for every provider are in the LLM context window comparison.

Latency rises too. Self-attention compares tokens with each other, so its cost grows with the square of sequence length (Vaswani et al., 2017). Google’s guide notes that “longer queries will have higher latency (time to first token).”

Context window overflow: what happens at the limit

When a request doesn’t fit, APIs fail loudly. On Anthropic’s API, input over the limit returns a 400 “prompt is too long” error. On newer Claude models, if generation runs past the limit, the response stops with model_context_window_exceeded.

Chat apps fail quietly. Anthropic notes that interfaces like claude.ai can manage the window “first in, first out,” so the oldest turns drop off. Local runtimes do something similar: Ollama allocates a context size based on your VRAM (as low as 4K tokens), and anything beyond it doesn’t fit. Many “the AI forgot what I said” complaints are overflow, not a model bug.

How to fix context window limitations

Every fix follows the same idea: send the model less, but better. In rough order of effort:

  1. Order the prompt. Stable instructions first, key facts near the edges, the question last.
  2. Clear tool output. Drop old tool results once the agent has used them. Anthropic’s API offers tool result clearing for this.
  3. Summarize or compact. Replace old turns with a summary. Anthropic’s server-side compaction “automatically summarizes earlier parts of the conversation” so it can continue past the limit.
  4. Retrieve instead of pasting. Index documents and load only the passages a question needs.
  5. Split work across sub-agents. Each sub-agent works in a clean context and returns a short summary.
  6. Add external memory. Store facts, preferences and past outcomes outside the model, and recall the relevant ones each turn.
  7. Measure. Test your task at the lengths you actually run, not just at 1K tokens.
FixSolvesTrade-off
Prompt orderingLost in the middleFree, but limited effect
Tool result clearingAgent windows filling with logsThe agent can’t re-read cleared output
Summarization / compactionLong conversations, overflowDetails lost in the summary
Retrieval (RAG)Large documents, cost, accuracyRetrieval misses mean wrong answers
Sub-agentsLong multi-step tasksMore calls, coordination overhead
External memory systemCross-session memory, growing historyExtra service, write-time LLM cost

Retrieval

Retrieval-augmented generation stores documents in an index and puts only the top matches into the prompt (Lewis et al., 2020). It turns a 500K-token document into a few thousand relevant tokens, which helps cost, latency and accuracy at once. The weak point is retrieval quality: if the right passage isn’t retrieved, the model can’t use it.

Summarization and compaction

Anthropic’s context engineering guide treats context as “a finite resource with diminishing marginal returns” and recommends compaction: when a conversation nears the limit, condense it and continue in a fresh window, keeping decisions and open issues while dropping redundant tool output. The same guide recommends structured note-taking and sub-agents; what context engineering is compares these techniques across Anthropic, LangChain and Manus. Our page on LLM memory compression covers summarization methods in more depth.

Memory systems

A memory system goes further than summarization. It extracts facts from conversations, stores them outside the model, and recalls the relevant ones on later turns or in later sessions. The window stays small no matter how long the agent has been running.

The Mem0 paper reports the size of the effect: compared with sending the full conversation, its approach cut p95 latency by 91% and token cost by more than 90% (Chhikara et al., 2025). That’s the vendor’s own benchmark, so treat it as an indication, not a guarantee.

Open-source options take different approaches:

  • Letta grew out of MemGPT, which treats the context window like an operating system’s main memory and pages information in and out (Packer et al., 2023).
  • Mem0 extracts and updates facts from conversations into a memory layer an agent queries.
  • Zep builds on Graphiti, a temporal knowledge graph that tracks how facts change over time.
  • Hindsight (MIT license) extracts facts, entities and timestamps when you retain information, then recalls with semantic, keyword, graph and time-based search in parallel, reranked and trimmed to a token budget you set (max_tokens).

For histories far bigger than any window, the data favors Hindsight. On the BEAM benchmark at 1M and 10M tokens of history, Mem0’s own comparison page lists Hindsight at 73.9 and 64.1 against Mem0’s 64.1 and 48.6 (all vendor-run). The catch for a context-window reader: by Mem0’s measurement Hindsight returns 24K-44K tokens per retrieval against Mem0’s under 7K, so lower max_tokens if prompt size is the reason you added memory. Mem0 vs Hindsight has the full numbers.

Which fits depends on your data and stack; our comparison of open-source memory systems goes through the differences.

Long context or memory? Two October 2026 studies

Two papers from October 2026 tested whether a memory system still beats simply giving the model the raw history. Neither is run by a memory vendor, and neither tested Hindsight.

StudySetupResult (self-reported)
MemoryTax (Peng, Shanghai Jiao Tong University)One LoCoMo conversation (419 turns, 152 questions): full context, BM25, Mem0, Zep and three coding agents, each with GPT-4o-mini, GPT-6 Luna and Claude Opus 5.5; one run per cellMem0 beat full context only with GPT-4o-mini (78% vs 74%); with GPT-6 Luna full context led (92% vs 80%); with Opus 5.5 both scored 95%. Mem0’s build alone cost more than a whole full-context run. A coding agent searching the raw history scored 99% with Opus 5.5 for under half the cost of full context (part of that lead came from photo captions only the agents could read)
Is Complex Agentic Memory Always Needed? (Bao et al.)Raw-RAG: dense retrieval plus reranking over the raw history, tested on LoCoMo, LongMemEval, MEME and MemoryAgentBenchRaw-RAG ranked first in six of seven benchmark-model settings, 0.13 to 5.53 points above the strongest agentic memory system compared

What this means for the context window problem:

  • With a strong model and a history that fits, full context is a fair baseline. MemoryTax found memory helped most when the model was weak. But it used one conversation that fits in the window; it says nothing about histories of millions of tokens, where full context isn’t possible.
  • Keep the raw text. Bao et al. found that even full access to transformed memory stores left an accuracy gap against raw evidence. MemoryTax found that a memory written by a weak model caps what a stronger model can answer later.
  • Measure against a simple baseline. Before adding a memory system, compare it with full context (if it fits) and with plain retrieval over the raw history, on your own questions. The test in the next section works for both.

More on these benchmarks is in how to evaluate LLM memory and RAG vs agent memory.

How to measure your effective context window

Published benchmarks won’t match your task. A quick in-house test:

  1. Pick 20 to 50 real questions where you know the correct answer and where it sits in your source material.
  2. Build prompts at several lengths, for example 8K, 32K, 128K and 512K tokens, padding with real but irrelevant material from your domain.
  3. Vary the position of the answer: start, middle, end.
  4. Include questions that need two facts from different places, not just one lookup.
  5. Score each length and position. The length where accuracy drops below what you can accept is your effective window.
  6. Compare with a retrieval baseline that sends only the relevant passages. If it matches or beats the long prompt, use it; it’s cheaper.

Re-run the test when you switch models. Effective context differs a lot between models with the same advertised size.