DEV Community

Devanshu Biswas
Devanshu Biswas

Posted on

Lost in the middle: read a long context in parts and summarize each — Thread of Thought beats one gulp

When you paste a long, messy context into a model and ask one question, it skims. Not out of laziness — it's a measured effect. Long-context models show a U-shaped accuracy curve: they use information best when it sits at the very start or very end of the input, and noticeably worse when the same fact sits in the middle. Attention is dominated by primacy and recency. So a decision buried halfway through a sprawling chat thread is exactly where the model is weakest, and a louder distractor at an edge can win instead. Thread of Thought (Zhou et al., 2023) fixes this without shortening the input, and I built a live demo to prove it: a real per-chunk relevance scorer, date extractor and finality detector that you can watch land the buried fact wherever you drag it.

Chain-of-thought fixes the wrong stage

The obvious upgrade is "let's think step by step." It genuinely helps — but CoT segments the reasoning, not the reading. The context is still consumed as one undivided blob in a single pass, so a fact the model skimmed past never enters the reasoning at all. You can reason beautifully over an incomplete picture and still be wrong. ThoT's insight is that the fix has to happen at the reading stage:

// CoT: better reasoning, same one-pass read of the blob
llm(context + question + "Let's think step by step.");
// a mid-context fact it skimmed never reaches the logic.
Enter fullscreen mode Exit fullscreen mode

The whole technique is one zero-shot line

What surprised me is how cheap ThoT is. No retriever, no second model, no extra API call — it's a single sentence appended to the prompt:

const THOT = "Walk me through this context in manageable parts " +
             "step by step, summarizing and analyzing as we go.";
llm(`Context: """${context}"""\nQuestion: ${question}\n${THOT}`);
Enter fullscreen mode Exit fullscreen mode

That one line reshapes the model's behaviour from "skim and answer" to "segment, summarize, then answer." It's the paper's exact zero-shot prompt, and it's attractive precisely because it's almost free to bolt onto any existing prompt.

Segment, summarize each part, carry a running thread

Conceptually ThoT does three things. It cuts the long context into manageable parts — by message, paragraph or window — so each part is small enough to receive full attention on its own pass; there's no "middle" to fall into when every segment briefly becomes the thing being read. For each part it writes a short summary and judges its relevance to the question: is this the fact, a superseded detail, or noise? Then those summaries accumulate into a running thread — a compact, ordered, externalized memory in which the buried fact is now explicit and the distractors are already labelled.

let thread = [];
for (const p of parts) thread.push(summarize(p));   // takeaway per part
const answer = synthesize(thread, question);        // answer from the thread
Enter fullscreen mode Exit fullscreen mode

The final answer is synthesized from that thread, not the raw blob. Because the thread already isolated the decisive fact and downgraded the noise, the synthesis is short and correct.

Why it works — equal attention plus written memory

Two mechanisms combine, and the demo makes both visible. In it, a messy seven-message thread hides one real decision — "we're locking the launch for April 9, that's final" — among distractor dates: an original March 14 target, an unrelated May 2 all-hands, a stale doc still showing March 14. The one-shot reader uses a positional attention weight (high at the ends, low in the centre) times a shallow surface relevance, so it grabs whatever dated chunk sits at an edge. Flip Thread of Thought on and it walks every chunk with equal attention, writes each takeaway down, and synthesizes only the chunk flagged as the final decision. Drag that decision to the start, middle or end and the one-shot answer follows position while the ThoT answer stays pinned to April 9. Segmenting flattens the U-shaped attention curve; writing each takeaway to the thread keeps what was read from decaying before the answer. Together they make the reading position-invariant.

When to reach for it

Use ThoT whenever a fact could be buried in a big input: tangled chat histories, multi-document QA, retrieval dumps full of distractors, needle-in-a-haystack lookups. It's cheaper than a retrieval pipeline — one prompt, no index — and it composes with one: walk the retrieved passages with ThoT to guard against "lost in the middle" inside them. Versus CoT, they stack cleanly — CoT segments the reasoning, ThoT segments the reading. Skip it for short, clean prompts where nothing is buried and there's no middle to lose.

Flip the switch and drag the buried decision around to watch the two answers diverge:
https://dev48v.infy.uk/prompt/day45-thread-of-thought.html

Top comments (0)