kwargs chain is broken in PGVector's search methods #53

Open
opened 2026-02-16 05:16:19 -05:00 by yindo · 0 comments
Owner

Originally created by @Voileexperiments on GitHub (Oct 27, 2024).

VectorStoreRetriever supports passing arbitrary parameters into the underlying VectorStore through search_kwargs. Similarly, base VectorStore methods pass kwargs through its inner methods; see this.

However, this is not done properly in the PGVector methods: similarity_search, similarity_search_with_score and max_marginal_relevance_search_with_score_by_vector breaks the kwargs chain, hence any additional named parameters are lost upon building the query.

As example, please look at similarity_search_with_score in base VectorStore and PGVector: the former pass kwargs into the inner method as expected, while the latter isn't.

This has important impacts as kwargs is typically used to pass additional params into inner methods to enable customizability. For example, if I want to customize a query to join other tables, I should be able to just inherit PGVector, override __query_collection and provide my custom query building logic. However, this would not be possible if kwargs is not passed through the search methods.

Originally created by @Voileexperiments on GitHub (Oct 27, 2024). `VectorStoreRetriever` supports passing arbitrary parameters into the underlying `VectorStore` through `search_kwargs`. Similarly, base `VectorStore` methods pass `kwargs` through its inner methods; see [this](https://python.langchain.com/api_reference/_modules/langchain_core/vectorstores/base.html). However, this is not done properly in the [`PGVector` methods](https://python.langchain.com/api_reference/_modules/langchain_postgres/vectorstores.html): `similarity_search`, `similarity_search_with_score` and `max_marginal_relevance_search_with_score_by_vector` breaks the `kwargs` chain, hence any additional named parameters are lost upon building the query. As example, please look at `similarity_search_with_score` in base `VectorStore` and `PGVector`: the former pass `kwargs` into the inner method as expected, while the latter isn't. This has important impacts as `kwargs` is typically used to pass additional params into inner methods to enable customizability. For example, if I want to customize a query to join other tables, I should be able to just inherit `PGVector`, override `__query_collection` and provide my custom query building logic. However, this would not be possible if `kwargs` is not passed through the search methods.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langchain-postgres#53