Fix: query expander duplicate queries#12035
Merged
sjrl merged 4 commits intoJul 20, 2026
Merged
Conversation
|
@aquib8112 is attempting to deploy a commit to the deepset Team on Vercel. A member of the Team first needs to authorize it. |
sjrl
reviewed
Jul 20, 2026
sjrl
reviewed
Jul 20, 2026
Contributor
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||||||||||||||
Contributor
Author
|
Hey @sjrl, thank you for the feedback! I have removed the case-insensitivity logic and moved the async tests to |
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
Proposed Changes:
QueryExpandercould return duplicate queries when the chat generator repeated an expansion._parse_expanded_querieskept every non-empty string from the response, and the post-processing inrun/run_asynconly checked whether the original query was already present. That check is a guard against appending the original twice, not deduplication, despite a comment claiming otherwise. Duplicates among the generated expansions were passed straight through.Downstream, each duplicate makes
MultiQueryTextRetrieverandMultiQueryEmbeddingRetrieverrun another retrieval for the same query, adding latency and backend load while reducing the number of distinct expansions.Generated queries are now deduplicated in
_parse_expanded_queries, preserving first-seen order. The inaccurate comment was removed from both methods.Two notes on the approach:
_parse_expanded_queriesbecause bothrunandrun_asyncalready call it, so both paths are fixed by one change and cannot drift apart again. The method already strips whitespace and drops empty or non-string entries, so it normalizes the response rather than merely parsing it.n_expansions=3and a response of["a", "a", "b", "c"], truncating first yields["a", "b"], while deduplicating first yields["a", "b", "c"].Deduplication can leave fewer than
n_expansionsqueries. This matches the documented contract, since the class docstring already describes the output as "up to" N additional queries, and no existing test changes behaviour.How did you test it?
Four unit tests added next to the existing
test_run_query_deduplication, covering both the sync and async paths:["a", "a", "b", "c"]withn_expansions=3returns three queries, not two)All four fail on
mainand pass with this change. Full file: 47 passed, 3 skipped.Also verified manually that the reproduction snippet from the issue now returns
{'queries': ['same query', 'other query']}on bothrunandrun_async.Notes for the reviewer
_post_process_querieshelper on the component instead, if you would prefer the parser to stay purely a parser. Kept the diff minimal here.Checklist
Disclaimer: This PR was assisted by AI. I have reviewed the changes and run the relevant tests.