Implement document expansion to improve RAG performance - #1
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds V1 document expansion after fused retrieval and before reranking. This helps the pipeline recover useful same-document context when retrieval finds the right source document but misses the most answer-bearing chunk.
The feature uses a route planner instead of a single expansion path:
doc_id + chunk_index, supported across all chunking strategies.section_pathmetadata is available.Summary.Why
Some multi-hop or field-style questions failed because retrieval identified the correct document but selected a nearby or related chunk instead of the chunk containing the key fact. For example, an athlete profile’s “Career Progression” chunk might be retrieved, while the “Summary” chunk contains the home resort.
Document expansion gives the reranker and generator a better candidate pool without requiring a broader initial retrieval sweep.
Implementation Notes
get_by_doc_id()support to the vector store protocol and Chroma backend.src/retrieval/document_expansion.pyfor planning and applying expansion requests.RAGPipelineafter fused retrieval and before rerank.document_expansionconfig defaults.document_expansion_added.Test Plan
uv run ruff check src/retrieval/document_expansion.py src/vectorstore/protocol.py src/vectorstore/chroma_store.py src/pipeline/rag_pipeline.py src/pipeline/models.py src/pipeline/trace.py src/config/loader.py src/evaluation/config_merge.py tests/test_document_expansion.py tests/test_vectorstore.py tests/test_config_merge.pyuv run pytest tests/test_document_expansion.py tests/test_vectorstore.py tests/test_config_merge.py tests/test_pipeline.pyuv run pytestAll tests passed:
143 passed, 2 deselected.