name: contextual-chunk-expansion-window description: Expands retrieved vector chunks with adjacent sliding window text sentences before LLM generation. Use when retrieved chunks cut off sentences or lack surrounding context. license: MIT metadata: author: Community List Maintainers version: "1.0.0" source: "https://python.langchain.com/docs/how_to/parent_document_retriever/"
Contextual Chunk Expansion Window
Overview
Arbitrary chunk boundaries frequently bisect key explanations or pronouns. Contextual chunk expansion dynamically fetches k-sentences before and after the matched chunk from the source text.
Operational Workflow
Index standard document chunks maintaining document sentence index offset metadata.:
- Index standard document chunks maintaining document sentence index offset metadata.
Retrieve top candidate chunks via semantic vector similarity or keyword search.:
- Retrieve top candidate chunks via semantic vector similarity or keyword search.
Look up sentence offsets and retrieve adjacent surrounding sentence buffer (window size:
- Look up sentence offsets and retrieve adjacent surrounding sentence buffer (window size: 2–3).
Merge adjacent overlapping chunks into unified coherent passage blocks for prompt synthesis.:
- Merge adjacent overlapping chunks into unified coherent passage blocks for prompt synthesis.
Recommended Tools & Environments
- Sliding Window
- Contextual Expansion
- LangChain
- Text Processing
Verification & Execution Criteria
- Pre-execution validation verifies all prerequisites and inputs.
- Step-by-step progress logging confirms intermediate state transitions.
- Post-execution checks verify output integrity and clean exit codes.