Skip to content

Commit

Permalink
langchain[minor]: Add pgvector to list of supported vectorstores in s…
Browse files Browse the repository at this point in the history
…elf query retriever (#22678)

The fact that we outsourced pgvector to another project has an
unintended effect. The mapping dictionary found by
`_get_builtin_translator()` cannot recognize the new version of pgvector
because it comes from another package.
`SelfQueryRetriever` no longer knows `PGVector`.

I propose to fix this by creating a global dictionary that can be
populated by various database implementations. Thus, importing
`langchain_postgres` will allow the registration of the `PGvector`
mapping.

But for the moment I'm just adding a lazy import

Furthermore, the implementation of _get_builtin_translator()
reconstructs the BUILTIN_TRANSLATORS variable with each invocation,
which is not very efficient. A global map would be an optimization.

- **Twitter handle:** pprados

@eyurtsev, can you review this PR? And unlock the PR [Add async mode for
pgvector](langchain-ai/langchain-postgres#32)
and PR [community[minor]: Add SQL storage
implementation](#22207)?

Are you in favour of a global dictionary-based implementation of
Translator?
  • Loading branch information
pprados authored and hinthornw committed Jun 20, 2024
1 parent 535f07b commit 5ccf8d5
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions libs/langchain/langchain/retrievers/self_query/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,14 @@ def _get_builtin_translator(vectorstore: VectorStore) -> Visitor:
if isinstance(vectorstore, Chroma):
return ChromaTranslator()

try:
from langchain_postgres import PGVector
except ImportError:
pass
else:
if isinstance(vectorstore, PGVector):
return PGVectorTranslator()

raise ValueError(
f"Self query retriever with Vector Store type {vectorstore.__class__}"
f" not supported."
Expand Down

0 comments on commit 5ccf8d5

Please sign in to comment.