Context Window Retrieval
A retriever matches small fragments, because small fragments match precisely. A reader needs more than a fragment to make sense of it. Context window retrieval is how those two facts are reconciled: match narrow, then hand the generator the surrounding text — as much of it as the window will take.
How it is doneEach chunk is stored with a pointer back to its neighbours in the original document. When a chunk wins the search, the system expands it — the sentences on either side, the full section, or the parent chunk it was split from — and passes the expanded version to the model. How many hits are admitted is then a budget calculation: the window has to hold the system prompt, the conversation, every expanded passage and the answer, so five richly expanded passages beat twenty bare ones.
Why it changes answers- A matched sentence carries pronouns and abbreviations whose referents sit in the sentence before it; without the neighbour, the model fills the gap by guessing.
- Expanding too far is its own failure — padding the window with loosely related text dilutes the evidence and pushes the useful part toward the middle, where models read least carefully.
- Tables, contract clauses and code break when split, so retrieval that returns one fragment of a table and nothing else produces confident nonsense.
LlamaIndex ships this as its sentence-window and auto-merging retrievers, and the same pattern goes by small-to-big. It is the cheapest fix available when a RAG system retrieves the right document and still answers badly.
Context window retrieval is retrieval governed by what the generator's context window can hold: matched chunks are expanded to their surrounding text — neighbouring sentences, the parent section — and admitted only as far as the token budget allows. It resolves the mismatch between small chunks, which match a query precisely, and larger passages, which a model can actually reason over. Over-expand and the evidence is diluted; under-expand and the model guesses at missing referents.
Imagine looking up a single line in a legal contract. The line you found says “this clause does not apply in that case” — useless on its own. You need the paragraph around it. Context window retrieval is the AI version of that instinct. The search finds the one line that matches your question, and then the system deliberately grabs the text on either side of it before handing anything to the assistant. It cannot grab everything, because an assistant can only read so much at once. So it is a judgement call: enough surrounding text to make the passage make sense, not so much that the point gets lost.