Skip to content

< CollectionsArticle

Contextual Retrieval.

Introducing Contextual Retrieval

Anthropic · 2024

Read the article (opens in a new tab)

A chunk loses its context when it is cut out. Put the context back before you index, and search with BM25 as well as embeddings.

5 sections · 9 problems

0 of 9 done

Start Next: 01 Build a Document Chunker

Fig. 1. Cut out of its filing, the chunk never says whose revenue it is, and the search misses it. Write that context onto the chunk before indexing, and the same search finds it.

Section 01

Chunks lose context

0 of 2

The article: A chunk on its own often lacks what it refers to, so the search that should find it misses. A short context written from the whole document puts it back.

  1. 01Build a Document Chunkerimplement · easy
  2. 02Tell Each Chunk Where It Came Fromimplement · medium

Section 02

Embeddings and BM25

0 of 3

The article: Embeddings miss exact terms like an error code; BM25 catches them, so run both and fuse the rankings.

  1. 03Search by Meaning, Not by Wordsimplement · medium
  2. 04Build BM25 From Scratchimplement · medium
  3. 05Fuse BM25 and Dense Search With RRFimplement · medium

Section 03

Reranking

0 of 2

The article: Retrieve a wide set, then rerank it and keep only the top chunks.

  1. 06Rerank the Retrieved Chunksimplement · medium
  2. 07Rerank With a Model That Understands the Questionimplement · medium

Section 04

Measure the failures

0 of 1

The article: Count how often the right chunk is missing from the top twenty.

  1. 08Measure Retrieval with Recall@k and MRRimplement · medium

Section 05

Prompt caching

0 of 1

The article: Writing context for every chunk is cheap when the document stays in the cache.

  1. 09Lay Out the Prompt So the Cache Hitsoptimize · medium
All collections