Technology · Language models
Long-context language models
Language model type
A long-context language model is a language model built to make its context window, the stretch of text, measured in tokens, that it can take in and attend to at once, very large, so that a single prompt can carry a whole novel, an entire code repository, or a bacterial genome rather than a paragraph or two.
That visible span is the context window: the stretch of text, measured in tokens (the word fragments or characters the model reads as units), that the model can take in and attend to at once.
Overview
Long-context language models
The difference is one of scale and kind. A model with a short window must be fed a document in pieces, and each piece is interpreted with little or no memory of the others; a model with a long window can be handed the document whole, so that a fact stated in the first chapter is still present when the last is read. The appeal is easy to see. A reader asking whether a contract contradicts itself, a programmer asking why a function fails when called from another file, or a biologist asking what a stretch of DNA encodes all pose questions whose answer depends on material spread across far more text than a short window holds. Long windows promise to let one model answer such questions directly, without first deciding which fragments to show it.

The promise is real but conditional, and the condition is the central theme of this chapter. Being able to accept a long input is not the same as using it well. The clearest demonstration comes from a study of two tasks that require finding relevant information in a long input: multi-document question answering and key-value retrieval. Performance was often highest when the relevant passage sat at the beginning or the end of the context and dropped significantly when it sat in the middle, even for models explicitly built for long context.[4] The model had the information in front of it and still failed to weigh it properly, a pattern that became known as the "lost in the middle" effect.
Retrieval of a single fact is also a weak test of understanding. A benchmark called RULER extended the familiar needle-in-a-haystack test, in which one sentence must be found among many irrelevant ones, to include several needles of different kinds and tasks that require tracing and aggregating information rather than merely locating it. Across 17 long-context models and 13 tasks, almost all showed large drops in performance as the input grew, and although all the models claimed context sizes of 32K tokens or greater, only half kept satisfactory performance at the length of 32K.[5] A model can therefore advertise a large window and still handle only a fraction of it dependably.
A long context window is a capacity, not a guarantee: what matters is whether the model actually finds and uses what the window contains.
This distinction between nominal capacity and effective use runs through everything that follows. The sections ahead trace how windows grew from the short spans of earlier models, explain the machinery that lets a model hold a long input and why that machinery is expensive, survey what long inputs are used for in medicine, law-like document work, code and genomics, and set out the evidence on where long context succeeds and where it quietly fails. They also take up the costs and risks that come with feeding a model more text, and the open question of whether very long windows will replace the external search systems that currently supply models with relevant passages. The thread connecting these topics is the one established here: a bigger window changes what a model can be shown, and the work of the field is to make what it is shown actually count.
History
From short snippets to hundred-thousand-token windows
Before a model can be given a long input, it has to be built in a way that lets it hold one. A comparison of count-based models with feedforward, recurrent and long short-term memory variants on two large speech-recognition tasks found that the neural networks modelled context dependencies differently and often over spans longer than count-based approaches considered.[6]

Convolutional language models took the bounded approach deliberately. Instead of carrying state, they stacked layers of convolutions, each of which combines a small window of neighbouring tokens, so that stacking layers widens the effective span. A gated convolutional model of this kind reached state-of-the-art results on the WikiText-103 benchmark, a corpus that features long-term dependencies, and cut the latency of scoring a sentence by an order of magnitude compared with a recurrent baseline.[7] The trade was explicit: a finite, computable context in exchange for speed and parallelism.
That is the machinery covered later; what matters here is that it made context length a dial that could be turned up. Turning it up, however, is not free, and the history of long-context models is largely a history of finding ways to pay for it.
Stretching the window
The most direct route is continual pretraining: take a model trained on short sequences and keep training it on longer ones. A series of models built this way from Llama 2 supported effective windows of up to 32,768 tokens, and the 70-billion-parameter variant could already surpass gpt-3.5-turbo-16k's overall performance on a suite of long-context tasks after a cost-effective instruction-tuning step that needed no human-annotated long instruction data. The same work's ablations suggested that having abundant long texts in the pretraining data was not the key to strong performance, and that continual pretraining on long sequences was more efficient and similarly effective compared with training from scratch on them.[8] What the model needed was practice at the longer length, not necessarily more long documents.
Continual pretraining at scale is expensive, so a second line of work made the fine-tuning cheaper. LongLoRA extended the context of pretrained models by fine-tuning with sparse local attention rather than dense global attention, on the reasoning that dense attention is needed at inference but not necessarily during training. It extended Llama2 7B from a 4k context to 100k, and Llama2 70B to 32k, on a single 8x A100 machine, while keeping the original architecture. The saving is easy to see in the arithmetic: training at a context length of 8,192 costs sixteen times as much in the self-attention layers as training at 2,048.[9]
A third route avoids training altogether. Dual Chunk Attention decomposes the attention computation for long sequences into chunks, capturing the relative positions of tokens within a chunk and across chunks, and so lets Llama2 70B handle windows of more than 100,000 tokens without continual training. On practical long-context tasks it performed comparably to or better than fine-tuned models, and the training-free 70B model attained 94% of the performance of gpt-3.5-16k.[10]
The same move in genomics
The shift happened in biology along a parallel track, because a genome is a sequence in much the same sense that a paragraph is. megaDNA, a multiscale transformer pretrained on unannotated bacteriophage genomes with byte-level tokenization, reads DNA at the single-nucleotide level and generates sequences up to 96,000 base pairs, finding functional promoters and ribosome binding sites in the regions it produces.[11] A larger model, Evo, was scaled to 7 billion parameters with a context length of 131 kilobases at single-nucleotide resolution and trained on whole prokaryotic genomes; it predicts gene essentiality at nucleotide resolution and generates coding-rich sequences up to 650 kilobases long.[12]
What the three text routes share is a shift in what counts as a unit of input. A recurrent or convolutional model was given a sentence or a few; a long-context transformer can be given a book, a repository, or a genome, and the engineering question becomes how to afford the span rather than how to work around its absence. Whether the model then uses that span well is a separate matter, and the evidence on that is taken up later.
How it works
How a model holds a long input
Everything a language model does begins with tokens. A token is the unit the model actually reads: not a word, not a letter, but a fragment, so that "unbelievable" might arrive as three or four pieces and a punctuation mark as one. Text is chopped into tokens before the model sees it, and every later count of length is a count of these pieces. The context window is the number of tokens the model can hold in view at once while producing its next token. It is a hard ceiling, set by how the model was built and trained, and anything beyond it simply is not there.
Holding a long input is not a matter of storage but of attention. Inside a transformer, each token is compared with every other token in the window, and the comparisons decide how much each one contributes to the representation of the others. This is what lets a pronoun be tied to a name several paragraphs back, or a variable to its definition in another file. The mechanism is powerful precisely because it is unrestricted: nothing in it says that a token two steps away matters more than one two thousand steps away. The cost of that freedom is the subject of the rest of this section.
The cost is quadratic. If the window holds n tokens, each of the n tokens must be compared with each of the others, so the work grows with n multiplied by n. Doubling the window roughly quadruples the computation in the attention layers, and the memory needed to store the comparisons grows the same way. This is why context length is expensive in a way that model size is not: a longer window taxes every layer at every step. The arithmetic shows up plainly in training. Training at a context length of 8,192 costs sixteen times as much in the self-attention layers as training at 2,048.[9] A window four times wider costs sixteen times more, and the curve steepens from there.
Paying less for the same span
The workarounds all attack the same term. One family accepts the full comparison at inference but avoids it during training, on the reasoning that a model needs dense attention when it is answering but not necessarily while it is being adapted. LongLoRA fine-tunes with sparse local attention, in which each token attends only to a nearby stretch rather than to the whole window, and extends a 7-billion-parameter model from a 4,000-token context to 100,000 on a single machine of eight A100 GPUs, keeping the original architecture.[9] The model still attends globally when it runs; only the expensive adaptation step is made cheaper.
A second family restructures attention itself. Dual Chunk Attention splits a long sequence into chunks and computes attention within each chunk and across chunks separately, so that the relative positions of tokens are captured without comparing every token with every other one directly. This lets a 70-billion-parameter model handle windows beyond 100,000 tokens with no additional training, and on practical long-context tasks it performed comparably to or better than models that had been fine-tuned for the length.[10] The saving comes from never forming the full grid of comparisons at once.
A third family changes the arithmetic outright. Linear-time attention replaces the exact comparison of every pair with an approximation whose cost grows in proportion to n rather than n squared. The Performer architecture does this with a mechanism it calls Fast Attention Via Orthogonal Random features, which scales linearly in the number of tokens, uses sub-quadratic memory, and comes with theoretical guarantees that the approximation is unbiased.[13] The trade is exactness for scale: the model no longer weighs every pair precisely, but it can be handed sequences that would otherwise be impossible.
A fourth family decides that not every token deserves equal attention in the first place. Core Context Aware attention groups input tokens and compresses each group into a single representative token chosen for its significance, while a second module keeps neighbouring tokens in view so that local detail is not lost. The compressed core carries the gist of a long passage at a fraction of the cost, and the module can replace ordinary attention in an existing model with little fine-tuning.[14] A related design pairs chunked local attention with a gated memory that stores representations of past tokens and updates them as new ones arrive, so that information from far back persists without every token having to look at it directly.[15] Both rest on the same judgement: much of a long context is redundant, and the model's job is to keep what matters and let the rest go.
Attention cost grows with the square of the window, so every practical long-context method is a way of not paying that bill in full.
These approaches are not exclusive, and a deployed model may combine several. What they share is a bargain: exact, full attention over a short span, or approximate, partial attention over a long one. The approximations are good enough that a model can accept a hundred thousand tokens, but each one gives up something, whether precision in the comparisons, the ability to revise an early decision, or the guarantee that a detail in the middle of the window will be weighed as heavily as one at the edge. Whether the resulting span is used well is a question about behaviour rather than architecture, and the evidence on that is taken up later.
Uses
What long inputs are used for
A long window is worth building only if something is worth putting in it. The applications that drove the work share a shape: the answer depends on material spread across far more text than a short window holds, and no small set of fragments can be chosen in advance without already knowing the answer. What follows surveys the areas where long inputs have been put to use, from medical evidence to genomes, and notes in each case what the long window was asked to do.

Medicine: summarizing evidence and supporting decisions
Medical evidence summarization means extracting and synthesizing the key findings from a body of research studies and clinical trials into a concise summary. It is a natural fit for a long window, because a single review can run to many pages and the relevant conclusions are scattered through it. A systematic evaluation put GPT-3.5 and ChatGPT to this task across six clinical domains, using Cochrane Reviews as the source material, and compared ChatGPT summaries generated from a review's entire abstract with those generated from its main-result section.[16] The comparison is instructive: the longer input did not help. Summaries conditioned on the entire abstract were less comprehensive, more likely to contain factual inconsistency, and less preferred by human evaluators, which the authors read as a sign that the model was distracted by material irrelevant to the question.[16] The finding belongs to the later discussion of failure modes, but it sets the tone for the applications that follow: a long window admits the whole document, and the whole document includes much that does not help.
Clinical decision support asks something harder. Here the model is not summarizing a fixed text but gathering information, weighing it against guidelines, and proposing a diagnosis or a treatment. A curated dataset of 2,400 real patient cases spanning four common abdominal pathologies, drawn from a critical-care database, was used to simulate a realistic clinical workflow, and current leading models did not reach the diagnostic accuracy of physicians across all the pathologies, did not follow diagnostic or treatment guidelines, and could not reliably classify a laboratory result as normal or abnormal even when given its reference range. The same evaluation found the models sensitive to the order in which information arrived and prone to diagnosing before the case was fully understood.[17] Strong performance on examination-style questions and readiness for a real consultation are evidently different things.
Question answering over retrieved and whole documents
Retrieval-augmented generation, or RAG, is the older answer to the same problem: rather than widen the window, fetch the few passages most likely to be relevant and place them in a short one. Long windows raise an obvious question about whether the fetching is still needed. Retrieval and a long window, on this evidence, are not rivals so much as two levers that can be pulled together.
The arrangement of retrieved material inside the window matters as much as its quantity. An order-preserving retrieval scheme, which keeps retrieved chunks in their original sequence and adds them one at a time, produced an inverted U-shaped curve: answer quality rose as more chunks were retrieved and then fell, so that a sweet point existed where quality was higher than feeding the model the entire context, at far fewer tokens.[18] The picture is of a capability that is real, uneven across task types, and sensitive to how the input is assembled.
Code, long documents and genomes
Software is a domain where the relevant material is spread across files by construction. Even when given the oracle context, the best of seven evaluated models reached only 69.1% Pass@1 on output prediction, and on call-chain prediction the models showed high precision but low recall, suggesting limited understanding of multi-hop dependencies.[2] Code makes the gap between nominal and effective context unusually visible, because a missed dependency produces a wrong answer rather than a slightly worse summary.
Long-form writing offers a quieter case. Automated essay scoring, the machine grading of student essays, has conventionally truncated long responses to fit a fixed input limit. Here the long window is not a convenience but a condition for measuring the thing at all.
Genomics is the domain where the unit of interest is longest. A genome is a sequence in much the same sense a paragraph is, and the functional elements that matter, genes, promoters, binding sites, are separated by stretches whose relevance is not known in advance. In both cases the window is wide enough to hold a whole functional unit, which is what makes the task possible at all.
Across these areas the pattern repeats. The long window is what lets a single model be handed a review, a patient record, a repository, an essay or a genome rather than a fragment of one. Whether it then uses that material well is a separate question, and the evidence on that is taken up next.
Research
Evidence on whether long context actually works
A model's context window is a claim about capacity, and capacity is easy to advertise. The harder question is whether a model given a long input actually finds what matters inside it, weighs it correctly, and produces an answer that depends on the whole rather than on a convenient fragment. Answering that question requires tests, and the history of long-context evaluation is largely a history of tests turning out to be too easy.

The simplest test is the needle in a haystack: place one sentence, the needle, somewhere in a long stretch of irrelevant text, the haystack, and ask the model to retrieve it. A model that scores near perfectly looks capable. The trouble is that retrieval of a single verbatim sentence exercises only a superficial form of long-context understanding, and a benchmark called RULER was built to go further by varying the type and number of needles and adding tasks that require tracing a chain of references or aggregating many pieces of information rather than locating one. Across 17 long-context models and 13 tasks, almost all showed large performance 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 pass the easy test and still handle only a fraction of its advertised window dependably.
Where in the window the answer sits
Position turns out to matter as much as length. In the multi-document question answering and key-value retrieval tasks described earlier, accuracy was often 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 explicitly for long context.[4] The model had the passage in front of it and still failed to give it proper weight. This is not a failure of storage but of use: the information was present in the window and did not influence the answer as it should.
The effect has a mirror image. If material at the edges is favoured, material early in a long input may be underweighted relative to material that arrives late, a pattern that shows up as recency bias. One line of work found that relevant information located earlier in the context is attended to less on average, a tendency the authors attribute to attention patterns likely learned during pretraining. What makes the finding useful is a second observation: even when a model fails to use a relevant document in its answer, it still pays more attention to that document than to an irrelevant one at the same position. That gap allows a repair. Attention sorting runs one step of decoding, ranks the documents by the attention they received, moves the highest-attention documents to the end of the context, and repeats before generating the answer, and this improved the performance of long-context models.[19] The model's attention is a better guide to relevance than its final answer, and the method exploits the difference.
When the labels themselves are the haystack
Retrieval tasks ask a model to find a passage. A harder demand is in-context learning, in which the prompt supplies a set of examples and the model must infer the pattern and apply it to a new case. Stretch the example set to thousands of tokens and the task becomes a test of whether the model can hold a large label space in view. A benchmark built for this, LongICLBench, used six datasets with between 28 and 174 classes and inputs from 2,000 to 50,000 tokens, and evaluated 15 long-context models. The models did well on the easier classifications, with small label spaces and short demonstrations, but struggled on the harder ones, including a task with 174 labels. Analysis of the errors revealed a bias toward labels presented later in the sequence, along with a need for better reasoning over multiple pieces of information at once.[20] The failure is not that the model cannot see the examples; it is that the examples do not all count equally, and the ones near the end count most.
Generation and the long output
Most benchmarks ask for a short answer drawn from a long input. A different demand is a long output that must stay coherent with dispersed material, and here the evidence is starker. A benchmark called LongProc set six procedural generation tasks, such as extracting structured information from web pages into a table format or executing a search procedure to build a travel plan, requiring models to follow detailed instructions, synthesize information scattered across the input, and produce structured output of up to 8,000 tokens. Of 23 models evaluated, all claiming windows above 32,000 tokens, open-weight models typically faltered on the 2,000-token tasks, and a closed model such as GPT-4o degraded significantly on the 8,000-token tasks; further analysis found that models struggle to maintain long-range coherence as the output grows.[21] Holding a long input and sustaining a long output turn out to be separate skills, and the second is the weaker.
Code shows the same pattern with less room for a plausible-sounding wrong answer. A benchmark organized long-code understanding into four aspects and eight tasks and evaluated nine models, six general and three built for code. Performance dropped sharply once the code exceeded 32,000 tokens, far below the 128,000-to-million-token windows the models claimed, and of the four aspects the hardest was understanding relations between separate code units.[22] A missed dependency in code yields a program that does not run, which makes the shortfall harder to overlook than a summary that reads well.
The metric that hides the problem
If a model's answers degrade with length, one would expect a standard measure of language-model quality to register the decline. Perplexity, the conventional measure, is the model's average surprise at each token it predicts: lower is better, and it is computed by averaging over all the tokens in a text. That averaging is the flaw. A long document contains many predictable tokens, function words and stock phrases, and these dominate the average, so a model that misses the few tokens carrying the meaning can still post a good perplexity score. A metric built to correct this, LongPPL, identifies the key tokens by contrasting a model's behaviour under long and short context and scores the model on those alone; it correlated strongly with performance on long-context benchmarks, with a Pearson correlation of −0.96, where conventional perplexity did not.[1] A number that averages over everything can conceal a failure concentrated in the few places that matter.
The test that is not a test
The most direct evidence that a long window can hurt comes from a task where the longer input was expected to help. In the medical evidence summarization study described earlier, summaries generated from a review's full abstract were compared with summaries generated from a shorter main-result section. The longer input produced less comprehensive summaries, more factual inconsistency, and summaries less preferred by human evaluators, which the authors read as the model being distracted by material irrelevant to the question.[16] The input was longer and the answer was worse.
A benchmark called HELMET, spanning seven application-centred categories with lengths up to 128,000 tokens, drew the threads together across 59 long-context models. Synthetic tasks such as needle-in-a-haystack did not reliably predict downstream performance; the categories showed distinct trends and low correlations with one another; and while most models achieved perfect needle-in-a-haystack scores, open-source models lagged significantly behind closed ones once a task required reasoning over the full context or following complex instructions, with the gap widening as length increased.[23] A single easy test, in other words, tells little about how a model will behave on the work one actually has in mind.
A model can hold a hundred thousand tokens and still answer from the wrong part of them; the tests that reveal this are the ones that ask for reasoning over the whole input, not retrieval of one sentence.
What these results share is a distinction between the window a model has and the window it uses. The failures cluster where a task requires weighing material across the whole input, keeping many items in play at once, or producing a long answer that stays faithful to distant parts of the source. They are less severe where a task requires finding one passage, which is why the easy tests looked reassuring for so long. The costs and risks that accompany these failures, and the question of whether external retrieval remains necessary, are taken up in the sections that follow.
Risks and limits
Risks, costs and failure modes
Every gain in context length is paid for twice: once in computation and memory, and once in the model's ability to keep its footing as the input grows. The first cost is arithmetic and can be estimated before a model is run. The second is behavioural, shows up only under test, and is the more dangerous of the two because a model that has lost track of a long input still produces fluent, confident text.

The bill for a wide window
For masked diffusion models, which apply full bidirectional attention at every denoising step, cost grows linearly with the number of denoising steps and with the square of the sequence length.[24] The arithmetic is stark in training: fine-tuning at a context length of 8,192 costs sixteen times as much in the self-attention layers as fine-tuning at 2,048.[9] The pressure is sharpest for architectures that attend over the whole sequence at every step. For an 8-billion-parameter masked diffusion model at a length of 8,192 over 128 steps, the key-value cache alone exceeds 40 gigabytes, which rules out long document generation on a single GPU. A window that fits on paper may not fit in memory.[24]
Distraction by what does not matter
A long window admits the whole document, and the whole document includes much that does not help. The tendency of a model to be pulled off course by irrelevant context, material present in the input that has no bearing on the task, has been measured directly. A benchmark called GSM-IC took arithmetic word problems and added information irrelevant to the solution, and found that the performance of cutting-edge prompting techniques dropped dramatically once that material was included; telling the model in the prompt to ignore the irrelevant information, or decoding with self-consistency, recovered some of the loss.[25]
The same failure appears where the stakes are higher. In the clinical decision-making evaluation described earlier, models given all relevant diagnostic information diagnosed worse than models given a single diagnostic exam, an inability to extract the most important signal from the evidence.[17] A long window, on this evidence, is not a neutral container: filling it changes what the model attends to, and not always for the better.
Saying the wrong thing fluently
Summarization turns the problem from missing information into misstated information. A summary can be fluent, well organized, and wrong in ways a reader has no easy way to check. The medical evidence summarization study sorted these errors into types.
Misinterpretation errors draw a conclusion that contradicts the source, or convey a different degree of certainty than the source supports, a subtype the authors call certainty illusion, in which a summary sounds more or less confident than the evidence warrants. Fabricated errors state something the source neither supports nor refutes, and attribute errors get a non-key element of the review question wrong, adding, omitting or distorting a detail such as the population studied or the number of trials included. LLMs generally generated summaries with few fabricated errors, but displayed a noticeable occurrence of attribute errors and misinterpretation errors, with ChatGPT-Abstract and GPT3.5-MainResult showing a higher incidence of the latter, and the authors note that drawing inaccurate conclusions or conveying incorrect certainty could lead to medical harm.[16] A wrong number in a summary is easy to miss and hard to trace, which is precisely what makes it dangerous.
Safety that does not carry over from short inputs
A model that behaves safely on a short prompt may not behave safely on a long one. A benchmark called LongSafety, covering seven categories of safety issue across six user-oriented long-context tasks, assembled 1,543 test cases averaging 5,424 words per context and evaluated 16 representative models. Most achieved safety rates below 55 percent, and strong safety performance in short-context settings did not necessarily carry over to long-context tasks; relevant context and extended input sequences could themselves exacerbate the risks.[3] The finding matters because it undercuts a natural assumption: that a model vetted on short inputs is vetted. The long window is a new surface, and the safety work done on the short one does not automatically cover it.
The gap between claimed and effective length
The failures above compound into a single practical problem: the length a model advertises and the length at which it works are different numbers. The RULER benchmark made the gap explicit. A separate study of retrieval-augmented generation across 20 open and commercial models, varying the total context from 2,000 to 128,000 tokens and beyond on three domain-specific datasets, found that retrieving more documents could improve performance, but only a handful of the most recent models maintained consistent accuracy above 64,000 tokens, and distinct failure modes appeared at long lengths.[26] The advertised window is a ceiling on what can be passed in, not a promise about what will be used.
A model can accept a hundred thousand tokens and still work reliably on a fraction of them; the number on the specification sheet is a capacity, not a guarantee.
These costs and failure modes are not separate problems so much as one problem seen from different angles. The computation that makes a wide window possible is the same computation that makes it expensive; the breadth that lets a model see everything is the breadth that lets irrelevant material compete for its attention; and the fluency that makes its output readable is what makes a wrong summary hard to catch. The question of whether external retrieval can substitute for some of this, and how the field is trying to close the gap between nominal and effective context, is taken up in the next section.
Later developments
Open problems and current direction
Retrieval and long context as two levers

The question that framed much of the earlier work was whether a wide window makes retrieval obsolete. The evidence points the other way. In a comparison of a model with a 4,000-token window using simple retrieval against a fine-tuned model with a 16,000-token window, the two performed comparably on long-context tasks, with the retrieval approach taking much less computation; adding retrieval to a model with an extended window improved it further, and the best configuration, a 70-billion-parameter model with a 32,000-token window plus retrieval, outperformed both gpt-3.5-turbo-16k and Davinci003 on an average over nine long-context tasks.[27] Retrieval, on this showing, is not a stopgap to be discarded once windows grow. It is a second lever that keeps working after the window has been widened.
The arrangement of what is retrieved matters as much as the retrieving. An order-preserving scheme, which keeps retrieved chunks in their original sequence, produced an inverted U-shaped curve: answer quality rose as more chunks were retrieved and then fell, so that a sweet point existed where quality was higher than feeding the model the entire context, at far fewer tokens.[18] That curve is the practical form of the nominal-versus-effective distinction. If a model uses only part of what it is given, then handing it everything is not the safe choice; it is a choice that spends tokens and dilutes attention. The open problem is not whether to retrieve but how much to retrieve and in what order, and the answer depends on the model and the task rather than on the size of the window alone.
Injection strategy as the real design question
Once windows are large, the constraint shifts from whether the material fits to whether the right material arrives in the right form. A survey of the field argues exactly this: that context injection strategy, meaning the decisions about what information reaches a model at inference time and how, is the defining research challenge for deploying long-context models, rather than context capacity itself. The survey sorts the literature into five families, direct injection, compression-based injection, retrieval-based injection, memory-based injection, and hybrid or agentic injection, and analyses them along three axes: selection, what information is chosen; representation, how it is encoded; and scheduling, when it is delivered during inference. Its assessment is that current systems overwhelmingly optimise selection while representation and scheduling remain largely unexplored.[28]
That imbalance is worth pausing on, because it reframes several failures described earlier. The survey identifies six structural open challenges that it judges unlikely to be resolved within any single paradigm, along with evaluation gaps that current benchmarks do not address, and concludes that progress on representation and scheduling is a more promising direction than further scaling of windows for closing the gap between nominal and effective capacity.[28] Whether that judgement holds is itself unsettled, but it names the place where the next round of work is likely to concentrate.
The data behind a long window
A model learns to use a long input from the data it is trained and tested on, and that side of the problem has received less attention than architecture. A survey of the data foundations of long-context models maps current data strategies against the capabilities they are meant to build, examines how targeted training data drives the interlocking skills of retrieval, reasoning and aggregation, and analyses how the choice of benchmark shapes what a model's limits look like. Its recommendations include quantifying data quality, establishing scaling laws for how length is distributed in training data, and building evaluation frameworks that change over time rather than fixing a single test set.[29] The point connects back to the earlier finding that abundant long documents in pretraining were not the key to strong long-context performance, and that long-context continual pretraining was found more efficient and similarly effective compared to pretraining from scratch with long sequences.[8]
Can a window replace a search engine?
The largest version of the question is whether a model that can ingest an entire corpus still needs the tools built to search one. A benchmark of real-world tasks requiring contexts up to millions of tokens, covering in-context retrieval and reasoning, found long-context models surprisingly able to rival state-of-the-art retrieval and RAG systems despite never having been trained for those tasks, while still struggling with the compositional reasoning that SQL-like tasks demand, and it found that prompting strategy significantly influenced performance.[30] The result is genuinely two-sided. It suggests that for some work the external machinery can be folded into the window, and it shows that the folding does not extend to tasks requiring structured operations over the material.
The open question is not whether long windows replace retrieval, but which parts of the work each is better suited to, and that division is still being drawn.
What remains unresolved, then, is a set of connected questions rather than a single one. How much of a corpus a model can use dependably, how retrieved and directly supplied material should be arranged, how training data should be composed to build the skill of using a long input, and where external tools remain necessary are all under active investigation, and the answers interact. A finding about arrangement changes what counts as an adequate training set; a finding about training changes what a benchmark is measuring. The one stable conclusion is the one the chapter opened with: a wide window changes what a model can be shown, and the work that remains is making what it is shown count.
Key studies
| Year | Study | Sample | Design | Finding |
|---|---|---|---|---|
| 2023 | Xu et al.[27] | a 43B GPT model and Llama2-70B | comparison of retrieval augmentation and long context | A 4K-window model with retrieval matched a fine-tuned 16K model while using much less computation. |
| 2023 | Shi et al.[25] | large language models on an arithmetic dataset | benchmark with irrelevant context added | Performance dropped dramatically when irrelevant information was included, and instructions to ignore it helped. |
| 2023 | Tang et al.[16] | GPT-3.5 and ChatGPT on Cochrane Review abstracts | zero-shot medical evidence summarization | Models were more error-prone when summarizing over longer textual contexts. |
| 2024 | Liu et al.[4] | language models including GPT-3.5 Turbo and GPT-3.5 Turbo (16K) | controlled evaluation with varied document positions | Accuracy dropped by more than 20% in the worst case, falling below the 56.1% closed-book score. |
| 2024 | Hsieh et al.[5] | 17 long-context language models | benchmark with 13 tasks | Only half of the models kept satisfactory performance at 32K tokens despite claiming windows of 32K or more. |
| 2024 | Howard et al.[23] | 59 long-context language models | benchmark with seven application categories up to 128K tokens | Most models scored perfectly on the needle test, but open-source models lagged on full-context reasoning, and the gap widened with length. |
| 2024 | Leng et al.[26] | 20 open-source and commercial models | RAG workflows at lengths from 2,000 to 128,000 tokens | Only a handful of recent models kept consistent accuracy above 64k tokens. |
| 2024 | Li et al.[20] | 15 long-context models | classification benchmark with 28 to 174 classes | Models struggled most with the 174-label task and showed a bias toward labels presented later. |
| 2024 | Hager et al.[17] | 2,400 real patient cases | simulated clinical decision-making | Models performed significantly worse than physicians and were sensitive to the quantity and order of information. |
| 2024 | Nguyen et al.[12] | Evo, a 7-billion-parameter genomic model | genome-scale sequence modeling | Evo was scaled to 7 billion parameters with a context length of 131 kilobases, and it generated coding-rich sequences up to 650 kb in length. |
| 2025 | Lu et al.[3] | 16 representative language models | safety benchmark with 1,543 test cases | Most models achieved safety rates below 55% on long-context tasks averaging 5,424 words per context. |
| 2025 | Ye et al.[21] | 23 long-context 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. |
See also
References
- 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
- 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
- Lu, Y., Cheng, J., Zhang, Z., Cui, S., Wang, C., Gu, X., Dong, Y., Jie, T., Wang, H., & Huang, M. (2025). LongSafety: Evaluating Long-Context Safety of Large Language Models. arXiv. doi:10.48550/arxiv.2502.16971 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
- Sundermeyer, M., Ney, H., & Schluter, R. (2015). From Feedforward to Recurrent LSTM Neural Networks for Language Modeling. IEEE/ACM Transactions on Audio, Speech, and Language Processing, 23(3), 517-529. doi:10.1109/taslp.2015.2400218
- Dauphin, Y., Fan, A., Auli, M., & Grangier, D. (2016). Language Modeling with Gated Convolutional Networks. arXiv. doi:10.48550/arxiv.1612.08083 Free full text
- Xiong, W., Liu, J., Molybog, I., Zhang, H., Bhargava, P., Hou, R. L., Louis, M., Rungta, R., Sankararaman, K. A., Oğuz, B., Khabsa, M., Han, F., Mehdad, Y., Narang, S., Malik, K., Fan, A., Bhosale, S., Edunov, S., Lewis, M., & ... Ma, H. (2023). Effective Long-Context Scaling of Foundation Models. arXiv. doi:10.48550/arxiv.2309.16039 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
- An, C., Huang, F., Zhang, J., Gong, S., Qiu, X., Zhou, C., & Kong, L. (2024). Training-Free Long-Context Scaling of Large Language Models. arXiv. doi:10.48550/arxiv.2402.17463 Free full text
- Shao, B., & Yan, J. (2024). A long-context language model for deciphering and generating bacteriophage genomes. Nature Communications, 15(1). doi:10.1038/s41467-024-53759-4
- Nguyen, E., Poli, M., Durrant, M. G., Kang, B., Katrekar, D., Li, D. B., Bartie, L. J., Thomas, A. W., King, S. H., Brixi, G., Sullivan, J., Ng, M. Y., Lewis, A., Lou, A., Ermon, S., Baccus, S. A., Hernandez-Boussard, T., Ré, C., Hsu, P. D., & Hie, B. L. (2024). Sequence modeling and design from molecular to genome scale with Evo. Science, 386(6723). doi:10.1126/science.ado9336
- Choromański, K., Likhosherstov, V., Dohan, D., Song, X., Andreea, G., Sarlós, T., Peter, H., Davis, J. Q., Belanger, D., Colwell, L. J., & Weller, A. (2020). Masked Language Modeling for Proteins via Linearly Scalable Long-Context Transformers. arXiv. doi:10.48550/arxiv.2006.03555 Free full text
- Chen, Y., You, Z., Zhang, S., Haokun, L., Yirui, L., Wang, Y., & Tan, M. (2024). Core Context Aware Transformers for Long Context Language Modeling. arXiv. doi:10.48550/arxiv.2412.12465 Free full text
- Ankit, K. (2025). Recurrent Memory-Augmented Transformers with Chunked Attention for Long-Context Language Modeling. arXiv. doi:10.48550/arxiv.2507.00453 Free full text
- Tang, L., Sun, Z., Idnay, B., Nestor, J. G., Soroush, A., Elias, P. A., Xu, Z., Ding, Y., Durrett, G., Rousseau, J. F., Weng, C., & Peng, Y. (2023). Evaluating large language models on medical evidence summarization. npj Digital Medicine, 6(1). doi:10.1038/s41746-023-00896-7
- Hager, P., Jungmann, F., Holland, R., Bhagat, K., Hubrecht, I., Knauer, M., Vielhauer, J., Makowski, M., Braren, R., Kaissis, G., & Rueckert, D. (2024). Evaluation and mitigation of the limitations of large language models in clinical decision-making. Nature Medicine, 30(9), 2613-2622. doi:10.1038/s41591-024-03097-1
- 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
- Peysakhovich, A., & Lerer, A. K. (2023). Attention Sorting Combats Recency Bias In Long Context Language Models. arXiv. doi:10.48550/arxiv.2310.01427 Free full text
- Li, T., Zhang, G., Do, Q. D., Yue, X., & Chen, W. (2024). Long-context LLMs Struggle with Long In-context Learning. arXiv. doi:10.48550/arxiv.2404.02060 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
- Li, J., Xuyuan, G., Li, L., Zhang, K., Li, G., Li, J., Tao, Z., Liu, F., Tao, C., Zhu, Y. S., & Jin, Z. G. (2025). LONGCODEU: Benchmarking Long-Context Language Models on Long Code Understanding. arXiv. doi:10.48550/arxiv.2503.04359 Free full text
- Howard, Y., Gao, T., Minmin, H., Ke, D., Fleischer, D., Izsak, P., Wasserblat, M., & Chen, D. (2024). HELMET: How to Evaluate Long-Context Language Models Effectively and Thoroughly. arXiv. doi:10.48550/arxiv.2410.02694 Free full text
- Teng, D., Rhee, M., Qin, Y., Zi, B., & Liu, W. (2026). SW-SpeedDLM: Sliding Window Speculative Decoding for Diffusion Language Models Under Long Context Constraints. Mathematics, 14(12), 2137. doi:10.3390/math14122137
- Shi, F., Chen, X., Misra, K., Nathan, S., David, D., H., E., A, N. S., & Zhou, D. (2023). Large Language Models Can Be Easily Distracted by Irrelevant Context. arXiv. doi:10.48550/arxiv.2302.00093 Free full text
- Leng, Q., Portes, J., Havens, S., Zaharia, M., & Carbin, M. (2024). Long Context RAG Performance of Large Language Models. arXiv. doi:10.48550/arxiv.2411.03538 Free full text
- 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
- 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
- Sun, Z., Sun, Y., Su, Z., Tang, Z., Li, J., Zhou, A., Chen, W., & Zhang, M. (2026). Data Foundations of Long-Context Language Models: A Survey. Transactions of the Association for Computational Linguistics, 14, 1803-1825. doi:10.1162/tacl.a.775
- Lee, J., Chen, A., Dai, Z., Dua, D., Sachan, D. S., Boratko, M., Luan, Y., Arnold, S. M. R., Perot, V., Dalmia, S., Hu, H., Lin, X., Pasupat, P., Amini, A., Cole, J. R., Riedel, S., Naim, I., Ming-Wei, C., & Guu, K. (2024). Can Long-Context Language Models Subsume Retrieval, RAG, SQL, and More? arXiv. doi:10.48550/arxiv.2406.13121 Free full text
Cite this page: Atlas Nova editors. (2026). Long-context language models. Atlas Nova. https://velocer.io/atlas/long-context-models/