From 4f88a5130e881445450c6f9d02e65508d2f8fac6 Mon Sep 17 00:00:00 2001 From: Christophe Bornet Date: Thu, 22 Feb 2024 22:19:27 +0100 Subject: [PATCH] langchain[patch]: Support langchain-astradb AstraDBVectorStore in self-query retriever (#17728) Co-authored-by: Bagatur --- libs/langchain/langchain/retrievers/self_query/base.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/libs/langchain/langchain/retrievers/self_query/base.py b/libs/langchain/langchain/retrievers/self_query/base.py index d54120ccfc..94a2fb9610 100644 --- a/libs/langchain/langchain/retrievers/self_query/base.py +++ b/libs/langchain/langchain/retrievers/self_query/base.py @@ -76,6 +76,7 @@ def _get_builtin_translator(vectorstore: VectorStore) -> Visitor: OpenSearchVectorSearch: OpenSearchTranslator, MongoDBAtlasVectorSearch: MongoDBAtlasTranslator, } + if isinstance(vectorstore, Qdrant): return QdrantTranslator(metadata_key=vectorstore.metadata_payload_key) elif isinstance(vectorstore, MyScale): @@ -85,6 +86,14 @@ def _get_builtin_translator(vectorstore: VectorStore) -> Visitor: elif vectorstore.__class__ in BUILTIN_TRANSLATORS: return BUILTIN_TRANSLATORS[vectorstore.__class__]() else: + try: + from langchain_astradb.vectorstores import AstraDBVectorStore + + if isinstance(vectorstore, AstraDBVectorStore): + return AstraDBTranslator() + except ImportError: + pass + raise ValueError( f"Self query retriever with Vector Store type {vectorstore.__class__}" f" not supported."