fix: don't mutate HybridSearchConfig during hybrid search - #338
Open
ankurjindal (ecomlisters) wants to merge 1 commit into
Open
ankurjindal (ecomlisters) wants to merge 1 commit into
ankurjindal (ecomlisters) wants to merge 1 commit into
Conversation
asimilarity_search and asimilarity_search_with_score stored the query in hybrid_search_config.fts_query, and __query_collection wrote fetch_top_k into hybrid_search_config.fusion_function_parameters. Both are the caller's objects, so after the first search every later search on the same store used the first query for the keyword half of hybrid search. Pass the query via kwargs["fts_query"] instead, and give the fusion function a copy of fusion_function_parameters with fetch_top_k set. An fts_query set explicitly in HybridSearchConfig still takes precedence.
This branch has not been deployed
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.
Fixes #337.
asimilarity_searchandasimilarity_search_with_scorestored the query inhybrid_search_config.fts_query, and__query_collectionwrotefetch_top_kintohybrid_search_config.fusion_function_parameters. Both are the caller's objects. Once the first search setfts_query, later searches on the same store used the first query for the keyword half of hybrid search.Changes
kwargs["fts_query"], which__query_collectionalready reads as a fallback, instead of assigning it to the config. Anfts_queryset explicitly inHybridSearchConfigstill takes precedence.fusion_function_parameterswithfetch_top_kset, and pass that to the fusion function instead of writing into the user's dict. The effectivefetch_top_kis unchanged (it is still the search'sk).Tests
Added to
tests/unit_tests/v2/test_async_pg_vectorstore_search.py, covering bothasimilarity_searchandasimilarity_search_with_score:fts_queryin the config still takes precedence.The first two fail on
mainand pass with this change.make test: 761 passed.make lintis clean.