By Sagar Shankaran, Founder of CallSphere
End-to-end contextual retrieval for Claude agents: chunk enrichment, dual embedding plus BM25 indexes, rank fusion, and reranking before the model reads.
Key takeaways
Plain retrieval-augmented generation has an embarrassing failure mode: it chops a document into chunks, embeds each chunk in isolation, and then acts surprised when a chunk that says "the limit was raised to 50,000 in Q3" never surfaces for the query "what is the API rate limit?". The chunk lost the context that told you which API, which quarter, which environment. For a one-shot chatbot you might tolerate the miss. For an agent built on Claude that chains six tool calls off the first retrieval, one bad chunk poisons the whole trajectory.
Contextual retrieval is the architectural fix. Instead of storing raw chunks, you prepend a short, model-generated description that situates each chunk inside its parent document, then index that enriched text in both a semantic vector store and a lexical BM25 store. This post walks the full architecture — what each component does, how the pieces connect, and where Claude sits in the loop.
Standard chunking destroys reference. A 200-token slice from page 14 of a contract might read "Either party may terminate with 30 days notice." Embedded alone, that vector lives near every other termination clause on the internet. It does not know it belongs to the master services agreement with Acme, governed by New York law. So a query like "how do I cancel the Acme MSA?" pulls back a neighbor's lease instead.
The second, quieter problem is lexical. Embeddings are great at meaning and terrible at exact strings. Queries that hinge on an error code, a SKU, a function name, or a version number ("ERR_2041", "v4.6.2") need exact-match retrieval, which is precisely what BM25 gives you and dense vectors fumble. A serious architecture refuses to choose between the two.
Contextual retrieval is a technique that prepends each chunk with a short, LLM-generated explanation of how the chunk fits into its source document, then indexes the combined text for both semantic and keyword search. That single definition captures the whole design: enrich, then index twice.
Hear it before you finish reading
Talk to a live CallSphere AI voice agent in your browser — 60 seconds, no signup.
The pipeline splits cleanly into an offline indexing path and an online query path. Indexing happens once per document version; querying happens on every agent turn that needs grounding.
flowchart TD
A["Source document"] --> B["Split into chunks"]
B --> C["Claude Haiku writes chunk context (whole doc cached)"]
C --> D["Enriched chunk = context + original"]
D --> E["Embed into vector index"]
D --> F["Tokenize into BM25 index"]
G["Agent query"] --> H["Retrieve top-K from both indexes"]
E --> H
F --> H
H --> I["Rank fusion + rerank to top-N"]
I --> J["Claude reads N chunks & acts"]The left branch (A through F) is your batch job. The right branch (G through J) runs in milliseconds at request time. Keeping them separate matters: context generation is the expensive, latency-tolerant step, and you never want it on the hot path.
For each chunk, you send Claude the entire parent document plus the specific chunk, and ask for a terse situating sentence — not a summary of the chunk, but the context the chunk is missing. The output is something like "This clause is from the termination section of the Acme Master Services Agreement (2026), governed by New York law." You prepend that to the original chunk text before indexing.
CONTEXT_PROMPT = """<document>{full_document}</document>
Here is a chunk we want to situate within the whole document:
<chunk>{chunk_text}</chunk>
Give a short, standalone context (1-2 sentences) that says what
this chunk is about and where it sits in the document. Answer
with ONLY that context."""The economic trick is prompt caching. The full document is identical across every chunk in the same document, so you cache it once and pay the cheap cached-read rate for each subsequent chunk. With Haiku 4.5 as the writer, enriching a large knowledge base becomes a back-of-the-envelope rounding error rather than a budget line.
Each enriched chunk goes into two stores. The vector index (any standard embedding model) handles semantic similarity. The BM25 index handles exact lexical overlap. At query time you pull the top results from each — say top-20 semantic and top-20 lexical — then merge them.
The merge is usually reciprocal rank fusion: each document gets a score based on its rank position in each list, and you sum across lists. A chunk that ranks #2 semantically and #4 lexically beats one that ranks #1 in only a single list. This is deliberately rank-based, not score-based, so you do not have to normalize incompatible similarity scales.
| Stage | Wins at | Misses |
|---|---|---|
| Semantic only | Paraphrase, intent | Exact IDs, codes |
| BM25 only | Exact strings | Synonyms, meaning |
| Fused + context | Both | Very little |
Fusion gives you high recall — the right chunk is probably in your top-20. But an agent should not read 20 chunks; that wastes context window and dilutes attention. A cross-encoder reranker reads the query and each candidate together and produces a true relevance score, letting you cut from 20 candidates to the 5 the model actually consumes.
Still reading? Stop comparing — try CallSphere live.
CallSphere ships complete AI voice agents per industry — 14 tools for healthcare, 10 agents for real estate, 4 specialists for salons. See how it actually handles a call before you book a demo.
For Claude agents this is where architecture meets economics. Fewer, sharper chunks mean a tighter system prompt, less chance of the model anchoring on an irrelevant passage, and shorter tool-call chains downstream. The reranker is the difference between an agent that confidently answers from the right paragraph and one that hedges across five half-relevant ones.
It is worth naming why this ordering of stages is not arbitrary. Recall and precision pull in opposite directions, and the architecture deliberately maximizes each at the stage best suited to it. Fusion is a recall stage: cast a wide net so the right chunk is almost certainly somewhere in the candidate pool, accepting that the pool is noisy. Reranking is a precision stage: read each candidate against the query with a heavier model that you could never afford to run over the whole corpus, and trust it to surface the few that truly answer the question. Trying to collapse the two — using one model to do both wide search and precise ranking — either costs too much to run at corpus scale or is too blunt to separate the near-misses from the hits. Splitting them is what makes contextual retrieval both affordable and accurate at once.
No — they solve different problems. Fine-tuning changes how the model behaves; contextual retrieval changes what facts the model can see at inference. Most teams reach for retrieval first because it is cheaper, instantly updatable, and auditable.
Each chunk grows by 50–100 tokens. That modestly increases storage and embedding cost at index time, but it is a one-time cost and the recall gain dwarfs it. Query-time cost is unchanged because you still retrieve a fixed top-K.
Haiku 4.5. The task is short, well-specified, and runs over your entire corpus, so you want the cheapest capable model with prompt caching. Reserve Sonnet or Opus for the agent's reasoning, not for bulk enrichment.
CallSphere builds the same contextual-retrieval and multi-agent patterns into voice and chat assistants that answer every call, pull the right account detail mid-conversation, and book work around the clock. See it live at callsphere.ai.
Source & attribution: This is an independent, original explainer inspired by Anthropic's coverage on the Claude blog. Claude, Claude Code, Claude Cowork, Claude Opus, and the Model Context Protocol are products and trademarks of Anthropic. CallSphere is not affiliated with or endorsed by Anthropic.

Written by
Sagar Shankaran· Founder, CallSphere
LinkedInSagar Shankaran is the founder of CallSphere, where he builds production AI voice and chat agents deployed across healthcare, hospitality, real estate, and home services. He writes about agentic AI, LLM engineering, and shipping voice agents that handle real calls in production.
See how AI voice agents work for your industry. Live demo available -- no signup required.
Anthropic's Claude Fable 5 and Mythos 5 explained: pricing, availability, frontier benchmarks, the dual-model safeguard architecture, and what they mean for AI agents.
Where Claude Code, MCP, and multi-agent systems are taking GTM engineering next, and how to prepare your team now for standing and multi-agent workflows.
Where Claude Cowork and the Claude agent ecosystem are heading next — standing agents, MCP, skills as a moat — and the concrete moves to prepare your team now.
The metrics, leading signals, and anti-metrics that prove Claude Cowork is working — acceptance rate, time-to-outcome, and why usage counts mislead.
Shipping an agentic GTM workflow is easy; proving it works is hard. The metrics, signals, and eval loops that show a Claude Code rebuild is paying off.
A realistic end-to-end Claude Cowork use case: a quarterly vendor-spend review from vague ask to shipped deliverable, with every agentic step shown.
© 2026 CallSphere Inc. All rights reserved.
Made within San Francisco
Watch how CallSphere handles real customer calls, schedules appointments, and processes payments — live.
Try Live DemoBook a DemoCalculate Your ROI