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.
AsyncPGVectorStore.asimilarity_searchandasimilarity_search_with_scorewrite into theHybridSearchConfigthey are given, whether it was passed to the store or per call:After the first search,
fts_queryis 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_collectionhas the same problem withfusion_function_parameters:This overwrites the user's dict. A configured
fetch_top_kgets replaced by whateverkthe last search used.Reproduce
Expected: each search uses its own query for keyword search, and the config object is left as the user created it. An
fts_queryset explicitly in the config should still take precedence.Separate follow-up, not addressed here:
AsyncPGVectorStore.create()also mutates the config, settinghybrid_search_config.tsv_column = ""when the TSV column is missing from the table.