What you will be able to do
- Merge the BM25 and vector rankings into one candidate set, then rerank it down to a top-k
- Choose how many chunks to pass to Claude, and explain the latency and cost trade-off of reranking
- Pass retrieved chunks as search_result blocks with citations enabled so answers can be traced to their sources
- Place the cache breakpoint correctly when the same retrieved content goes into many requests
1.Retrieve broadly, fuse, rerank and pass the top-k
At query time, the pipeline turns a user's question into a short, well-ordered list of chunks. Ingestion has already built a BM25 index and a vector index over chunks that each carry a short generated context; for why both indexes are needed, see Semantic embeddings vs BM25, and hybrid search. Each index returns its own ranking. BM25 ranks chunks by exact term matches, and the vector index ranks them by semantic similarity to the question, which is embedded with input_type="query". Rank fusion then merges the two lists and removes duplicates, leaving one set of candidates.
Retrieve broadly, then rerank narrowly. In a large knowledge base, the first retrieval can return hundreds of chunks of mixed relevance. A reranking model takes the query and the candidate list, scores each chunk for relevance, and you keep only the top-k. Anthropic's tests sent 150 candidates in and kept 20, using the Cohere reranker. Voyage offers rerank-3 for the highest accuracy and rerank-3-lite when latency and cost matter more, both called with rerank().
| Pipeline | Failure rate | Reduction vs. baseline |
|---|---|---|
| Standard embeddings | 5.7% | — |
| Contextual embeddings | 3.7% | 35% |
| Contextual embeddings + contextual BM25 | 2.9% | 49% |
| Reranked contextual embeddings + contextual BM25 | 1.9% | 67% |
Reranking has a cost of its own. Claude gets fewer chunks, so generation is cheaper and faster, but the reranker adds a step to every request. It scores chunks in parallel, yet scoring more candidates still adds latency and cost. Choose the number of candidates against your latency budget: more candidates give better results, fewer give lower latency and cost.
Choosing k trades recall against distraction. More chunks make it more likely the answer is in the prompt, and more text also gives the model more to be distracted by. Twenty beat five and ten in Anthropic's tests, but that doesn't make 20 a constant. Measure it with Pass@k: for each test query, check whether its known relevant chunk appears in the first k results. On one codebase dataset, plain embeddings scored 81% at Pass@5 and 90% at Pass@20.
Checkpoint 1 of 5· Put it in order
A user's question arrives at a RAG pipeline that has a contextual BM25 index, a contextual vector index and a reranker. Put the query-time steps in order.
- 1.Send the candidate chunks and the user's query to a reranking model, which scores each chunk for relevance
- 2.Merge the two rankings with rank fusion and remove duplicates to get one broad candidate set
- 3.Keep only the top-k highest-scoring chunks
- 4.Search both indexes: BM25 matches exact terms, and the vector index searches with the question embedded using input_type="query"
- 5.Add those top-k chunks to the prompt Claude uses to generate the answer
The pipeline retrieves broadly first, then narrows. Both indexes return candidates, and rank fusion merges them. The reranker can only score chunks that have already been retrieved, and Claude sees only the top-k chunks left after reranking.
“give each chunk a score based on its relevance and importance to the prompt, then select the top-K chunks”Source: www.anthropic.com
Checkpoint 2 of 5· Exam question
A platform team is redesigning their RAG pipeline after an audit found a high rate of retrieval failures, where relevant chunks exist in the knowledge base but are not returned for matching queries. They can implement several changes before the next release. Which of the following changes are documented to measurably reduce retrieval failure rates? (Select all that apply.)(Select 3)
Correct answers: A, B, C — Prepend chunk-specific contextual summaries to chunks before generating their embeddings.; Index the same contextualized chunk text lexically with BM25 alongside the embeddings.; Add a reranking stage that rescores initial retrieval candidates before generation.
- A. Correct. Contextual embeddings, which prepend explanatory context before encoding, are documented to reduce retrieval failures on their own.
- B. Correct. Combining contextual embeddings with contextual BM25 lexical indexing further reduces retrieval failures beyond embeddings alone.
- C. Correct. Adding a reranking stage on top of contextual embeddings and BM25 produces the largest documented reduction in retrieval failures of the three combined techniques.
- D. Incorrect. Sampling temperature affects the wording and variability of the generated answer text; it has no effect on which chunks are retrieved or how retrieval failures occur.
- E. Incorrect. Binary quantization is a storage and cost optimization that reduces embedding precision; it is not a documented technique for reducing retrieval failure rates and can trade off retrieval accuracy for space.
- F. Incorrect. Disabling overlap speeds up index building but removes a safeguard against split-boundary content, which tends to increase rather than decrease retrieval failures.
2.Passing chunks to Claude as citable search results
Chunks pasted into the prompt as plain text lose the link to where they came from. Search result content blocks keep that link. Each retrieved chunk goes in as a search_result block with a source and a title. With citations enabled, Claude attributes its answer to those sources the same way it cites web search results. No special prompting is needed: the citations appear on the text blocks that draw on your content.
{
"type": "search_result",
"source": "https://example.com/article", // Required: Source URL or identifier
"title": "Article Title", // Required: Title of the result
"content": [
// Required: Array of text blocks
{
"type": "text",
"text": "The actual content of the search result..."
}
],
"citations": {
// Optional: Citation configuration
"enabled": true // Enable/disable citations for this result
}
}source accepts any stable string, such as a URL or an internal identifier like kb://article-1234, so point it at the chunk's document in your store. content is an array of text blocks only; images and other media aren't supported. Citations are off by default, so set citations.enabled to true. Every search result in a request must use the same citations setting.
There are two ways to deliver search results. In the first, a custom retrieval tool such as search_knowledge_base returns search_result blocks inside its tool_result. If retrieval must run on every request, force the call with tool_choice. In the second, you fetch the chunks yourself and put the search results directly in the user message. All active models support search results with citations except Claude Haiku 3.
You also choose what text goes into each block. Responses may improve when Claude gets the contextualized chunk with the generated context clearly separated from the original chunk text. Run evals before settling on a format.
Each chunk went to Claude as a search_result block whose source field held a stable identifier for its article, and citations were enabled on every result. Each cited passage in the answer carries that source and title.
Checkpoint 3 of 5· Check yourself
Your retrieval tool returns each chunk as a search_result block with a source of the form kb://article-1234 and a title. You leave out the optional citations field. Claude answers correctly, but no citations appear. What is the most likely cause?
Sending chunks as search_result blocks doesn't turn citations on, because they are off by default. Set citations.enabled to true, with the same setting on every result in the request. No special prompting is needed. Any stable string works as the source. Results returned by a tool and results placed in the user message both support citations.
“Citations are disabled by default; every example on this page sets "enabled": true explicitly.”Source: platform.claude.com
3.Caching retrieved context that repeats across queries
Some pipelines send the same retrieved content on every request. A support bot, for example, might add the same product documentation to the system prompt and then append each user's question. Prompt caching (Prompt reuse and caching) lets that repeated prefix be read from the cache instead of processed again, but only if the request is ordered and marked correctly.
Put the static content first and mark where it ends. Cache prefixes are built in a fixed order: tools, then system, then messages. The documentation therefore comes before the question, and the cache_control breakpoint goes on the last block of the documentation. The question that follows changes every time and stays outside the cached prefix. A breakpoint on the question would cache a prefix that no other request shares. A breakpoint on the first sentence of the system prompt would leave the documentation uncached.
Requests don't need an identical final message to benefit. A single breakpoint at the end of the static content is enough, because the system finds the longest prefix that an earlier request already wrote to the cache. search_result blocks also accept cache_control, so results passed in the messages can carry the breakpoint themselves.
Checkpoint 4 of 5· Check yourself
A support bot sends the same five search_result blocks of product documentation in the user message on every request, followed by a text block with that user's question. The team wants those repeated blocks read from the cache. Where should the cache_control breakpoint go?
Put the breakpoint at the end of the static content, here the last search_result block, which accepts cache_control. The system matches the longest prefix already in the cache, so the question that changes on every request doesn't stop cache reads. A breakpoint on the question caches a prefix no other request shares. A breakpoint on the first sentence of the system prompt leaves the documentation uncached.
“cache_control | object | Cache control settings (for example, {"type": "ephemeral"})”Source: platform.claude.com
Checkpoint 5 of 5· Exam question
A support-bot pipeline retrieves the same set of product documentation chunks for every user session and appends them to the system prompt, followed by whatever question the current user asks. The team wants to use prompt caching to cut latency and cost across the many queries that reuse this documentation. Where should they place the cache breakpoint?
Correct answer: A — On the last content block of the retrieved documentation, immediately before the user's question is added to the request.
- A. Correct. The cache breakpoint should sit on the last block that stays identical across requests. In this pipeline, that is the end of the retrieved documentation, right before the variable user question, so every query benefits from a cache hit on the stable content.
- B. Incorrect. The user's question changes on every request, so placing the breakpoint there means the cached prefix never matches between requests and no cache hits occur.
- C. Incorrect. Caching only the first sentence of the system prompt leaves the much larger, genuinely stable retrieved documentation uncached, missing almost all of the available savings.
- D. Incorrect. Caching does not require the entire request to be identical; only the cached prefix (here, the retrieved documentation) needs to match, so this pipeline is a strong caching candidate.
Sources5
Sources
(5)
Every claim above is drawn from one of these pages, quoted as it was written on the date shown.
- 1.
“Voyage AI also offers rerankers, which take a query and a list of documents and return them ranked by relevance to the query.”
↩︎ Retrieve broadly, fuse, rerank and pass the top-k - 2.https://www.anthropic.com/engineering/contextual-retrievalSecondary source
“Combine and deduplicate results from (3) and (4) using rank fusion techniques;”
↩︎ Retrieve broadly, fuse, rerank and pass the top-k“Perform initial retrieval to get the top potentially relevant chunks (we used the top 150);”
↩︎ Retrieve broadly, fuse, rerank and pass the top-k“There is an inherent trade-off between reranking more chunks for better performance vs. reranking fewer for lower latency and cost.”
↩︎ Retrieve broadly, fuse, rerank and pass the top-k“Response generation may be improved by passing it the contextualized chunk and distinguishing between what is context and what is the chunk.”
↩︎ Passing chunks to Claude as citable search results“We tried delivering 5, 10, and 20 chunks, and found using 20 to be the most performant of these options”
↩︎ Exam trap 2“We tried delivering 5, 10, and 20 chunks, and found using 20 to be the most performant of these options”
↩︎ Prediction“give each chunk a score based on its relevance and importance to the prompt, then select the top-K chunks”
↩︎ Checkpoint - 3.
“Pass@k checks whether or not the 'golden document' was present in the first k documents retrieved for each query.”
↩︎ Retrieve broadly, fuse, rerank and pass the top-k - 4.
“Any stable string works: a URL, or an internal identifier such as kb://article-1234”
↩︎ Passing chunks to Claude as citable search results“All active models support search results with citations, with the exception of Claude Haiku 3.”
↩︎ Passing chunks to Claude as citable search results“The following example forces the tool call with tool_choice, so the retrieval step runs every time.”
↩︎ Passing chunks to Claude as citable search results“Citations are disabled by default”
↩︎ Exam trap 1“Citations are disabled by default; every example on this page sets "enabled": true explicitly.”
↩︎ Checkpoint“cache_control | object | Cache control settings (for example, {"type": "ephemeral"})”
↩︎ Checkpoint - 5.
“Cache prefixes are created in the following order: tools, system, then messages.”
↩︎ Caching retrieved context that repeats across queries“Place static content (tool definitions, system instructions, context, examples) at the beginning of your prompt.”
↩︎ Caching retrieved context that repeats across queries“You can use just one cache breakpoint at the end of your static content, and the system will automatically find the longest prefix”
↩︎ Caching retrieved context that repeats across queries“You can use just one cache breakpoint at the end of your static content, and the system will automatically find the longest prefix”
↩︎ Exam trap 3