Skip to content

Hybrid search mutates the caller's HybridSearchConfig, so later searches reuse the first query for keyword search #337

Description

AsyncPGVectorStore.asimilarity_search and asimilarity_search_with_score write into the HybridSearchConfig they are given, whether it was passed to the store or per call:

if hybrid_search_config and not hybrid_search_config.fts_query:
    hybrid_search_config.fts_query = query

After the first search, fts_query is no longer empty, so every later search on the same store skips this branch and keeps running keyword search with the first query's text. The vector half uses the new query while the keyword half stays stuck on the old one, and nothing reports an error.

__query_collection has the same problem with fusion_function_parameters:

hybrid_search_config.fusion_function_parameters["fetch_top_k"] = final_k

This overwrites the user's dict. A configured fetch_top_k gets replaced by whatever k the last search used.

Reproduce

store = await AsyncPGVectorStore.create(..., hybrid_search_config=HybridSearchConfig(tsv_column="content_tsv"))
await store.asimilarity_search("apple", k=2)
store.hybrid_search_config.fts_query                    # 'apple'
store.hybrid_search_config.fusion_function_parameters   # {'fetch_top_k': 2}
await store.asimilarity_search("orange", k=2)           # keyword half still searches for "apple"

Expected: each search uses its own query for keyword search, and the config object is left as the user created it. An fts_query set explicitly in the config should still take precedence.

Separate follow-up, not addressed here: AsyncPGVectorStore.create() also mutates the config, setting hybrid_search_config.tsv_column = "" when the TSV column is missing from the table.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions