langchain[patch]: Support langchain-astradb AstraDBVectorStore in self-query retriever (#17728)

Co-authored-by: Bagatur <baskaryan@gmail.com>
This commit is contained in:
Christophe Bornet 2024-02-22 22:19:27 +01:00 committed by GitHub
parent 9775de46cc
commit 4f88a5130e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -76,6 +76,7 @@ def _get_builtin_translator(vectorstore: VectorStore) -> Visitor:
OpenSearchVectorSearch: OpenSearchTranslator, OpenSearchVectorSearch: OpenSearchTranslator,
MongoDBAtlasVectorSearch: MongoDBAtlasTranslator, MongoDBAtlasVectorSearch: MongoDBAtlasTranslator,
} }
if isinstance(vectorstore, Qdrant): if isinstance(vectorstore, Qdrant):
return QdrantTranslator(metadata_key=vectorstore.metadata_payload_key) return QdrantTranslator(metadata_key=vectorstore.metadata_payload_key)
elif isinstance(vectorstore, MyScale): elif isinstance(vectorstore, MyScale):
@ -85,6 +86,14 @@ def _get_builtin_translator(vectorstore: VectorStore) -> Visitor:
elif vectorstore.__class__ in BUILTIN_TRANSLATORS: elif vectorstore.__class__ in BUILTIN_TRANSLATORS:
return BUILTIN_TRANSLATORS[vectorstore.__class__]() return BUILTIN_TRANSLATORS[vectorstore.__class__]()
else: else:
try:
from langchain_astradb.vectorstores import AstraDBVectorStore
if isinstance(vectorstore, AstraDBVectorStore):
return AstraDBTranslator()
except ImportError:
pass
raise ValueError( raise ValueError(
f"Self query retriever with Vector Store type {vectorstore.__class__}" f"Self query retriever with Vector Store type {vectorstore.__class__}"
f" not supported." f" not supported."