Back to catalog / Retrieval
Add document context to chunks before indexing
Generate a short contextual description for each chunk and embed it with the original text to improve retrieval of context-poor passages.
Goal
Make indexed chunks retrievable for domain questions even when separated from their full document.
Steps
- Retain each chunk’s heading, text, and document-level context as in the contextual-retrieval notebook. [contextual]
- Ask Claude for a context description per chunk, then embed
context + chunkwith Voyage into the vector index. [contextual] - Compare retrieval against the chunk-only index on the same gold questions and record context/embedding versions. [contextual]
How to verify
The contextual index improves retrieval for at least one low-recall case while preserving original-source links and reproducibility.
Troubleshooting
If a description adds unsupported facts, reject that enrichment and use a short description grounded in the source document.
Permissions
Prerequisites
- Python, Anthropic/Voyage API keys, authorized corpus, and an existing baseline RAG index.
Permissions
- Send only authorized chunks to the model; do not reuse sensitive descriptions across documents.
Limitations
Generated descriptions add indexing cost and may introduce bias; retain original chunks and provenance—summaries do not replace source text.
Pinned upstream source
- Repository
- anthropics/anthropic-cookbook
- File path
- capabilities/contextual-embeddings/guide.ipynb
- Pinned commit
9c1e493ddd2b82df399d2a61b9c806c539e18be6- Source checked
- 2026-10-14 · Reviewed against the pinned upstream source
Repository metrics
These values describe the upstream repository, not popularity or likes for an individual skill or playbook.
- Stars
- Not collected
- Forks
- Not collected
- Observed at
- Not collected
No metrics snapshot is available yet.
License: MIT
Main topic
Take a coding Agent change from context to verification