Skip to content

Lost in the Middle: How Language Models Use Long Contexts

Skip →YaRN
LLM stage 2 #1corefundamentalpaperrubric 11/122023 · TACL 2023 · ~40 min

Nelson F. Liu, Kevin Lin, John Hewitt, …, Percy Liang

Status

TL;DR. Give a model 20 retrieved passages, one of which holds the answer, and move that passage from first to last. Accuracy traces a U: high when the gold passage is first, lowest in the middle, partly recovered at the end. For GPT-3.5-Turbo the middle is worse than answering with no passages at all.

Why it matters now. RAG systems, rerankers and search agents all decide which passages to put in the prompt and in what order. This paper shows that the reader is itself a ranking-sensitive component: putting the best evidence first or last matters, and adding more passages beyond about 20 barely helps. Those are IR problems (reranking, truncation, placement), not only model problems.

Hold the question and passages fixed and vary only the gold passage’s position ii among kk passages. Measure accuracy Acc(i,k)\text{Acc}(i, k) for multi-document QA on NaturalQuestions-Open (2,655 queries, Contriever distractors, k∈{10,20,30}k \in \{10, 20, 30\}). A synthetic key-value task (find the value for a UUID key among 75 to 300 JSON pairs) tests pure retrieval from context.

A useful summary is the gap between the edges and the middle, and the comparison with the closed-book score:

ΔU=Acc(1,k)−min⁡iAcc(i,k),harmful if min⁡iAcc(i,k)<Accclosed-book.\Delta_{\text{U}} = \text{Acc}(1, k) - \min_i \text{Acc}(i, k), \qquad \text{harmful if } \min_i \text{Acc}(i, k) < \text{Acc}_{\text{closed-book}}.

For GPT-3.5-Turbo with 20 passages, ΔU=75.8−53.8=22\Delta_{\text{U}} = 75.8 - 53.8 = 22 points, and the minimum is below its 56.1 closed-book score.

Lost in the middle: QA accuracy depends on where the gold passage sits among 20 retrieved passages Left: a line chart of multi-document QA accuracy against the position of the answer-bearing passage among 20 passages, redrawn from the paper's appendix table. GPT-3.5-Turbo scores 75.8 percent when the passage is first, falls to 53.8 percent at position 10 and recovers to 63.2 percent at position 20, a U shape. Its middle positions fall below its closed-book score of 56.1 percent, drawn as a dashed line. Claude-1.3 has a flatter curve between about 56 and 60 percent. Right: what this means for a retrieval-augmented pipeline. Recall from the retriever keeps rising with more passages, but the reader saturates, so precision at the top and placement of the best passages at the edges of the prompt matter more than packing in more passages. Accuracy vs gold-passage position (20 passages) 50607080 15101520 position of the gold passage in the prompt GPT-3.5 closed-book 56.1 75.8 53.8 63.2 GPT-3.5-Turbo (thick) Claude-1.3 (thin) Numbers from the paper's Table 6 (20 documents); redrawn, not copied. What it means for RAG retriever: recall keeps rising reranker / truncation: fewer, better reader: saturates after ~20 docs Going from 20 to 50 passages adds ~1.5 points (GPT-3.5) and ~1 point (Claude-1.3), while recall climbs. Place the strongest evidence at the start (or end) of the prompt, not in the middle.
Original sketch, redrawn from the paper's Table 6. Accuracy by gold position for GPT-3.5-Turbo and Claude-1.3 with 20 passages, and what it implies for a retrieve-rerank-read pipeline.
  • §2–3, closed-book vs oracle accuracy: GPT-3.5-Turbo 56.1 vs 88.3, Claude-1.3 48.3 vs 76.1, MPT-30B-Instruct 31.5 vs 81.9, LongChat-13B (16K) 35.0 vs 83.4.
  • Appendix G, Table 6 (20 passages, positions 1/5/10/15/20): GPT-3.5-Turbo 75.8 / 57.2 / 53.8 / 55.4 / 63.2; Claude-1.3 59.9 / 55.9 / 56.8 / 57.2 / 60.1, a much flatter curve.
  • Table 7 (30 passages): GPT-3.5-Turbo (16K) drops from 73.4 at position 1 to 50.5 at position 10 and recovers to 63.7 at position 30.
  • Key-value retrieval (Figure 7): Claude-1.3 is near perfect; other models struggle at 140 and 300 pairs, with a worst case of 45.6%.
  • §5, Figure 11: reader accuracy saturates long before retriever recall.
  • Appendix D–E: GPT-4 is better overall but still U-shaped; Llama-2 7B is only recency-biased, while 13B and 70B are U-shaped.
  • One gold passage per question and clean distractors; real retrieved lists mix partial, redundant and conflicting evidence.
  • QA inputs reach only a few thousand tokens (Appendix F) and the models are from 2023. The curve must be re-measured for each new model.
  • The analysis is behavioural. Why the bias forms (data order, positional encoding, attention patterns) is open.
  • Open for IR: should rerankers optimise a position-aware utility that accounts for the reader’s U-shape rather than plain nDCG?

Questions to think through

These questions have no single right answer. Write or say your answer before you open the hints. Mark a question once you could defend your answer in a reading group.

  1. Derive / compute

    Use GPT-3.5-Turbo's 20-document accuracies by gold position (position 1: 75.8, 5: 57.2, 10: 53.8, 15: 55.4, 20: 63.2; closed-book 56.1). Your reranker puts the gold passage at rank 1 for 50% of queries, rank 5 for 30% and rank 10 for 20%, and you insert passages in rank order. Compute expected accuracy. Then reorder so that rank 5 goes to position 20 and rank 10 to position 15, and recompute, assuming each position's aggregate accuracy transfers to your rank groups. Which position condition has a lower aggregate accuracy than the closed-book setting, and what can and cannot be concluded from that?

    What a strong answer covers
    • Rank order: 0.5 × 75.8 + 0.3 × 57.2 + 0.2 × 53.8 = 37.90 + 17.16 + 10.76 = 65.82.
    • Reordered: 0.5 × 75.8 + 0.3 × 63.2 + 0.2 × 55.4 = 37.90 + 18.96 + 11.08 = 67.94, about 2 points gained only by moving passages.
    • Gold at position 10 gives 53.8, below the 56.1 closed-book score, so in aggregate that position condition does worse than giving the model no passages.
    • This does not identify which individual queries should skip retrieval: the mixture arithmetic assumes position-conditional accuracy transfers to your rank groups, but rank and question difficulty may be correlated, and aggregate means say nothing about per-query counterfactuals.
    • Raising the share of rank-1 golds is worth more than any reordering: each 10 points of queries moved from rank 10 to rank 1 adds about 2.2 points.
    • Caveat: these are averages from controlled insertions with one gold passage; real lists can hold several relevant passages, so the 2.2-point figure is also only an estimate under the transfer assumption.
  2. Mechanism

    The paper runs three probes into why the U-shape appears: encoder-decoder vs decoder-only models, query-aware contextualization, and base vs instruction-tuned models. State what each probe found and what explanation of the U-shape survives.

    What a strong answer covers
    • Encoder-decoder: Flan-UL2 is fairly robust (1.9-point best-to-worst gap) when the input fits its 2048-token training length, but becomes U-shaped beyond it. Bidirectional encoding helps only within the trained length.
    • Query-aware contextualization (query placed before and after the data) makes key-value retrieval near perfect, but barely changes the multi-document QA curve. So decoder-only models not seeing the query early is not the main cause for QA.
    • Instruction tuning: base MPT-30B is also U-shaped, so instructions placed at the start of tuning data do not explain the primacy effect alone.
    • Scale: Llama-2 7B is only recency-biased; 13B and 70B show both primacy and recency. The U-shape seems to emerge with scale and training.
    • What survives: a position bias learned in training, close to the serial-position effect in human recall. The paper does not identify a mechanism inside the network.
  3. What if…

    Compare GPT-3.5-Turbo with GPT-3.5-Turbo (16K), and Claude-1.3 with Claude-1.3 (100K), across 10, 20 and 30 documents. What does this show about whether a longer context window fixes the problem, and how does the open-domain experiment with up to 50 retrieved documents support this?

    What a strong answer covers
    • Extended-context versions score almost the same as the base ones at every position: 20 documents, gold at position 1, GPT-3.5-Turbo 75.8 vs 16K 75.7; Claude-1.3 59.9 vs 100K 59.8.
    • More documents deepen the middle dip: GPT-3.5 (16K) with 30 documents falls from 73.4 at position 1 to 50.5 at position 10.
    • In open-domain QA with Contriever, reader accuracy saturates long before retriever recall. Going beyond 20 documents adds about 1.5 points for GPT-3.5-Turbo and about 1 point for Claude-1.3.
    • Conclusion: a longer window only adds capacity, not better use of it. The bottleneck is how the model uses positions, not how many tokens fit.
  4. Critique

    Critique the experimental design as evidence about RAG in 2025. Consider how distractors are chosen, the accuracy metric, the role of parametric knowledge in NaturalQuestions, and the set of models.

    What a strong answer covers
    • Distractors are top Contriever passages that do not contain an annotated answer, so they are topically close but clean. Real retrieved lists contain partial or conflicting evidence and several relevant passages.
    • The metric checks whether any gold answer string appears in the output. It rewards long outputs and cannot detect a correct answer in a different form.
    • NQ-Open questions are often answerable from memory (GPT-3.5 closed-book 56.1), so the experiment mixes using the passage with recalling the fact. Rare-entity questions would isolate context use.
    • The 2023 models (GPT-3.5, Claude-1.3, MPT-30B, LongChat-13B) have mostly been replaced. Newer evaluations such as RULER and NoLiMa show related weaknesses at longer lengths, but the exact U-shape must be re-measured per model.
    • Each passage is at most 100 tokens, so QA inputs reach only about 4–8K tokens (key-value inputs about 21K), far from today's 128K windows.
  5. Design

    You build the reader stage for a RAG system with a 20-passage budget. Using this paper's findings, design the pipeline between first-stage retrieval and the prompt (reranking, truncation and ordering), and describe an evaluation that would show whether each step pays off for your reader model.

    What a strong answer covers
    • Rerank with a strong cross-encoder so the best evidence reaches the top ranks, as the paper suggests; then apply ranked-list truncation (Arampatzis et al., 2009) to stop when scores fall, instead of always filling 20 slots.
    • Place the best passages at the edges of the prompt, for example top-1 first and the next best last, since middle positions are used worst.
    • Evaluation: re-run the paper's position sweep on your reader with your own retrieved lists, measuring accuracy by gold position and number of passages, and compare against closed-book.
    • Report recall@k of the retriever next to reader accuracy at k, to see where the reader saturates (the paper found about 20 passages).
    • Check faithfulness separately, e.g. with nugget-based evaluation, since substring accuracy can be met from memory.
  6. Research idea

    Deep-research agents accumulate tool outputs over many turns, so the evidence a final answer needs may sit anywhere in a long trace. Propose a study that extends the position sweep to agent traces, and say what result would change how such agents should manage their context.

    What a strong answer covers
    • Fix a set of questions whose answer requires one specific tool output. Replay the same trace while moving that output to different turns and padding with real but irrelevant tool outputs, keeping total length fixed.
    • Vary total length (8K to 128K) and the number of relevant outputs, and compare against a summarised or reranked memory of the same trace.
    • If accuracy depends strongly on the turn index, agents should re-retrieve or re-rank their own history before answering, treating context as a retrieval problem.
    • If accuracy is flat for current models, the U-shape is a solved 2023 artefact and long raw traces are fine. Report both results per model family, since the shape depends on scale.

Done with this page?

Status