The lost-in-the-middle effect is the tendency of language models to use information best when it appears at the beginning or end of their input, and worst when it appears in the middle. It was measured in a 2023 study from Stanford and has direct consequences for how pages should be written if they are to be quoted by AI assistants.
The study
“Lost in the Middle: How Language Models Use Long Contexts” was published in July 2023 by Nelson F. Liu, Kevin Lin, John Hewitt, Ashwin Paranjape, Michele Bevilacqua, Fabio Petroni and Percy Liang, and later appeared in the journal Transactions of the Association for Computational Linguistics in 2024.
The researchers gave models a question and a set of documents, only one of which contained the answer, and moved that document to different positions in the input. They ran a second test in which models had to retrieve a value from a long list of key-value pairs.
What they found
- Accuracy followed a U-shaped curve: highest when the relevant document was first or last, lowest when it was in the middle.
- The effect appeared in models built for long inputs as well as standard ones.
- In one setting, GPT-3.5-Turbo answered less accurately with the relevant document placed in the middle of 20 documents than it did with no documents at all, when it had to rely on memory alone.
- Adding more documents did not reliably help, because the extra material pushed the useful document further from the edges.
Model makers have worked on long-context performance since 2023, and newer models handle it better. How strongly the effect applies depends on the model and the task, but no published result shows position has stopped mattering.
Why it matters for AI search
An AI assistant using retrieval-augmented generation places several retrieved passages into the model’s input and asks it to answer. The same position effect applies at two levels:
- Within the set of passages: a passage placed early or late in the input is more likely to influence the answer.
- Within a single passage: the sentence that states the answer is more likely to be used if it comes first.
You cannot control where a system places your passage among others. You can control where the answer sits within your own text.
How to write for it
Put the answer first
Start each section with the sentence that answers its heading. Background, history and caveats come after.
Keep sections short enough to be one passage
A section that runs for many paragraphs is likely to be split by a retrieval system. If the answer is in the third chunk, the first two compete with it.
Repeat the key fact in the summary line
For long guides, a short summary at the top that states the main conclusions gives systems an answer at the start of the page, where it is most likely to be used.
Avoid long lead-ins
Introductions like “In today’s fast-changing digital world” push the useful sentence down and add nothing a model can quote.
Before and after
| Before | After |
|---|---|
| Crawl budget has been discussed in the SEO community for years, and many site owners worry about it. Google has written about the topic several times. In practice, it mainly matters for very large sites. | Crawl budget mainly matters for sites with more than about a million pages, or around ten thousand pages that change daily, according to Google. Smaller sites rarely need to manage it. |
The second version puts the answer and its source in the first sentence, where both people and models look first.
Frequently asked questions
Do bigger context windows solve the problem?
Not on their own. The original study found the effect in long-context models too. A bigger window lets a model read more, but position still affects how well it uses what it reads.
Does this apply to Google’s normal rankings?
The study measured how language models read their input and did not look at search rankings. Answer-first writing also helps featured snippets, but for a different reason: Google selects a passage that answers the query directly.