RAG
Contextual chunk headers
Prepend a short description of where a chunk comes from before embedding and indexing it.
What it is and why it exists
A chunk like “Limits go up to 1,000 per minute” is ambiguous alone. Prefixing it with document title, section path or an LLM-written one-line context (“From the API docs, section Rate limits for the Enterprise plan”) makes both dense and keyword retrieval far more accurate.
Quick prototype
Prepend “Title > Section”.
In production, at scale
Generate a context line per chunk once at ingest (cache the full document in the prompt so it’s cheap), embed and index the context + chunk, but show only the original chunk in citations.
Vendors and tools
| Anthropic “contextual retrieval” | Published method and measured gains |
|---|---|
| LlamaIndex / LangChain | Metadata and title extractors |
How it fails
- Ingest cost explodes when every chunk needs a full-document LLM call without caching
What the interviewer asks next
Why does this help BM25 too?
The added words (product name, section) now appear in the chunk text, so keyword search can match them.