Technology · Language models
Context window
Language model input capacity
A context window is the span of text a language model can hold in view at one time.
Everything the model reads and everything it writes passes through this window: the question just asked, the instructions given earlier, the document being summarized, and the words it is about to produce. Text inside the window is available to the model as it works; text outside it is, for practical purposes, invisible. The window is measured in tokens, the small chunks of characters into which text is broken before the model processes it, so a window of a few thousand tokens corresponds to a few thousand word-fragments, roughly a handful of pages.
Overview
Context window
The size of the window sets the scale of the task. A model with a window of a couple of thousand tokens can take in a short email thread or a single web page and answer questions about it, but a full contract, a novel, or a folder of source files will not fit, and whatever does not fit must be cut away, summarized, or fed in piece by piece. A model with a window of a hundred thousand tokens or more can be handed the whole contract at once and asked which clauses conflict. The difference is not a difference in intelligence; it is a difference in how much material the model can consider simultaneously when it produces its answer.
The limit is a consequence of how the model is built. A transformer language model works by attention: at each step, every token in the input is compared with the tokens that came before it, so that the model can weigh which earlier words matter for the current one. That comparison is done over a fixed number of positions, set when the model is trained, and the machinery cannot address positions beyond that count. The window is therefore a hard architectural boundary rather than a soft preference, and raising it is a deliberate engineering effort, covered later in this chapter.
A large advertised window, however, does not by itself mean the model uses the whole of it well. The clearest demonstration comes from a study of two tasks that require finding a piece of information in a long input: multi-document question answering, where the answer lies in one of several supplied documents, and key-value retrieval, where a specific value must be picked out of a long list. Performance was highest when the relevant passage sat at the beginning or the end of the input and fell significantly when it sat in the middle, even for models built specifically for long contexts.[4] The model could accept the text; placing the needed fact in the middle of it made the fact harder to use.
Benchmarks designed to test the window more thoroughly show the same gap between capacity and use. A suite called RULER extends the familiar needle-in-a-haystack test, in which a model must retrieve one hidden sentence from a long stretch of filler, into variations with several needles, multi-hop tracing, and aggregation tasks that require combining scattered facts rather than locating one. Across 17 long-context models and 13 tasks, almost all showed large drops in accuracy as the input grew, and although every model claimed a window of 32,000 tokens or more, only half kept satisfactory performance at that length.[5] Near-perfect scores on the simple retrieval test had been a poor guide to what the models could do with a long input.
Measurements of real use sharpen the point. One study defined a maximum effective context window, the length at which a model still performs reliably on a given kind of problem, and set out to find where performance breaks down across hundreds of thousands of data points from several models. The effective window differed sharply from the advertised one and shifted with the type of problem; a few top-of-the-line models failed with as few as 100 tokens in context, most showed severe accuracy loss by 1,000 tokens, and all fell short of their stated maximum by as much as 99 percent.[1] The advertised figure describes what the model can accept. What it can actually use is a separate and usually smaller quantity, and the rest of this chapter is largely about that distinction: how windows are measured, how they are extended, what they are used for, and why a bigger number on a specification sheet is not the same as a model that reads carefully.
A context window is a capacity, not a guarantee: the model can be handed a long text, but whether it finds and uses what matters inside that text is a separate question.
History
From sliding word windows to million-token inputs
The phrase "context window" is older than the language models that made it famous. In the statistical study of language it named a small span of neighbouring words: to learn what a word means, a model looks at the words that keep it company, and the window fixes how far to the left and right that company is counted. A word's meaning is then represented as a word embedding, a list of numbers arranged so that words used in similar surroundings end up close together in the numerical space. The window is the instrument that decides which surroundings count.

How much span is enough was an empirical question, and the answers were modest. Applying a mutual-information technique first used for English to Chinese text, one study tested how far associations between characters and between words actually reach and concluded that a window of nine characters was large enough to capture most of them.[6] The choice is not neutral: widen the window and a word's representation is shaped by a broader, looser neighbourhood; narrow it and the representation sharpens around immediate collocations. A systematic sweep of window settings for skip-gram models, which learn embeddings by predicting nearby words, found that allowing the window to cross sentence boundaries helped, and that windows reaching mainly to the right of a word performed surprisingly well.[7] The window here is a sliding one, moving along the text word by word, and it is small by design, because its job is to sample local company rather than to hold a document.
The transformer changed what the word meant. Instead of a sliding span of neighbours, the window became the fixed stretch of tokens a model is built and trained to process in one pass, and that length is set before training begins. A model trained on sequences of a few thousand tokens has learned to place and compare tokens within that range; hand it a longer input and the positions run past what it has seen. The boundary is therefore a property of the trained model, not a setting that can be turned up at inference, and the rest of this chapter treats it that way.
Raising the boundary turned out to be a problem of arithmetic as much as of engineering. Position Interpolation, a method for stretching the windows of pretrained models that encode position with rotary embeddings, works by linearly down-scaling the input position indices so that a longer sequence is squeezed into the range the model already knows, rather than extrapolated beyond it; the authors report extending LLaMA models up to 32,768 tokens with fine-tuning of under 1,000 steps, while keeping quality on tasks that fit the original window.[8] The distinction between squeezing and extrapolating matters: pushing positions past the trained range produces attention scores so large that the mechanism breaks down, which is why the interpolation route was the stable one.
Ambition grew quickly once the route was open. LongRoPE reported extending the window of pretrained models to 2,048,000 tokens, using a progressive strategy that first fine-tunes at 256,000-token training lengths and then applies a second positional interpolation, with up to only 1,000 fine-tuning steps in total, and then readjusting the model at short length so that performance on ordinary inputs was not lost.[9] The trajectory across these efforts runs from a nine-character window found sufficient for most character and word associations in Chinese text, through a few thousand tokens fixed at training time, to inputs of two million tokens. What changed at each step was not the basic question, which is always how much surrounding material a model may consult, but the scale at which the answer had to be delivered.
That scale brings its own machinery. Holding a million tokens in view requires positional schemes that can address positions that far out, attention that does not become prohibitively expensive at that length, and training procedures that reach the target length without paying for it all at once. These are the subjects of the sections that follow, which take up how positions are encoded, how windows are extended in practice, and what the enlarged windows are actually used for.
The term began as a small sliding span for learning word meaning and became a fixed, trained capacity for holding a whole document; the continuity is the question of how much surrounding text a model may consult, and the change is the scale of the answer.
How it works
Tokens, attention and the cost of looking back
A language model never sees letters. Before any text reaches it, a tokenizer cuts the text into tokens, the units the model actually counts, and each token is mapped to an integer that indexes a row in a lookup table. A common word is often one token; a rare word, a name, or a number may be split into several fragments, and punctuation and spaces are folded in as they fall. The window is measured in these units rather than in words or pages, which is why a stated capacity in tokens translates only roughly into a length of prose, and why a page of dense code or unusual names can consume more of the window than a page of ordinary English.
The reason the count matters is that every token in the window has to be processed against the others. A transformer model works by self-attention: to compute a representation for a given token, the model compares that token with every token that precedes it, assigning each a weight that says how much it should contribute. The comparison is not a single number but a set of learned projections, so each token is turned into a query, a key and a value, and the weights come from matching the query against the keys of the earlier tokens. This is what lets a pronoun be resolved against a noun several sentences back, or a clause be read in the light of an instruction given at the top of the document. The mechanism is the source of the model's ability to use context at all, and also the source of its cost.
That cost grows steeply with length. If the input holds L tokens, each of them must be compared with the tokens before it, so the number of comparisons rises roughly with the square of L. Doubling the input does not double the work in the attention layers; it multiplies it by about four. The point is concrete enough to have been used as a benchmark of the problem: training on a context length of 8,192 tokens was reported to need sixteen times the computational cost in the self-attention layers as training on 2,048.[10] The same arithmetic governs inference, where a long input must be attended to at every step of generation, and it is the reason long windows are expensive to train, expensive to serve, and worth extending only with methods that avoid paying the full price.
Positions and why they are hard to stretch
Attention as described so far has no sense of order. Matching a query against keys treats the input as a set, so without extra information the sentence "the dog bit the man" and "the man bit the dog" would look the same to the mechanism. Models therefore add positional encoding, a signal attached to each token that records where it sits in the sequence. A widely used scheme is rotary position embedding (RoPE), adopted by models such as LLaMA, PaLM and GPT-NeoX, which rotates the query and key vectors by an angle proportional to the token's position before they are compared. The angle of the rotation encodes the position, and the relative angle between two tokens encodes the distance between them, so the model can learn to weigh nearby tokens differently from distant ones.
RoPE is where the difficulty of a longer window concentrates. The rotations are computed from a fixed set of frequencies chosen when the model is built, and the model learns during training how to interpret the angles that arise within the lengths it sees. Push the positions past that range and the angles become ones the model has never had to interpret, and the attention weights it produces stop being meaningful. This is the failure that makes a trained window a boundary rather than a setting: the model has not learned what a position beyond its training range means, and no amount of input will teach it at inference time.
The methods that extend windows are, in large part, ways of manipulating these rotations so that a longer sequence lands back inside the range the model understands. Position Interpolation does this by linearly down-scaling the input position indices, squeezing a longer sequence into the trained range instead of extrapolating past it; the authors' theoretical study shows the upper bound of interpolation is at least ~600 times smaller than that of extrapolation, which is the formal statement of why squeezing is the stable route and stretching is not.[8] YaRN, a later scheme, takes a more selective approach to the same frequencies and reports reaching longer contexts with about a tenth of the tokens and 2.5 times fewer training steps than previous methods.[11] The details of these techniques belong to the next section; what matters here is that they are all edits to the positional signal, made because the attention mechanism cannot address positions it was not trained on.
Tokens are what the window counts, attention is why each one costs work against all the others, and positional encoding is why the count cannot simply be raised after training.
Extending the window: interpolation, sparse attention and retraining
Every method for giving a trained model a longer window has to solve the same underlying problem: the model has learned to interpret a fixed range of positions, and a longer input pushes it past that range. The techniques differ in where they intervene. Some rewrite the positional signal so that a long sequence is squeezed back into familiar territory; some change how much of the input each token is allowed to look at during training; some grow the window in stages so the model is never asked to jump further than it can learn. None of them changes the model's architecture in any deep sense, which is why they can be applied to models that already exist rather than requiring a new model to be built from scratch.
The first family works directly on the rotations that encode position. Position Interpolation takes the position indices of a long input and linearly down-scales them, so that a sequence of, say, twice the trained length is mapped onto the same span of angles the model already knows. The sequence is compressed rather than stretched, and the model sees positions it has seen before, just packed more tightly. The authors report extending LLaMA models up to 32,768 tokens with fine-tuning of under 1,000 steps, while preserving quality relatively well on tasks that fit inside the original window. The reason for compressing rather than extrapolating is arithmetic: pushing positions past the trained range produces attention scores so large that the mechanism breaks down, and the authors' analysis puts the upper bound on interpolation error at least some six hundred times smaller than that of extrapolation.[8] Squeezing is stable; stretching is not.
YaRN refines the same idea by treating the frequencies that make up the rotary encoding unequally. Rather than scaling every frequency by the same factor, it adjusts them selectively, on the reasoning that some dimensions of the encoding carry fine positional detail that should be preserved while others can be stretched. The reported result is a compute-efficient route to longer contexts, requiring about a tenth of the tokens and 2.5 times fewer training steps than previous methods, and the extended models can extrapolate somewhat beyond the length they were fine-tuned on.[11] The gain comes from not spending training effort on dimensions that do not need it.
LongRoPE pushes the same line of attack to a much larger scale by exploiting two kinds of non-uniformity in positional interpolation, found through an efficient search, which give a better starting point for fine-tuning and allow an eightfold extension even before any fine-tuning is done. It then grows the window in two stages: a model is first fine-tuned at a length of 256,000 tokens, and a second round of interpolation is applied to that already-extended model to reach 2,048,000 tokens, with up to only 1,000 fine-tuning steps at within 256k training lengths.[9] A final readjustment at short length recovers performance on ordinary inputs, so that the enormous window does not come at the cost of the small one. The pattern across all three methods is the same: the positional encoding is edited, the model is fine-tuned briefly to absorb the edit, and the result is a model that can address positions it was never trained on.
Changing what the model looks at
A second family leaves positions alone and attacks the cost of attention instead. The obstacle is that self-attention compares every token with every earlier token, so the work grows with the square of the input length, and training at long lengths is correspondingly expensive. LongLoRA observes that dense global attention is needed when the model is actually answering, but not when it is being fine-tuned: during fine-tuning, attention can be restricted to sparse local windows, with the windows shifted between layers so that information still propagates across the whole sequence. The saving is substantial, and the shifted sparse attention can be implemented with only two lines of code in training, while being optional in inference; dense global attention is still needed during inference. Combined with an improved parameter-efficient fine-tuning setup in which the embedding and normalization layers are made trainable, it extends Llama2 7B from a 4,000-token window to 100,000, or Llama2 70B to 32,000, on a single machine with eight A100 GPUs.[10] The model keeps its original architecture; only the training procedure changes.
Growing the window in stages
The third family is about the order in which training happens rather than the arithmetic of position. Training directly at the target length is expensive, so several methods decouple the length used for training from the length the model can eventually handle. Positional Skip-wise Training (PoSE) simulates a long input inside a short training window: the original window is divided into chunks, and small bias terms are added to each chunk's position indices so that the chunks appear to sit at scattered places along a much longer sequence, with the biases and chunk lengths varied for every training example.[12] The model therefore sees every position within the target length without ever processing a sequence that long. With this method, LLaMA was extended to 128,000 tokens using a training window of only 2,000, at greatly reduced memory and time cost compared with fine-tuning at full length.[12]
Staged growth is also how large models are trained from the start. Evo 2, a biological foundation model trained on genomic sequences, was first pretrained at a context length of 8,192 tokens, with data weighting focused on genic windows to learn functional genetic elements, and was then put through a multi-stage midtraining phase over which the window was stretched to 1 million tokens, so that it could learn relationships between elements separated by long stretches of genome. The authors describe this as matching best practice in natural language, where starting short improves both efficiency and final quality.[13] The two phases teach different things: the short window teaches what a gene looks like, and the long window teaches how distant parts of a genome relate.
Extension methods are edits to position, to attention, or to the training schedule; all of them exist because a window is fixed at training time, and all of them work by making a longer input resemble the shorter one the model already understands.
Uses
What long windows are used for
A long window is not an end in itself; it is useful because some tasks cannot be done without one. The clearest case is a single long document. A contract, a court judgment, a research paper or a novel can be handed to the model whole, and questions can be asked about it without first deciding which pages to keep. Summarization is the same task in reverse: the model reads the whole text and produces a shorter one, and the quality of the summary depends on the model having seen all of it rather than a selection made in advance. When the input fits, the window replaces the work of choosing what to show the model, and that choice is exactly where information tends to get lost.

Putting documents in front of the model
A second use is retrieval-augmented generation, in which a separate search step finds documents relevant to a question and those documents are placed in the model's input before it answers. The usual way to build such a system is to change the model's architecture so it can absorb outside text, which complicates deployment. A simpler route, called In-Context RALM, leaves the model untouched and simply prepends the retrieved documents to the input, with no further training; building on general-purpose retrievers, this produced large gains in language modelling performance across model sizes and corpora.[14] The window is what makes the approach possible: the retrieved text has to fit somewhere, and the input is where it goes. The same logic explains why retrieval and long windows are often discussed as rivals, a comparison taken up later.
Many documents at once
Multi-document work raises the demand again. Answering a question whose evidence is spread across several sources means holding all of them in view and combining what each says, and a window large enough for the whole set removes the need to summarize each source first. Code is a demanding version of the same problem. A single function usually fits in any modest window, but real software does not: a change in one file has consequences in another, and understanding what a program does requires following calls and dependencies across the repository.
A benchmark built for this setting, RepoReasoner, evaluates two abilities, predicting the output of code whose execution reasoning spans files and predicting call chains that express how parts of the repository depend on one another, and it constructs its ground truth by tracing test executions rather than by asking a model. Even under oracle context, the best of seven evaluated models reached only 69.1 percent Pass@1 on output prediction, and on call-chain prediction the models showed high precision but low recall, meaning they named correct dependencies but missed many of them.[2] Fitting the repository into the window is a precondition for the task, not a solution to it.
Reading a genome
The most literal use of a long window is in biology, where the text is DNA and the "document" is a genome. Genomes carry information at very different distances: a regulatory element may sit next to the gene it controls, or hundreds of thousands of bases away, and the relationships between distant elements are part of what the sequence means. A model trained only on short stretches can learn what a gene looks like locally but cannot see those long-range relationships. Evo 2, a biological foundation model trained on a curated genomic atlas spanning all domains of life, was built with a 1 million token context window at single-nucleotide resolution.[13] The window is measured in the same units as the sequence itself, which is what allows the model to take in a stretch of genome long enough to contain both an element and its distant regulator.
The uses of such a model follow from what a long view permits. Evo 2 predicts the functional impact of genetic variants, from noncoding mutations to clinically significant BRCA1 variants, without task-specific fine-tuning, and its internal representations were found to correspond to biological features including exon-intron boundaries, transcription factor binding sites and prophage regions. It also generates mitochondrial, prokaryotic and eukaryotic sequences at genome scale, and produces experimentally validated chromatin accessibility patterns when guided by predictive models and search at inference time.[13] None of these tasks is a matter of retrieving one fact from a long input; each requires the model to have weighed material spread across a long sequence and to produce something new from it. That is a different demand from question answering over a document, and it shows that the value of a long window depends on what the task asks the model to do with the span once it has it.
Long windows serve tasks where the material cannot be usefully cut down in advance: a whole document, a set of retrieved sources, a repository of code, or a stretch of genome whose distant parts matter to each other.
Research
Does a bigger window mean better use of it
A model's stated window and its working window are two different quantities, and the gap between them is where most of the practical difficulty lies. The stated figure is what the architecture can accept: how many tokens can be passed in before the machinery runs out of positions. The working figure is how much of that input the model can actually draw on when it answers. Nothing in the design of a long-context model guarantees that the second matches the first, and a body of evidence gathered since long windows became common suggests it often does not.
The earliest clear sign came from varying where the needed information sat rather than how much of it there was. In multi-document question answering, a model is given several documents and a question whose answer lies in exactly one of them; in key-value retrieval, it must pick a specific value out of a long list of paired entries. Both tasks hold the amount of relevant material constant and change only its position in the input. Performance was highest when the relevant passage came at the beginning or the end of the context and dropped significantly when it sat in the middle, and this held even for models built specifically to handle long inputs.[4] The finding is often summarized as a tendency to lose information in the middle. What it shows is that the window is not used uniformly: the same fact is more or less accessible to the model depending on where in the span it happens to fall, which means a document that fits comfortably inside the window can still be partly unread in practice.
Retrieval tests that ask for a single hidden sentence had suggested the problem was solved, and a broader benchmark showed why that impression was misleading. RULER takes the familiar needle-in-a-haystack setup, in which one target passage must be found among long filler text, and varies it: several needles instead of one, questions that require tracing a chain of references across the input, and aggregation tasks that ask the model to collect and combine facts scattered throughout rather than locate a single one. Across 17 long-context models and 13 tasks, almost all showed large accuracy drops as the input grew, and although every model claimed a window of 32,000 tokens or more, only half maintained satisfactory performance at that length.[5] A model can score near-perfectly on simple retrieval and still falter once the task requires assembling material from several places, because finding one sentence and reasoning over a whole span place different demands on the same window.
The distinction between accepting an input and using it has been given a name. The maximum effective context window is the length at which a model still performs reliably on a given kind of problem, as opposed to the maximum context window it advertises. Measuring it means testing a model across a range of input sizes and problem types until performance breaks down. Across hundreds of thousands of data points from several models, the effective window differed sharply from the advertised one and shifted with the type of problem; a few top-of-the-line models failed with as few as 100 tokens in context, most showed severe accuracy loss by 1,000 tokens, and all fell short of their stated maximum by as much as 99 percent.[1] The result is striking precisely because the shortfalls appeared at lengths far below the advertised limits, in the range where a model would be expected to be on solid ground. It also indicates that the effective window is not one number per model but a property of the pairing between model and task.
If a long window is unreliable, an obvious alternative is to keep the window short and supply only what is needed. Retrieval-augmented generation does exactly this: a separate search step selects documents relevant to the query, and those documents are placed in the model's input before it answers, so the model reads a small, chosen set rather than everything available. The two approaches can be compared directly. Using two pretrained models, a 43B GPT and Llama2-70B, one comparison found that a model with a 4,000-token window using simple retrieval at generation time achieved performance comparable to a fine-tuned model with a 16,000-token window on long-context tasks, while requiring much less computation. Retrieval also improved results regardless of how large the model's extended window was, and the best configuration tested, a retrieval-augmented Llama2-70B with a 32,000-token window, outperformed GPT-3.5-turbo-16k and Davinci003 on an average over nine long-context tasks, including question answering, query-based summarization and in-context learning, and beat its own non-retrieval baseline while generating faster.[15] The lesson is not that long windows are useless but that selection can substitute for capacity: a small window filled with the right material can match a large window filled with everything.
The reverse case has also been argued, and it turns on what happens when a long input contains much that is irrelevant. A long-context model given an entire document must locate the pertinent passages itself, and the more surrounding text there is, the more its focus is spread across material that does not matter. An alternative called order-preserve retrieval-augmented generation retrieves chunks of the source and keeps them in their original order, and its behavior as more chunks are added is not a straight line: answer quality first rises, then declines, forming an inverted U-shaped curve, with sweet points at which it achieves higher answer quality than a long-context model reading the whole input, using far fewer tokens.[16] The shape of that curve is the important part. Adding relevant material helps up to a point, and past that point the added text begins to dilute the model's attention rather than inform it, which is the same underlying difficulty seen from the other side.
Taken together, these results describe a consistent pattern. A larger window raises the ceiling on what a model can be given, but the fraction of that input a model actually uses varies with where the information sits, how many separate pieces must be combined, and how much irrelevant material surrounds them. The practical consequence is that the advertised number is a poor guide to what a model will do with a long document, and that deciding what to put in front of the model remains a live design question rather than one that a bigger window settles. The costs that make long inputs expensive to serve, and the benchmarks that can flatter a model into looking better at long inputs than it is, are taken up later.
A window is a limit on what can be supplied, not a measure of what will be used; position, task type and the amount of surrounding noise all move the effective size well below the advertised one.
Risks and limits
Costs, failure modes and misleading benchmarks
The price of a long window is paid twice: once in computation and once in the quality of attention. The computational side follows from the arithmetic of self-attention, where each token is compared with every token before it, so the work rises with the square of the input length. Training at 8,192 tokens was reported to need sixteen times the computational cost in the self-attention layers as training at 2,048.[10] The same scaling governs inference, where a long input must be attended to at every step of generation, and it is why long windows are expensive to serve as well as to train. Memory follows the same curve, since the stored keys and values for every token in the window must be kept available while the model generates.

The second cost is subtler and does not show up in a compute budget. A model given a very long input must locate the relevant passages itself, and the more surrounding text there is, the more its attention is spread across material that does not matter. This is not a failure of capacity but a consequence of how attention distributes weight: every token in the window competes for consideration, and irrelevant tokens dilute the focus that relevant ones receive. The effect can be measured by varying how much retrieved material is supplied. An approach called order-preserve retrieval-augmented generation retrieves chunks of a source document and keeps them in their original order, and as the number of chunks grows, answer quality first rises and then declines, forming an inverted U-shaped curve.
At the sweet points on that curve, the method could achieve higher answer quality than a long-context model reading the whole input, while using much fewer tokens.[16] The shape matters more than the specific numbers: adding relevant material helps up to a point, and past that point the added text begins to dilute the model's attention rather than inform it. A long window therefore does not simply remove the need to choose what to show the model; it moves the choice inside the model, where it is made less reliably.
Why perplexity misleads
Judging whether a long-context model works requires a measure, and the standard one has been perplexity, the model's average surprise at each token it encounters, computed across the whole input. A model that predicts the next token well will have low perplexity, and the measure is cheap to compute on any text. Its weakness in the long-context setting is that it averages over all tokens equally. Most tokens in a long document are predictable from their immediate neighbours and carry little information about whether the model has understood the document as a whole; a few key tokens carry most of that information, and averaging buries their contribution under the mass of easy predictions. A model can therefore post an excellent perplexity score while handling the parts of a long input that matter poorly.
A metric built to correct this, called LongPPL, identifies the key tokens by contrasting a token's predictability in its long context against its predictability in a short one, and scores the model on those tokens instead. Across a range of long-context benchmarks, LongPPL correlated strongly with actual performance, with a Pearson correlation of -0.96, far exceeding traditional perplexity as a predictor.[3] The practical lesson is that a low perplexity figure is not evidence that a model uses a long window well, and that evaluating long-context ability requires measures that concentrate on the tokens where understanding shows.
Benchmarks that reward recall but not reasoning
The benchmarks themselves can flatter a model in the same way. The needle-in-a-haystack test, in which a model must retrieve one hidden passage from a long stretch of filler, rewards exactly the ability to locate a single fact, and a model that does this perfectly may still be unable to do anything more demanding with the same input. RULER was built to expose the gap, adding variations with several needles, multi-hop tracing and aggregation tasks that require collecting and combining scattered facts rather than finding one. Near-perfect scores on simple retrieval had been a poor guide to what the models could do.
A newer benchmark pushes the point further by asking for long outputs rather than short answers. LongProc consists of six procedural generation tasks, such as extracting structured information from HTML pages into a tabular format or executing a search procedure to build a travel plan, which require integrating information dispersed across a long input and producing structured output of up to 8,000 tokens. Of 23 long-context models evaluated, all claimed windows above 32,000 tokens, yet open-weight models typically faltered on tasks requiring only 2,000 output tokens, and closed-source models such as GPT-4o showed significant degradation at 8,000.[17] The benchmark also found that models struggle to maintain long-range coherence across a long generation, a failure that retrieval-style tests cannot detect because they ask for a single short answer. What these benchmarks share is a demand that the model do something with the material it has found, and it is precisely there that the gap between accepting a long input and reasoning over it becomes visible.
The costs of a long window are quadratic computation, diluted attention as irrelevant text accumulates, and benchmarks that reward finding one fact while missing the harder work of combining many.
Later developments
Where context-window research is heading
The methods described so far mostly buy a longer window by training: a brief fine-tuning pass teaches the model to interpret positions it has never seen. A newer line of work asks whether that pass is needed at all. Training-free extrapolation adjusts the positional encoding at inference time and leaves the weights untouched. One such method, Dimension-Wise Positional Embeddings Manipulation, treats the dimensions of the rotary encoding unequally: it measures the effective length each dimension can support, then rescales the position indices of only the dimensions that matter for extension, reusing the pretrained embeddings elsewhere. The reported result is that DPE enables Llama3-8k 8B to support context windows of 128k tokens without continual training, and improves Llama 3.1 70B by over 18 points on the RULER benchmark.[18] The appeal is practical: if the positional signal can be repaired after training, the cost of a longer window falls to a configuration change rather than a training run.

A related idea is that the window need not be fixed at all. Adaptive context means letting the model's usable span vary with the query, so that a simple question is answered over a short span and a complex one over a longer span, without retraining. One proposal, CoWPE, adjusts the base frequency of the rotary encoding and scales the attention logits, combining neighbour attention with bi-level grouped attention that captures interdependence among tokens far apart, and requires no fine-tuning.[19] The motivation is that a fixed window spends the same capacity on every input, while the difficulty of the input varies; the open question is whether the complexity of a query can be judged reliably enough, before the model has read it, to set the span correctly.
Compression takes a different route: rather than extend the window, shrink what has to fit inside it. The most developed version stacks two short-context models, a lower one that compresses a long input into compact multi-grained representations and an upper one that decodes from them, with information passed only at the lowest layers to avoid long forward paths and redundant cross-attention. Because the two models are drawn from the same underlying layers, the arrangement is called self-injection, and a tree-structured index lets the upper model retrieve the level of detail a query needs. Trained on sequences of only 8,000 tokens, the system generalizes to inputs beyond 128,000, with reported inference speedups of twice over streaming and three times over encoder-decoder designs.[20] The window stays small; the material is made to fit.
Running beneath these techniques is a shift in what the field treats as the hard problem. A survey of the literature argues that context injection strategy, meaning how information is chosen, encoded and delivered to the model at inference time, rather than raw context capacity, is the defining challenge for deploying long-context models. It sorts existing systems into five families, direct injection, compression, retrieval, memory and hybrid agentic approaches, and analyzes them along three axes: selection of what information is chosen, representation of how it is encoded, and scheduling of when it is delivered during inference. The survey's assessment is that current work overwhelmingly optimizes selection while representation and scheduling remain largely unexplored, and that progress on those two axes, rather than further scaling of windows, is the most promising route to closing the gap between nominal and effective capacity.[21] That framing returns to the distinction drawn earlier in this chapter: a window is a limit on what can be supplied, and the work of deciding what to supply, and in what form, is where the remaining gains are expected to lie.
The direction of travel is away from the size of the window and toward what is put in it: positions repaired without retraining, spans that adapt to the query, long inputs compressed before they arrive, and delivery scheduled rather than left to capacity.
Key studies
| Year | Study | Sample | Design | Finding |
|---|---|---|---|---|
| 2023 | Chen et al.[8] | LLaMA models from 7B to 65B | positional interpolation with minimal fine-tuning within 1000 steps | The method extended context windows to up to 32768 while preserving quality on tasks within the original window. |
| 2023 | Bowen et al.[11] | LLaMA models | context extension method requiring 10x fewer tokens and 2.5x fewer training steps | The models handled context lengths well beyond the length used in their original pre-training. |
| 2023 | Zhu et al.[12] | LLaMA models | positional skip-wise training with a 2k training context window | The LLaMA model reached 128k tokens while using less memory and time than full-length fine-tuning. |
| 2023 | Chen et al.[10] | Llama2 models from 7B and 13B to 70B | efficient fine-tuning with shifted sparse attention and improved LoRA | On one machine with 8 A100 GPUs, LongLoRA took Llama2 7B from a 4k context to 100k and Llama2 70B to 32k. |
| 2023 | Xu et al.[15] | a proprietary 43B GPT and Llama2-70B | comparison of retrieval augmentation with long context extension on nine long-context tasks | A 4K-window model with retrieval matched a fine-tuned 16K model while taking much less computation. |
| 2023 | Ram et al.[14] | OPT models up to 66B parameters and GPT-2 models | in-context retrieval with a BM25 retriever, stride 4 tokens, query length 32 tokens | Retrieval improved a 6.7B parameter OPT model to match a 66B parameter OPT model. |
| 2024 | Liu et al.[4] | language models including GPT-3.5-Turbo and its 16K version | multi-document question answering and key-value retrieval with varied positions | GPT-3.5-Turbo's score could drop by more than 20 percent, and the worst 20- and 30-document settings fell below the closed-book score of 56.1 percent. |
| 2024 | Hsieh et al.[5] | 17 long-context language models | synthetic benchmark of 13 representative tasks | Only half of the models kept satisfactory performance at 32K tokens despite all claiming 32K or more. |
| 2024 | Ding et al.[9] | LLaMA2 and Mistral models | progressive positional interpolation with up to 1k fine-tuning steps at within 256k training lengths | The context window was extended to 2048k tokens while maintaining performance at the original short context window. |
| 2025 | Ye et al.[17] | 23 long-context models, including instruction-tuned and reasoning models | procedural generation benchmark at three difficulty levels | Open-weight models typically faltered on 2K-token tasks, and GPT-4o degraded significantly on 8K-token tasks. |
| 2025 | Lu et al.[18] | Llama3-8k 8B and Llama3.1 70B | training-free manipulation of positional embeddings by dimension | Llama3-8k 8B supported 128k tokens without continual training, and Llama3.1 70B gained over 18 points on RULER. |
| 2026 | Paulsen[1] | several models, both open-source and proprietary, across hundreds of thousands of data points | benchmark testing of context window effectiveness over sizes and problem types | A few top models failed with as few as 100 tokens in context, and all models fell short of their stated maximum by as much as more than 99 percent. |
See also
References
- Paulsen, N. (2026). Context Is What You Need: The Maximum Effective Context Window for Real World Limits of LLMs. Advances in Artificial Intelligence and Machine Learning, 06(01), 01-26. doi:10.54364/aaiml.2026.61268
- Wang, Y., Wang, S., Wang, Y., Zhang, B., Guo, D., Chen, J., & Zheng, Z. (2026). RepoReasoner: Evaluating Repository-Level Code Reasoning Ability of Long-Context Language Models. Proceedings of the ACM on Software Engineering, 3(FSE), 2790-2812. doi:10.1145/3808131
- Lizhe, F., Wang, Y., Liu, Z., Zhang, C., Jegelka, S., Gao, J., Ding, B., & Wang, Y. (2024). What is Wrong with Perplexity for Long-context Language Modeling? arXiv. doi:10.48550/arxiv.2410.23771 Free full text
- Liu, N. F., Lin, K., Hewitt, J., Paranjape, A., Bevilacqua, M., Petroni, F., & Liang, P. (2024). Lost in the Middle: How Language Models Use Long Contexts. Transactions of the Association for Computational Linguistics, 12, 157-173. doi:10.1162/tacl_a_00638
- Hsieh, C. P., Sun, S., Kriman, S., Acharya, S., Rekesh, D., Fei, J., Yang, Z., & Boris, G. (2024). RULER: What's the Real Context Size of Your Long-Context Language Models? arXiv. doi:10.48550/arxiv.2404.06654 Free full text
- HUNG, K. Y., LUK, R., YEUNG, D., CHUNG, K., & SHU, W. (2001). Determination of Context Window Size. International Journal of Computer Processing of Languages, 14(01), 71-80. doi:10.1142/s0219427901000291
- Lison, P., & Kutuzov, A. (2017). Redefining Context Windows for Word Embedding Models: An Experimental Study. arXiv. doi:10.48550/arxiv.1704.05781 Free full text
- Chen, S., Sherman, W., Chen, L., & Tian, Y. (2023). Extending Context Window of Large Language Models via Positional Interpolation. arXiv. doi:10.48550/arxiv.2306.15595 Free full text
- Ding, Y., Zhang, L. L., Zhang, C., Xu, Y., Ning, S., Xu, J., Yang, F., & Yang, M. (2024). LongRoPE: Extending LLM Context Window Beyond 2 Million Tokens. arXiv. doi:10.48550/arxiv.2402.13753 Free full text
- Chen, Y., Qian, S., Tang, H., Lai, X., Liu, Z., Han, S., & Jia, J. (2023). LongLoRA: Efficient Fine-tuning of Long-Context Large Language Models. arXiv. doi:10.48550/arxiv.2309.12307 Free full text
- Bowen, P., Quesnelle, J., Fan, H., & Shippole, E. (2023). YaRN: Efficient Context Window Extension of Large Language Models. arXiv. doi:10.48550/arxiv.2309.00071 Free full text
- Zhu, D., Yang, N., Wang, L., Song, Y., Wu, W., Wei, F., & Li, S. (2023). PoSE: Efficient Context Window Extension of LLMs via Positional Skip-wise Training. arXiv. doi:10.48550/arxiv.2309.10400 Free full text
- Brixi, G., Durrant, M., Ku, J., Naghipourfar, M., Poli, M., Sun, G., Brockman, G., Chang, D., Fanton, A., Gonzalez, G., King, S., Li, D., Merchant, A., Nguyen, E., Ricci-Tam, C., Romero, D., Schmok, J., Taghibakhshi, A., Vorontsov, A., & ... Hie, B. (2026). Genome modelling and design across all domains of life with Evo 2. Nature. doi:10.1038/s41586-026-10176-5
- Ram, O., Levine, Y., Dalmedigos, I., Muhlgay, D., Shashua, A., Leyton-Brown, K., & Shoham, Y. (2023). In-Context Retrieval-Augmented Language Models. Transactions of the Association for Computational Linguistics, 11, 1316-1331. doi:10.1162/tacl_a_00605
- Xu, P., Ping, W., Wu, X., McAfee, L., Zhu, C., Liu, Z., Sandeep, S., Bakhturina, E., Shoeybi, M., & Catanzaro, B. (2023). Retrieval meets Long Context Large Language Models. arXiv. doi:10.48550/arxiv.2310.03025 Free full text
- Tan, Y., Xu, A., & Akkiraju, R. (2024). In Defense of RAG in the Era of Long-Context Language Models. arXiv. doi:10.48550/arxiv.2409.01666 Free full text
- Ye, X., Yin, F., Yinghui, H., Joie, Z., Howard, Y., Gao, T., Durrett, G., & Chen, D. (2025). LongProc: Benchmarking Long-Context Language Models on Long Procedural Generation. arXiv. doi:10.48550/arxiv.2501.05414 Free full text
- Lu, Y., Wanxu, Z., Xin, Z., An, C., Wang, C., Li, S., Yang, Y., Zhao, J. C., Ji, T., Gui, T., Zhang, Q., & Huang, X. (2025). Effective Length Extrapolation via Dimension-Wise Positional Embeddings Manipulation. arXiv. doi:10.48550/arxiv.2504.18857 Free full text
- Tamanampudi, V. M. (2024). CoWPE: Adaptive Context Window Adjustment in LLMs for Complex Input Queries. Journal of Artificial Intelligence General science (JAIGS) ISSN:3006-4023, 5(1), 438-450. doi:10.60087/jaigs.v5i1.221
- Han, W., Zhou, P., Poria, S., & Yan, S. (2026). Stacked from One: Multi-Scale Self-Injection for Context Window Extension. arXiv. doi:10.48550/arxiv.2603.04759 Free full text
- Dakir, A., El Hajji, M., Ait Baha, T., & Es-Saady, Y. (2026). A Survey on Context Injection Strategies for Long-Context Language Models: Three Perspectives. EPJ Web of Conferences, 381, 00014. doi:10.1051/epjconf/202638100014
Cite this page: Atlas Nova editors. (2026). Context window. Atlas Nova. https://velocer.io/atlas/context-window/