Glossary
Sentence window retrieval
A retrieval technique that matches single sentences and returns each match with the sentences around it.
Sentence window retrieval is a technique used in RAG systems that indexes a document one sentence at a time and, when a sentence matches a query, returns it together with a few sentences on either side. The single sentence gives a sharp embedding for matching. The window around it gives the model enough text to read the answer in context.
How sentence window retrieval works
At indexing time a text splitter breaks each document into sentences rather than fixed-size chunks. Each sentence is embedded on its own and stored in a vector store, and next to it the system saves a window: the sentence plus a set number of sentences before and after it, usually kept as metadata. At query time the retriever compares the query with the sentence embeddings, takes the best matches and swaps each matched sentence for its window before the text goes into the prompt.
LlamaIndex made the pattern widely known with a sentence window node parser, which stores the window in each node’s metadata, and a postprocessor that replaces the sentence with that window after retrieval. Its examples use three sentences on each side. LangChain vs LlamaIndex compares the two main frameworks, and Exabase vs LlamaIndex covers where a managed search layer fits.
Why match on sentences
Most chunking strategies ask one size to do two jobs. A long chunk averages several ideas into one vector, so it matches specific questions weakly, and a short chunk matches well but often leaves out the text needed to answer. Matching on one sentence and expanding it afterwards adds the surrounding text back without diluting the vector that did the matching. Chunk overlap softens the same problem at fixed boundaries, while a sentence window is centred on wherever the match lands. Chunking is a workaround, not a design makes the wider case.
Choosing a window size
The window size is the main setting. One or two sentences on each side keeps requests short and suits factual lookups, and three to five suits explanations that build over a paragraph. Larger windows start to behave like parent document retrieval, with more tokens per result and a greater chance of pulling in unrelated text. Test a few sizes against a small set of real questions with known answers, using measures such as context precision and faithfulness.
Sentence window retrieval compared
Technique | Unit searched | Unit returned | Main cost |
|---|---|---|---|
Sentence window retrieval | Single sentence | Sentence plus neighbours | Many small vectors, window size to tune |
Parent document retrieval | Small child chunk | Parent section or document | More tokens per result |
Fixed-size chunking | Chunk | The same chunk | One size for matching and context |
Semantic chunking | Topic-shaped chunk | The same chunk | Embedding calls to find boundaries |
Contextual retrieval | Chunk with added context | The same chunk | A model call per chunk at indexing |
Semantic chunking and recursive chunking change where chunks are cut, and fixed size vs semantic chunking compares the two most common methods. Contextual retrieval and late chunking put document context into each chunk’s vector instead. Sub-document retrieval locates the answering passage at query time.
Trade-offs
Indexing every sentence multiplies the number of vectors, often by ten or more for prose, which raises storage costs and the work in each re-indexing run. Short sentences such as headings or list items embed poorly on their own and can match too easily. Neighbouring matches return overlapping windows, so merge them or apply deduplication before building the prompt. Sentence splitting also struggles with tables, code and scanned layouts, where a sentence is not a meaningful unit.
Several wide windows in one prompt can bury the useful sentence, the lost in the middle effect. Top-k is the wrong default explains why a fixed number of results is a weak setting on its own.
Sentence window retrieval and Exabase
Deep Search indexes content stored as Resources when it is written, with no chunking logic to build or tune, and returns each hit with its matched chunks, relevance scores and page numbers or timestamp ranges. Exabase works at the chunk and passage level, with no sentence index or window-size setting, so a sentence window pipeline would sit on top. The searching resources guide covers filters and the precision setting.
If you run your own retriever on Extract output, each chunk carries a sequence number with its page number or timestamps, so a window can be widened by fetching neighbouring chunks through the chunks endpoint, which takes start and end positions. The RAG pipelines use case shows a full pipeline, and RAG accuracy covers why the passage that contains the fact matters more than the one that looks similar.
FAQs
What is sentence window retrieval?
Sentence window retrieval embeds and searches single sentences, then returns each matching sentence with a fixed number of neighbouring sentences so the model reads it in context.
What window size should I use?
Start with two or three sentences on each side and adjust against real questions. Smaller windows save tokens, and larger ones help when answers span a paragraph.
How is sentence window retrieval different from parent document retrieval?
Both search small units and return more text. Sentence window retrieval returns a window centred on the matched sentence, while parent document retrieval returns a predefined section or document.
Does sentence window retrieval work with hybrid search?
Yes. The sentence index can be searched with hybrid search that pairs BM25 with vector similarity, and windows are attached after the results are merged.
Is sentence window retrieval worth it for short documents?
Often not. If the documents fit comfortably in the context window, passing them whole can be simpler, and RAG vs long context covers that choice.
Does Exabase support sentence window retrieval?
Not as a built-in setting. Deep Search returns sub-document chunks with page numbers or timestamps, and Extract chunks carry sequence numbers, so your application can widen a match by fetching its neighbours.
Related pages: Parent document retrieval, Contextual retrieval, Chunking, Chunk overlap, Semantic chunking, Sub-document retrieval, Retriever, Late chunking, Deep Search, RAG accuracy.