Skip to content

< CollectionsPaper

Lost in the Middle.

Lost in the Middle: How Language Models Use Long Contexts

Liu et al. · 2023 · arXiv 2307.03172

Read the paper (opens in a new tab)

Models use what is at the start and the end of a long context best, and miss what is in the middle.

3 sections · 6 problems

0 of 6 done

Start Next: 01 Put the Answer Where the Model Will Read It

Fig. 1. Twenty documents, one holding the answer. Move it from first to last: the model finds it best at the start, then at the end, and worst in the middle.

Section 01

The U-shaped curve

0 of 1

The paper: Accuracy is highest when the relevant document is first or last in the context, and drops when it sits in the middle.

  1. 01Put the Answer Where the Model Will Read Itimplement · medium

Section 02

More documents, little gain

0 of 3

The paper: Past about twenty retrieved documents, adding more barely helps the reader, even as recall keeps rising.

  1. 02Rerank the Retrieved Chunksimplement · medium
  2. 03Rerank With a Model That Understands the Questionimplement · medium
  3. 04Stay Under the Token Budgetoptimize · medium

Section 03

A long conversation

0 of 2

Beyond the paper: The same lesson for a chat: what you keep, and where you put it, decides what the model reads.

  1. 05Trim the Conversation, Keep the System Promptimplement · medium
  2. 06Compact a Long Conversation Without Losing the Decisionimplement · medium
All collections