I ran into an issue when using AsyncPGVectorStore.asimilarity_search() where I was getting suboptimal results. Investigating the code, I found this logic:
|
# add fts_query to hybrid_search_config |
|
hybrid_search_config = kwargs.get( |
|
"hybrid_search_config", self.hybrid_search_config |
|
) |
|
if hybrid_search_config and not hybrid_search_config.fts_query: |
|
hybrid_search_config.fts_query = query |
|
kwargs["hybrid_search_config"] = hybrid_search_config |
When hybrid_search_config is not passed in via the kwargs, the value of the instance variable self.hybrid_search_config is used instead. If the value does not have an fts_query defined, it is set to the passed in query... mutating the value of the instance variable. This means all subsequent calls to asimilarity_search will use the same fts_query value as the very first call to asimilarity_search.
I think the fix here is to just make a copy of the value of the instance variable instead of using it directly.
I'm happy to provide a PR.
I ran into an issue when using
AsyncPGVectorStore.asimilarity_search()where I was getting suboptimal results. Investigating the code, I found this logic:langchain-postgres/langchain_postgres/v2/async_vectorstore.py
Lines 780 to 786 in 0f0394f
When hybrid_search_config is not passed in via the kwargs, the value of the instance variable self.hybrid_search_config is used instead. If the value does not have an fts_query defined, it is set to the passed in query... mutating the value of the instance variable. This means all subsequent calls to asimilarity_search will use the same fts_query value as the very first call to asimilarity_search.
I think the fix here is to just make a copy of the value of the instance variable instead of using it directly.
I'm happy to provide a PR.