A retrieval-augmented generation (RAG) pipeline can only answer from what it retrieves, and what it can retrieve was decided at ingestion time, when nobody was looking at a user's question. Chunking and indexing choices therefore set a ceiling on answer quality that no prompt or model change can lift. First decide whether you need RAG at all: Anthropic's Contextual Retrieval post suggests that a knowledge base under about 200,000 tokens (roughly 500 pages) can simply be placed in the prompt with prompt caching. That figure is from the post, so re-check it against current context limits and caching behaviour. Retrieval strategy is Lesson 1.6; this lesson covers ingestion, chunking and indexing.
From raw documents to an index
- Parse and clean. Extract text with its structure (headings, tables, code), strip boilerplate, and dedupe near-duplicate documents. Scanned PDFs need OCR first; note that Claude's citations feature cannot cite a PDF that has no extractable text.
- Chunk along meaningful boundaries (next section).
- Enrich. Attach metadata: source ID, title, section path, version or date, language, and the access-control or tenant attributes that retrieval will filter on. Optionally add generated context (below).
- Embed. Anthropic does not offer its own embedding model; its docs point to Voyage AI and recommend setting
input_typeto distinguish documents from queries. Vectors from different models or dimensions are not comparable, so changing embedding model means re-embedding the whole corpus. - Index. Store chunk text and metadata with the vectors, and add a keyword (BM25) index if you plan hybrid retrieval.
- Keep it fresh. Update incrementally by document ID and content hash, delete or tombstone removed documents, version them, and set a staleness target you can monitor.
Chunking decisions and their trade-offs
| Decision | Risk if too small or absent | Risk if too large or heavy |
|---|---|---|
| Chunk size | Chunks lose the context to be interpretable, and answers span several chunks | Embeddings blur several topics, tokens are wasted, and the answer is buried |
| Boundaries | Fixed-size cuts split sentences, tables and functions | Whole documents as chunks defeat precision |
| Overlap | Facts at a boundary are lost | Duplicated content inflates the index and fills top-k with near-copies |
| Metadata | No filtering, no attribution, no freshness signals | Inconsistent fields that nothing uses |
Prefer structure-aware boundaries (headings, paragraphs, table rows with their headers, code functions) over fixed token counts, and treat overlap as a patch rather than a design. A common pattern is parent-child chunking: match on small chunks for precision, then pass the enclosing section to the model for context.
The context problem has a documented fix. Anthropic's Contextual Retrieval prepends a short, chunk-specific explanation (typically 50–100 tokens) generated by Claude to each chunk before embedding and BM25 indexing, so "revenue grew by 3% over the previous quarter" becomes attributable to a company and period. In Anthropic's experiments, top-20 retrieval failure fell from 5.7% to 3.7% with contextual embeddings, 2.9% when combined with contextual BM25, and 1.9% with reranking. Those are results on their datasets; measure yours. Prompt caching keeps per-chunk generation affordable because the document is reused, and the embeddings docs also list Voyage models that produce contextualised chunk embeddings without manual augmentation.
Key concept: retrieval is the ceiling
If the evidence is not in the retrieved set, generation cannot recover it. Evaluate retrieval separately: for a labelled set of questions, is the gold chunk in the top-k? When it is not, the problem is chunking, indexing or retrieval, and swapping the generation model will not help.
Citations: making chunks attributable
Claude's citations feature grounds answers in your documents. You set citations: {enabled: true} on document blocks; plain text and PDFs are automatically chunked into sentences, while custom content documents use your content blocks as-is with no further chunking. Anthropic's guidance for RAG is to put each chunk in a plain-text document if you want sentence-level citations, or use custom content if you want to control granularity. Citations come back as char_location, page_location or content_block_location objects with a cited_text field that does not count toward output tokens. Constraints: citations must be enabled on all or none of the documents in a request, and combining them with structured outputs returns a 400 error.
For tool-based retrieval, search_result blocks (with source, title, content and citations) can be returned from a tool or supplied as top-level content, and Claude cites them automatically. In a tool result, if any block is a search_result then all must be. The design consequence: your chunk boundaries and stable source identifiers decide citation granularity and what a user can verify.
How chunking failures show up
| Symptom | Likely cause | Direction of fix |
|---|---|---|
| Right topic, wrong document or entity | Chunk lacks its context ("the company", "Section 4.2") | Contextual enrichment; prepend title and section path |
| Partial or wrong answers where facts sit in adjacent chunks | Boundary splits, chunks too small | Structure-aware boundaries; parent-child |
| The right chunk exists but is never retrieved | Diluted large chunks, low top-k, or an exact-term miss | Smaller chunks; rerank; hybrid retrieval (Lesson 1.6) |
| Top-k full of near-duplicates | Heavy overlap, duplicated sources | Dedupe; reduce overlap |
| Wrong numbers from tables | Table split, headers lost | Keep tables whole or repeat headers |
| Outdated answers | No update or delete path | Incremental re-index, versions, freshness metadata |
| Users see content they should not | Access metadata missing or applied after retrieval | Filter at retrieval by the user's entitlements (Lesson 1.2) |
Common exam distractor
"Larger context windows make chunking irrelevant" ignores cost, latency and dilution. "Increase chunk size to restore missing context" blurs embeddings without adding document-level context; enrichment does that. "Generate embeddings with Claude" is wrong because Anthropic offers no embedding model. And "switch to a bigger generation model" is the classic wrong-layer fix when the gold chunk was never retrieved.