perf: query the Document Store once in SentenceWindowRetriever - #12997
Merged
Merged
Conversation
SentenceWindowRetriever called filter_documents once per retrieved document. It now combines all windows into a single OR filter and assigns the returned documents to each window in memory. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
Contributor
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||
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.
Related Issues
SentenceWindowRetrievercalleddocument_store.filter_documents()(orfilter_documents_async()) once for every retrieved document. With atop_kof 10 upstream, one pipeline run sent 10 separate queries to the Document Store, which puts unnecessary load on backends like OpenSearch.Proposed Changes:
Now
run()andrun_async()send one query:source_idfields==,split_idbetweensplit_id ± window_size) for each retrieved document, drop duplicate conditions, and combine them into one{"operator": "OR", "conditions": [...]}filter.context_windows/context_documentsexactly as before.The output contract is unchanged.
The two private helpers
_retrieve_context_for_documentand_retrieve_context_for_document_asyncare replaced by shared sync/async helpers (_get_windows,_build_filters,_assemble_context), so the only sync/async difference left is the store call.How did you test it?
Load on the cluster now stays flat as
top_kgrows instead of rising with it.Notes for the reviewer
len(retrieved_documents) * (2 * window_size + 1)documents (70 fortop_k=10,window_size=3). This is well under the stores'filter_documentscaps (OpenSearch/Elasticsearchsize=10_000; Pinecone's 1000top_klimit is the tightest). It could matter only with very largetop_k×window_sizeon Pinecone.max_clause_count.split_idbeforemerge_documents_text). Whichever merges second needs a trivial rebase. With this PR the change becomesself.merge_documents_text(sorted_context_docs)inside_assemble_context.Checklist
fix:,feat:,build:,chore:,ci:,docs:,style:,refactor:,perf:,test:and added!in case the PR includes breaking changes.🤖 Generated with Claude Code