Agent Wealth HubFree public resources
中文 EN العربية

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

  1. Retain each chunk’s heading, text, and document-level context as in the contextual-retrieval notebook. [contextual]
  2. Ask Claude for a context description per chunk, then embed context + chunk with Voyage into the vector index. [contextual]
  3. 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

Permissions

Limitations

Generated descriptions add indexing cost and may introduce bias; retain original chunks and provenance—summaries do not replace source text.

Pinned upstream source

https://github.com/anthropics/anthropic-cookbook/blob/9c1e493ddd2b82df399d2a61b9c806c539e18be6/capabilities/contextual-embeddings/guide.ipynb

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

Related resources