AI in Production
A Million Tokens of Context, and It Missed the Clause in the Middle
· 8 min read · Anton Babayan, Founder
Context windows went from a couple of thousand tokens to a million in about four years, and the obvious conclusion was drawn immediately: paste in the whole contract, the whole codebase, the whole case file. A result published in 2024 keeps getting in the way of that conclusion, and it has not stopped being true as the windows have grown.
The finding
Nelson Liu, Kevin Lin and Percy Liang published Lost in the Middle: How Language Models Use Long Contexts in the Transactions of the ACL. They took tasks where the answer depends on one specific piece of the input, and moved that piece around.
Accuracy tracked position. Information near the beginning was used well. Information near the end was used well. Information in the middle was used considerably less well, and the curve across position came out U-shaped. Their conclusion is stated plainly: models do not robustly use information in long input contexts.
Why a bigger window does not solve it
The window and the attention are different things. A larger window means more text fits. It says nothing about whether the model attends evenly across what fits, and the effect above is about position rather than capacity.
So enlarging the window moves the middle rather than removing it. A document that sat awkwardly in a 128,000-token prompt sits awkwardly further in when the window is a million, and the part of it that gets read least carefully is still the part in the middle.
The paper also tested an obvious mitigation, putting the question both before and after the documents, and reports that it did not substantially improve robustness to position in multi-document question answering. Worth knowing before building it.
What this costs in practice
A failure that announces nothing. The model does not say it skimmed. It answers from what it attended to, with the same fluency it would have used if it had read everything, and the omission is only visible to somebody who knows what was in the document.
A bill proportional to what you pasted. Input tokens are charged whether they influenced the answer or not, so a long prompt pays in full for text the model used lightly. In Arabic the same document costs considerably more tokens again, which compounds both problems.
Latency the user feels. The whole prompt is processed before the first word of the answer appears, and that wait grows with the input.
A larger surface for planted instructions. Every extra page of untrusted text is another place for an instruction written for the model rather than for a person to sit unnoticed.
Retrieval, which this makes the case for
The argument for retrieval is usually made on cost. The stronger argument is this one: finding the relevant passage with a search system and putting that in the prompt sidesteps the positional problem entirely, because the model is no longer being asked to locate a clause inside a hundred pages it is holding all at once.
A short, relevant extract also means a short prompt, which is cheaper and faster, and a curated one, which is harder to poison. Those are three benefits from one decision, which is unusual. The mechanics of doing it well are the same mechanics that stop a model inventing answers.
If it all has to go in the prompt
Sometimes it does. A contract has to be read as a whole, and splitting it changes the meaning. In that case the finding is still useful, because it tells you where to put things.
Put what the answer depends on near the start or the end rather than buried in the middle. Keep the prompt to what the question needs rather than everything that might be relevant. And ask the model to quote the passage it is relying on before it answers, which turns a silent miss into a visible one.
Sources
The finding and the mitigation that did not work are from Lost in the Middle: How Language Models Use Long Contexts by Nelson F. Liu, Kevin Lin and Percy Liang, in Transactions of the Association for Computational Linguistics, 2024. The paper measures multi-document question answering and key-value retrieval; the drawing above shows the shape it reports rather than any model’s numbers.
The short version
A window large enough to hold your document is not the same as a model that reads all of it. Published work puts accuracy in a U across position, with the middle used least reliably, and a larger window moves the middle rather than removing it. Retrieve the relevant passage instead of pasting everything, and when everything must go in, put what matters at the edges and ask the model to quote what it used.
Frequently asked questions
What is the lost-in-the-middle effect?
A positional bias measured by Liu, Lin and Liang and published in TACL in 2024: models use relevant information placed near the beginning or the end of a long input far more reliably than the same information placed in the middle, producing a U-shaped accuracy curve across position.
Does a bigger context window fix it?
A bigger window changes how much text fits, not how evenly the model attends across it. The effect is about where information sits in the input rather than about running out of room, so enlarging the window moves the middle rather than removing it.
Is retrieval still worth building if the window is huge?
For anything where a specific clause has to be found and used, yes. Retrieval puts a short, relevant extract in front of the model instead of a long document it must search internally, which sidesteps the positional problem, costs less per request and answers faster.
What is the cheapest mitigation if everything must be in the prompt?
Position matters, so put the material the answer depends on near the start or the end rather than buried mid-document, and keep what goes in to what the question needs. Asking the model to repeat the relevant passage before answering also makes a miss visible rather than silent.