Introducing Contextual Retrieval (Anthropic)
TL;DR. For every chunk, give Claude the whole document plus the chunk and ask for a short note that situates the chunk (usually 50–100 tokens). Prepend that note to the chunk before both embedding it and BM25-indexing it. Retrieval failures drop sharply with no training at all.
Why it matters now. This post made the “chunks lose context” problem mainstream. It is the baseline that every later contextual-embedding model compares against: Voyage reports beating it, and research papers cite it. Treat it as the zero-training reference point for the whole section.
Key idea
Section titled “Key idea”- Example: the chunk “The company’s revenue grew by 3% over the previous quarter.” becomes “This chunk is from an SEC filing on ACME corp’s performance in Q2 2023; the previous quarter’s revenue was $314 million. The company’s revenue grew by 3%…”
- Two indexes, both contextualised: contextual embeddings plus contextual BM25, fused with rank fusion. Then rerank the top 150 down to 20 (the post’s tests used Cohere’s reranker).
- Cost control: load the document into the prompt cache once and reuse it for each of its chunks.
Limitations and open questions
Section titled “Limitations and open questions”- It is a vendor blog, not a paper. The evaluation sets are internal, and results are aggregated across domains with one embedding configuration highlighted.
- Index-time cost grows with chunks × document length. Caching helps, but re-indexing a large, frequently changing corpus is still expensive.
- The note is free text from a generator, so it can hallucinate context. The post does not measure how often that hurts retrieval.
- Deployment concerns the post does not cover: freshness (an edited document invalidates every chunk’s note), permissions (a note written from the whole document can leak content from sections a user may not see), index-time latency per update, and evidence localisation (the prepended note, not the chunk, may be what matched).
- It cannot use information from other documents. Compare CDE.
Connections
Section titled “Connections”- Learned alternatives: Late Chunking gets context inside the encoder instead of the text. voyage-context-3 reports beating Contextual Retrieval by 6.76% (chunk level) and 2.40% (document level).
- Head-to-head study: Reconstructing Context (2504.19754) compares late chunking with contextual retrieval.
- Agent-side context engineering: see Agents → Memory & context.
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.
- Derive / compute
Use the post's cost setting: 8,000-token documents, 800-token chunks, a 50-token instruction and 100 output tokens per chunk. Assume these prices per million tokens: input USD 0.25, cache write USD 0.30, cache read USD 0.03, output USD 1.25. (a) Compute the cost per million document tokens without caching, and with the document cached once per document. (b) Redo both for 80,000-token documents with the same chunk size. What scaling law do you see?
What a strong answer covers
- 8k, no cache: 10 calls × 8,850 = 88,500 input tokens (USD 0.0221) plus 1,000 output tokens (USD 0.0013) ≈ USD 0.0234 per document. With 125 documents per million tokens, about USD 2.92.
- 8k, cached: one write of 8,000 (USD 0.0024), nine reads of 8,000 (USD 0.0022), 8,500 uncached chunk and instruction tokens (USD 0.0021), output (USD 0.0013) ≈ USD 0.0079 per document, about USD 0.99 per million. The post reports USD 1.02 under the same assumptions; the gap depends on exactly what is cached.
- 80k, no cache: 100 calls × 80,850 = 8.085M input tokens (USD 2.02) plus 10,000 output ≈ USD 2.03 per document. With 12.5 documents per million, about USD 25.
- 80k, cached: write 80,000 (USD 0.024), 99 reads = 7.92M tokens (USD 0.24), 85,000 uncached (USD 0.021), output (USD 0.0125) ≈ USD 0.30 per document, about USD 3.7 per million.
- Scaling: cost per document ≈ (L/c)·L, so cost per document token grows linearly with document length L. Caching shrinks the constant on that term about 8× (0.03 vs 0.25) but does not change the law.
- Mechanism
The post reports that prepending generic document summaries gave very limited gains, while a chunk-specific note works well. Explain the difference separately for the dense embedding and for BM25, in terms of what each kind of note does to the chunk's vector and to its term statistics.
What a strong answer covers
- BM25: the note adds the missing query terms (company, quarter) to the chunk's term vector, so an exact-match query can hit it. A generic summary adds the same terms to every chunk of the document, so they no longer separate this chunk from its siblings.
- BM25 side-effects: every chunk grows by 50–100 tokens, which shifts length normalisation, and document-wide terms now occur in many more chunks, which lowers their IDF.
- Dense: a shared summary pulls every chunk vector of the document towards the same point. That helps find the document but erases within-document discrimination, the same collapse that InSeNT's same-document negatives counter.
- A chunk-specific note adds only the context this chunk lacks, so it disambiguates the document while keeping the chunk distinct.
- What if…
The headline numbers are cumulative: top-20 failure rate 5.7% → 3.7% (contextual embeddings) → 2.9% (+ contextual BM25) → 1.9% (+ reranking). Compute what each step removes as a share of the failures left before it, and explain what these numbers cannot tell you about the value of contextual BM25 itself.
What a strong answer covers
- Per step: (5.7 − 3.7)/5.7 ≈ 35%; (3.7 − 2.9)/3.7 ≈ 22%; (2.9 − 1.9)/2.9 ≈ 34%.
- The second step changes two things at once: it adds a lexical index (hybrid fusion) and contextualises it. Without a contextual-embeddings-plus-plain-BM25 arm you cannot split the hybrid gain from the context gain; the post's appendix breakdown is where to look.
- Stacked gains depend on order. A reranker may recover part of what contextual BM25 adds, so each component's marginal value inside the full stack can be smaller than its step here.
- A clean design is factorial: {plain, contextual} × {dense only, hybrid} × {no rerank, rerank}, reported per domain with confidence intervals.
- Critique
The context note is free text that an LLM writes from the whole document. Explain how a wrong or overly generic note could hurt retrieval in ways that 1 − recall@20 averaged over four domains would hide, and design an experiment that measures it.
What a strong answer covers
- A hallucinated entity or date makes the chunk match other queries. That costs precision for those queries, while recall@20 on the chunk's own queries can still look fine.
- A note that copies document-level facts into every chunk makes near-identical documents (templates, report editions) harder to tell apart at chunk level.
- Averages over domains with one highlighted embedding configuration, on internal evaluation sets, hide where it hurts.
- Experiment: audit a sample of notes against their documents for factual errors; inject controlled errors (wrong entity, wrong period) into k% of notes; measure recall and precision separately for affected and unaffected queries, per domain.
- Design
You index 20 million chunks from 2 million contracts. About 2% of documents change every day, and most contracts are near-identical templates that differ in party names, dates and amounts. Choose between Anthropic-style contextual retrieval and a late-chunking contextual encoder, and say how you would validate the choice.
What a strong answer covers
- Daily re-indexing: contextual retrieval needs one LLM call per chunk, each reading the whole document, for every changed document. Late chunking needs one encoder pass per changed document.
- Templates: the disambiguating field (party, date) may be far from the chunk. The note writes it into BM25-visible text, which suits exact field queries; a contextual encoder has to learn to carry it into the vector.
- A defensible hybrid: late chunking for dense retrieval, plus cheap deterministic metadata (title, parties, date) prepended for BM25, with an LLM note only where metadata is missing.
- Validate on held-out queries that need the disambiguating field: document disambiguation accuracy (right contract among look-alikes), chunk-level recall, and cost per re-indexed document.
- Connect
Jina's late-chunking paper reproduced this method with Claude 3 Haiku on the ACME example and found that the two methods give the relevant chunk similar similarity to the query. Explain how the two methods move the same information into the chunk vector by different routes, and when they would diverge.
What a strong answer covers
- Contextual retrieval moves context through text: the LLM writes the missing entity into the chunk, so any encoder and BM25 can see it.
- Late chunking moves it through hidden states: the chunk's tokens attend to the whole document, and the pooled vector absorbs the antecedent.
- They diverge when the document is longer than the encoder window (the LLM can read more), when the encoder never learned to use context, or when exact terms matter for BM25 (only the text route helps lexical retrieval).
- They also differ in cost and in failure modes: hallucinated notes versus diluted mean pooling.