Skip to module content
Module 13 ยท ~14 min

Working With Long Context

A million tokens is a capability, not a strategy.

Reading progress
0/5 ยท 0%

The big idea

๐Ÿ’กKey idea
A huge context window means content technically fits, but fitting isn't the same as the model attending to it well โ€” models pay less attention to content buried in the middle of a long context, a phenomenon called lost-in-the-middle. Structured approaches like map-reduce, pointers, and checkpoint summaries beat dumping everything into one giant paste.
Quick check
1 question ยท instant feedback
0/1
  1. "Lost in the middle" refers to:

Deep dive

7/7 open

A model with a very large context window can technically hold hundreds of pages of text at once, and that's genuinely useful โ€” it means you can hand over an entire contract, codebase, or research corpus without pre-chunking it yourself. But there's an attention tax: everything in that context is competing for the model's limited attention, and a single relevant paragraph buried among 200 pages of noise gets diluted.

The capability of a large context window and the strategy of how you use it are two different things โ€” having room for a million tokens doesn't mean the best move is filling it.

Research and practical experience both show that models tend to pay less attention to content placed in the middle of a long context than content at the beginning or end โ€” a phenomenon called "lost in the middle." This means if the answer to your question happens to sit in the center of a huge pasted document, the model is measurably more likely to miss it or under-weight it compared to the same fact placed near the start or end.

This has a direct practical implication: placement matters, and pointing the model explicitly at where to look ("see section 4.2") compensates for attention that naturally degrades with distance from the edges.

The map-reduce pattern handles large documents more reliably than one giant paste: in the "map" phase, you extract structured information from each section or document individually ("liabilities, unusual terms, dates โ€” structured"), then in the "reduce" phase, you run a synthesis pass over just those extractions ("patterns, contradictions, top risks") rather than over the raw source material again.

This is not just more reliable โ€” it's also traceable: every fact in the final synthesis can be tracked back to the specific extraction, and from there to the specific source document, which matters enormously for due diligence, legal review, or any high-stakes reading task.

For long-running projects or documents that keep growing, the same map-reduce idea applies over time rather than over sections: periodically summarize the current state โ€” decisions made, open questions, next steps โ€” rather than letting the full history accumulate indefinitely in one context.

This progressive summarization keeps a living project navigable no matter how long it runs, because you're always working from a compact, current summary rather than re-reading the entire history each time you need to orient yourself.

When you know roughly where relevant information lives in a large document, say so explicitly rather than relying on the model to find it unaided: "using section 4.2 specifically, summarize the payment terms" dramatically outperforms a bare "summarize the payment terms" against the same large document.

Pointers cost you nothing extra to write and meaningfully improve accuracy, precisely because they counteract the lost-in-the-middle effect by directing attention rather than hoping the model self-navigates.

Long context and retrieval-augmented generation (RAG, covered in module A3) solve related but different problems. Long context is well suited to one-off, deep reads of a specific set of documents โ€” read this whole data room once, thoroughly. RAG is better suited to repeated queries over a stable corpus that doesn't change often, because it retrieves only the relevant chunks each time rather than re-processing everything.

Choosing between them comes down to frequency and stability: a document you'll query once deeply favors long context; a corpus you'll query dozens of times over weeks favors RAG.

Long conversations degrade the same way long documents do โ€” accumulated turns compete for attention and contradictions pile up. The fix is a checkpoint habit: roughly every 20 turns, ask for a summary of current state โ€” decisions, open questions, next steps โ€” and paste that summary into a fresh thread rather than continuing the increasingly cluttered original.

This single habit prevents the common failure mode of a 200-turn "sludge" thread that's technically still within the context window but has become functionally unreliable, and it costs almost nothing compared to the quality it preserves.

Quick check
1 question ยท instant feedback
0/1
  1. What does map-reduce mean in this context?

Pitfalls & takeaways

Failure modes

  • Pasting an entire large document and asking one question, trusting that "it fits" means it will be read carefully
  • Ignoring lost-in-the-middle effects on content placed in the center of a huge context
  • Letting week-long project chats run to hundreds of turns instead of checkpointing into fresh threads
  • Using long context for a task that actually needs repeated querying over a stable corpus (a RAG use case)
  • Not pointing the model at the specific section relevant to a question when the source document is large

Durable takeaways

  • A large context window is a capability, not a strategy โ€” fitting content doesn't mean it's attended to well
  • Map-reduce (per-section extraction, then synthesis) beats one giant paste for large documents
  • Checkpoint long conversations into fresh threads every ~20 turns to avoid degraded, cluttered context
Quick check
1 question ยท instant feedback
0/1
  1. When should you choose RAG over simply using long context?

Do the work

๐Ÿ‹๏ธProve you learned it

Take one document too large to read comfortably yourself, or five long related documents, and run a map-reduce pass: extract structured information per section or per document, then run a synthesis pass over just those extractions. Compare the result against a single whole-document paste on three specific questions, and score which approach actually found more.

0 chars
Quick check
1 question ยท instant feedback
0/1
  1. What is the checkpoint habit for long conversations?

Sources

  • ยท Anthropic docs (docs.claude.com โ€” long context tips)
  • ยท OpenAI Cookbook (cookbook.openai.com)
  • ยท Simon Willison (simonwillison.net) on context strategies