Glossary
Contextual retrieval
A RAG technique that adds a short, document-aware description to each chunk before it is embedded and indexed.
Contextual retrieval is a retrieval augmented generation technique that adds a short explanation of where each chunk sits in its document before the chunk is embedded and indexed. A chunk that says “revenue grew 3% over the previous quarter” becomes searchable as a statement about a named company in a named quarter. Anthropic described the method in September 2024 and reported that, combined with reranking, it cut retrieval failures by 67% in its tests.
The problem it solves
Chunking cuts documents into pieces small enough to embed and fit in a prompt, and in doing so it strips each piece of the text around it. A passage about “the company” or “this clause” no longer says which company or which contract. Its embedding misses queries that name them, and keyword search misses them too because the names are not in the text. Retrieval then returns chunks on the right topic that cannot be tied to the right source, a failure covered in Similarity isn’t relevance.
How contextual retrieval works
Before indexing, each chunk is sent to a language model with the full document and an instruction to write a short context for it. Anthropic’s version produces about 50 to 100 tokens per chunk, naming the document, section and subject the chunk belongs to. That text is prepended to the chunk, and the combined text is embedded, which Anthropic calls contextual embeddings, and added to a BM25 index, called contextual BM25. At query time the retriever searches both indexes, merges the results with a method such as reciprocal rank fusion and can pass the top candidates to a reranking model.
BM25 vs embeddings explains why the two indexes catch different misses, and contextual embeddings covers other ways to put document context into a chunk’s vector.
Reported results
Anthropic measured the share of queries where the relevant chunk was missing from the top 20 results. Contextual embeddings reduced that failure rate by 35%, adding contextual BM25 took the reduction to 49%, and adding reranking took it to 67%. Twenty chunks worked better than five or ten in the same tests. The figures come from Anthropic’s own datasets, so they show the direction of the gain rather than what a given corpus will see. How to evaluate retrieval and recall@k cover measuring it on your own data.
Setup | Top-20 retrieval failure rate | Reduction |
|---|---|---|
Standard embeddings and BM25 | 5.7% | Baseline |
Contextual embeddings | 3.7% | 35% |
Contextual embeddings and contextual BM25 | 2.9% | 49% |
Both, plus reranking | 1.9% | 67% |
Costs and trade-offs
Every chunk needs a model call at indexing time, and each call includes the whole document. Prompt caching keeps this affordable by loading the document once and reusing it for that document’s chunks. Anthropic estimated a one-time cost of $1.02 per million document tokens with caching, at its model prices at the time. Each re-indexing run repeats the work for changed documents, which makes incremental indexing more valuable. The generated context can also be wrong, so spot-check it on documents where a mistake would matter.
Small corpora may not need retrieval at all. Anthropic’s guidance is that a knowledge base under about 200,000 tokens can go straight into the prompt, the trade-off covered in RAG vs long context.
Contextual retrieval and Exabase
Exabase tackles the same lost-context problem from the search side. Deep Search indexes content stored as Resources when it is written, with no chunking or embedding pipeline to build, and runs hybrid search by default. Each hit returns its source resource with the matched chunks, relevance scores and page numbers or timestamps, so a chunk always arrives attached to the document it came from. Exabase does not write per-chunk context with a language model, so contextual retrieval in Anthropic’s exact form would sit in your own pipeline, for example on chunks from Extract.
RAG accuracy explains the sub-document approach, the searching resources guide covers filters and the precision setting, and the knowledge bases use case shows a corpus kept current by Workers. Best RAG infrastructure compares managed options.
FAQs
What is contextual retrieval?
Contextual retrieval adds a short, model-written description of each chunk’s place in its document before the chunk is embedded and keyword-indexed, so chunks can be found by queries about their source.
Who created contextual retrieval?
Anthropic published the technique in September 2024. Simpler forms of the idea existed earlier, such as adding a document’s title or section heading to each chunk before embedding.
What is the difference between contextual retrieval and contextual embeddings?
Contextual embeddings are one part of the method. Contextual retrieval also applies the added context to a BM25 index and usually adds a reranking step.
Does contextual retrieval work with any embedding model?
Yes. The added context is plain text, so any embedding model and any keyword index can use it.
How much does contextual retrieval cost?
It costs one model call per chunk at indexing time. Anthropic estimated $1.02 per million document tokens with prompt caching, and the cost recurs whenever documents change.
Is contextual retrieval the same as late chunking?
They target the same problem in different ways. Contextual retrieval adds generated text to each chunk, while late chunking embeds the whole document first and pools token vectors into chunk vectors, with no extra model call.
Does Exabase support contextual retrieval?
Not as a built-in step. Deep Search keeps every matched chunk attached to its source document with page numbers or timestamps and combines keyword and semantic search, which addresses the same lost-context problem.
Related pages: Contextual embeddings, Late chunking, Chunking, Sentence window retrieval, Parent document retrieval, Hybrid search, Reranking, BM25, Deep Search, RAG accuracy.