Chunking has a quiet flaw. Cutting a document into pieces also cuts each piece off from the thing that made it meaningful. A chunk reading:
is nearly unretrievable. Which company? Which quarter? A query like "how did Acme do in Q2 2026" will not match it, because none of those words are in the chunk. The information was in the document; chunking threw it away.
Restoring what chunking removed
Before embedding, generate a sentence or two situating the chunk in its parent document, and prepend it:
const context = await summarise(`
Document: ${doc.title}
Write one sentence situating this excerpt in the document.
Excerpt: ${chunk}
`)
const embedded = `${context}\n\n${chunk}` // embed this, not the bare chunkThe stored chunk becomes:
Now the query matches, because the words the query uses are finally present.
The cost, and why it is usually worth paying
You pay one extra model call per chunk at index time. That is a one-off, offline cost, and it buys better retrieval on every query forever after. It is one of the rare cases where the expensive thing happens where nobody is waiting for it.
- Keep the generated context short. Two sentences. You are adding retrieval handles, not summarising.
- Generate it from the whole document, or at least surrounding sections, or the model has no more context than the chunk did.
- Prepend it to the text you embed and to the text you index for keyword matching, so hybrid search benefits too.
Related terms
Chunking
Chunking is splitting a long document into smaller pieces before you embed and retrieve them. The size and overlap of the chunks decide what can be found as a unit, so it quietly makes or breaks a retrieval system.
Read definition →ConceptEmbeddings
An embedding turns a piece of text into a list of numbers that captures its meaning, so that similar ideas land near each other. Embeddings are what let you search by meaning instead of by exact keyword.
Read definition →PatternProvenRetrieval-augmented generation (RAG)
RAG is the workhorse pattern of context engineering: retrieve the material relevant to a request, put it in the context, and let the model generate an answer grounded in it rather than guessing from memory.
Read definition →PatternValidatedHybrid search
Hybrid search runs a keyword search and a vector search over the same corpus and merges the two result lists. It exists because embeddings are good at meaning and bad at exact strings, and keyword search is the other way round.
Read definition →