Skip to content

Instance variable hybrid_search_config‎ incorrectly mutated #288

@johntrimble

Description

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions