Back to glossary

Term

Contextual Retrieval

Contextual Retrieval is an Anthropic RAG technique that prepends an LLM-generated context sentence to every chunk before indexing — sharply raising retrieval quality.

Contextual Retrieval — explained in more detail

Classic RAG splits documents into chunks and embeds them in isolation — losing the link back to the surrounding document. A chunk like “revenue rose 12%” carries no meaning without its chapter and quarter. Contextual Retrieval has an LLM (e.g. Claude) generate a short context sentence for every chunk before indexing, anchoring the chunk inside the document, and prepends it to the chunk text. The enriched text is then written into both a vector index (contextual embeddings) and a BM25 index (contextual BM25) — both run in parallel and their hits are merged.

Example / Practical context

Anthropic reports 35% fewer retrieval failures from contextual embeddings alone, 49% with contextual embeddings combined with contextual BM25, and 67% on top of that when a reranker is added. The one-off indexing cost — one LLM call per chunk — amortises because the index is static and only needs rebuilding on updates. Prompt caching cuts costs further, since the source document gets reused across the per-chunk LLM calls.

Query expansion operates at query time and enriches the search query; contextual retrieval operates at indexing time and enriches the chunks being searched. Reranking runs after retrieval and re-orders hits without touching the index. In practice all three can be stacked.

Entdecke mehr

Themenuebersicht