Contextual retrieval vs GraphRAG: solving chunk fragmentation
Why chunking strips document context from RAG, and how contextual retrieval and GraphRAG restore it, with Anthropic's published failure-rate results.
Topics:RAG and retrieval
The most common point of failure in enterprise Retrieval-Augmented Generation (RAG) is not the embedding model or vector database; it is chunk fragmentation. When an ingestion pipeline splits a 50-page technical specification or financial SEC filing into 500-token chunks, standalone passages lose their broader document context. A chunk stating "revenue grew by 14% to $3.2B in the third quarter" fails to retrieve when a user asks "How did Acme Corp perform in Q3?", because the company name only appeared on page one.
TL;DR
Chunk fragmentation strips semantic context from isolated text segments, so relevant passages fail to retrieve. Two primary architectures have emerged to solve this: Anthropic's Contextual Retrieval, which prepends an LLM-generated document summary to every chunk before embedding and BM25 indexing, and Microsoft's GraphRAG, which extracts entity-relationship knowledge graphs and community summaries. In Anthropic's published tests, Contextual Retrieval cut the top-20 retrieval failure rate by 49%, and by 67% with reranking added, while GraphRAG excels at high-level thematic queries spanning thousands of disparate documents.
The root cause of chunk fragmentation
In traditional RAG pipelines, text splitters divide documents using sliding character windows (e.g., 512 tokens with a 64-token overlap). While this preserves sentence structures, it obliterates global context:
1. Entity Anaphora: Pronouns like "the company", "the system", or "the patient" lose their antecedents. 2. Missing Temporal Anchors: Dates and fiscal years stated in table headers disappear in subsequent page splits. 3. Implicit Scope Loss: Section titles, governing jurisdictions, and safety disclaimers do not propagate down to sub-clauses.
When dense vector models embed these isolated fragments, the resulting embeddings cluster near generic concepts rather than the specific entities the user is searching for.
- Fewer retrieval failures with Contextual Embeddings alone (5.7% down to 3.7%)
- 35%
- Anthropic, Introducing Contextual Retrieval, September 2024
- Fewer retrieval failures with Contextual Embeddings and Contextual BM25 together (5.7% down to 2.9%)
- 49%
- Same Anthropic article
- Fewer retrieval failures when reranking is added on top (5.7% down to 1.9%)
- 67%
- Same Anthropic article
These are Anthropic's figures on its own test sets, measured as 1 minus recall@20. We have not reproduced them. The GraphRAG paper reports substantial improvements over a conventional RAG baseline in the comprehensiveness and diversity of answers to corpus-wide questions. It measures something different, so the two sets of results cannot be compared directly.
Architecture 1: Anthropic Contextual Retrieval
Anthropic's Contextual Retrieval directly repairs chunk fragmentation at ingestion time without introducing a complex graph database. During preprocessing, an automated prompt instructs a fast foundation model to read the entire parent document alongside each individual chunk, generating a concise 50-to-100 token contextual prefix that situates the chunk within the document.
Step 1: 1. Full document ingestion
Load parent document and split into raw semantic chunks (approx. 300–500 tokens).
Step 2: 2. Contextual prefix synthesis
Fast LLM (e.g., Claude 3.5 Haiku) generates an explanatory prefix situating the chunk within the parent document.
Step 3: 3. Prepend and tokenize
Concatenate the synthesized prefix to the chunk:
[Prefix] + \n\n + [Original Chunk Content].Step 4: 4. Dual index generation
Generate dense vector embeddings for the augmented chunk and index into a BM25 inverted lexical index.
Step 5: 5. Hybrid retrieval and reranking
Query both vector and BM25 indices simultaneously, merge results with Reciprocal Rank Fusion, and rerank with Cohere or BGE.
-- Example Chunk Transformation --
Original Fragment:
"The operating margin expanded by 240 basis points to 18.2%, primarily driven by
operational efficiencies in logistics and decreased customer acquisition costs."
Contextual Augmented Chunk:
"This chunk is from Acme Technologies Inc.'s Q3 2025 financial earnings report,
discussing the enterprise cloud software division's quarterly profitability metrics:
The operating margin expanded by 240 basis points to 18.2%, primarily driven by
operational efficiencies in logistics and decreased customer acquisition costs."By prepending the company name, fiscal period, and document topic, both semantic vector search and exact BM25 keyword matching can locate the fragment instantly.
# Contextual Prefix Generation Pipeline
import anthropic
client = anthropic.Anthropic()
PROMPT_TEMPLATE = """
<document>
{full_document}
</document>
Here is the chunk we want to situate within the whole document:
<chunk>
{chunk_content}
</chunk>
Please give a short, succinct context to situate this chunk within the overall document
for the purposes of improving search retrieval. Answer in 1-2 sentences. Do not mention "this chunk".
"""
def generate_contextual_prefix(full_doc: str, chunk: str) -> str:
response = client.messages.create(
model="claude-3-5-haiku-20241022",
max_tokens=100,
temperature=0.0,
messages=[{
"role": "user",
"content": PROMPT_TEMPLATE.format(full_document=full_doc, chunk_content=chunk)
}]
)
return response.content[0].text.strip()Architecture 2: Microsoft GraphRAG
While Contextual Retrieval excels at targeted search ("What was Acme's margin in Q3?"), it struggles with holistic, corpus-wide synthesis questions like "What are the primary risk factors mentioned across all 500 supplier audits?". Traditional vector search cannot answer this because the answer does not reside in any single chunk; it requires synthesizing themes distributed across hundreds of documents.
Microsoft's GraphRAG solves this by converting unstructured text into a knowledge graph: - Entity & Relationship Extraction: An LLM scans chunks to extract named entities (people, organizations, concepts) and their relationships. - Graph Clustering (Leiden Algorithm): Partitions the entity graph into hierarchical communities of related concepts. - Community Summaries: Pre-generates executive summaries for every community cluster, allowing top-down global query answering.
Contextual Retrieval (Anthropic)
- Primary Strength: Precise factual lookup and narrow question-answering.
- Index Overhead: Low to moderate (one fast LLM call per chunk).
- Storage Backend: Standard vector database (pgvector, Pinecone, Qdrant) + BM25.
- Query Latency: Low: one vector search, one BM25 search and a rerank.
- Best For: Technical manuals, enterprise policies, customer support, and API documentation.
GraphRAG (Microsoft)
- Primary Strength: Global aggregation, thematic summarization, and multi-hop relationship reasoning.
- Index Overhead: Very high (dozens of LLM extraction and clustering passes).
- Storage Backend: Graph database (Neo4j, Memgraph) + vector store + community index.
- Query Latency: Higher for global questions, which are answered from many community summaries.
- Best For: Fraud investigation, research literature synthesis, intelligence analysis, and risk discovery.
Ingestion cost analysis and operational overhead
Before choosing between Contextual Retrieval and GraphRAG, engineering teams must evaluate indexing budgets and query SLAs.
Before (Standard Chunks)
- Chunks are embedded exactly as they were split.
- Top-20 retrieval failure rate in Anthropic's tests: 5.7%.
- Ingestion cost: embedding calls only.
- Failure mode: Misses chunks where key entities are implied rather than stated.
After (Contextual Embeddings, Contextual BM25 and Reranking)
- Each chunk gets a short generated prefix before embedding and BM25 indexing.
- Top-20 retrieval failure rate in Anthropic's tests: 2.9%, or 1.9% with reranking.
- One-time cost to generate the prefixes with prompt caching: $1.02 per million document tokens, on Anthropic's assumptions (800-token chunks, 8k-token documents, 100 tokens of context per chunk).
- Caveat: these figures come from Anthropic's test sets. Measure on your own corpus before relying on them.
GraphRAG indexing costs substantially more than Contextual Retrieval, because of repeated entity extraction, entity deduplication, graph clustering passes, and hierarchical summary generation. We do not have a sourced multiple for the difference, so price both on a sample of your own documents.
Selecting the right retrieval pattern
Align your retrieval architecture with the dominant query patterns of your end users.
If
Factual lookups over structured/unstructured docs
Choose
Contextual Retrieval + Hybrid BM25 + Reranking
Because
Low query latency; cheaper ingestion
If
Multi-hop relationship tracing across datasets
Choose
GraphRAG with local community exploration
Because
Traverses entity edges; connects disparate facts
If
Corpus-level thematic analysis ("What trends exist?")
Choose
GraphRAG global search with pre-computed summaries
Because
Aggregates across thousands of documents simultaneously
Frequently asked questions
What is chunk fragmentation in RAG? Chunk fragmentation occurs when large documents are divided into arbitrary token segments, causing individual chunks to lose essential parent context like document titles, authors, dates, and entity definitions that only appeared earlier in the document.
How does contextual retrieval differ from metadata filtering?
Metadata filtering applies discrete SQL or vector filters (such as department = 'legal'), which requires predefined schemas and exact matches. Contextual Retrieval injects rich natural language context directly into the text, allowing dense vector search and BM25 lexical search to match nuanced, unstructured queries automatically.
Does contextual retrieval increase embedding storage costs? Slightly. Adding a 50-to-100 token prefix to a 400-token chunk increases the token length of each chunk by about 12% to 25%, resulting in a proportional increase in vector database storage and indexing time, but vector dimension sizes remain identical.
Can I use prompt caching to reduce contextual retrieval ingestion costs? Yes. Because the parent document remains constant while generating prefixes for dozens of sequential chunks, caching the parent document means it is billed at the cache-read rate on every chunk after the first. Anthropic bills cache reads at 0.1x the base input price on most Claude models, and puts the one-time cost of generating the prefixes at $1.02 per million document tokens.
When is GraphRAG worth the added infrastructure complexity? GraphRAG is worth the investment when users ask broad questions that require aggregating information from across the entire document collection (e.g., "Summarize all legal risks identified in our contracts") rather than finding a specific paragraph or clause.
What is the role of reranking in contextual retrieval? A cross-encoder reranker (such as Cohere Rerank or BGE Reranker) evaluates the query and retrieved contextual chunks together, scoring semantic relevance with deeper attention layers to ensure only the most authoritative chunks reach the final LLM context window.
Related
Sources
- Introducing Contextual Retrieval (Anthropic Research, 2024)
- From Local to Global: A Graph RAG Approach to Query-Focused Summarization (Edge et al., Microsoft Research, 2024)
- Reciprocal Rank Fusion Outperforms Condorcet and Individual Rank Learning Methods (Cormack et al., SIGIR)
- Dense Passage Retrieval for Open-Domain Question Answering (Karpukhin et al., 2020)
RAG and retrieval
Your next step
Reading is the start. Turn it into skill: read the chapter, practise on something real, check the numbers, then follow a path.
More on RAG and retrieval
- Why good retrieval still produces bad answersDebug RAG failures with a runnable Python exercise that separates retrieval misses, dropped evidence, unsupported claims and incorrect refusals.
- Embeddings and vector search, explained for engineersHow embeddings and vector search work: similarity, nearest-neighbour indexes, filters, hybrid search and the version trap, explained step by step for engineers.
- Production RAG architecture: a practical guideThe full production RAG architecture: ingestion, chunking, embeddings, hybrid search, reranking, generation, evaluation and observability, with code.
Discuss this article
Got a question, a counter-example or a correction? Bring it to the community.
Prefer a feed reader? Follow by RSS.