diff --git a/libs/langchain/langchain/retrievers/self_query/base.py b/libs/langchain/langchain/retrievers/self_query/base.py index f08038d072..68253fa74f 100644 --- a/libs/langchain/langchain/retrievers/self_query/base.py +++ b/libs/langchain/langchain/retrievers/self_query/base.py @@ -1,4 +1,5 @@ """Retriever that generates and executes structured queries over its own data source.""" + import logging from typing import Any, Dict, List, Optional, Sequence, Tuple, Type, Union @@ -8,7 +9,6 @@ from langchain_community.vectorstores import ( DashVector, DeepLake, Dingo, - ElasticsearchStore, Milvus, MongoDBAtlasVectorSearch, MyScale, @@ -22,6 +22,9 @@ from langchain_community.vectorstores import ( Vectara, Weaviate, ) +from langchain_community.vectorstores import ( + ElasticsearchStore as ElasticsearchStoreCommunity, +) from langchain_core.documents import Document from langchain_core.language_models import BaseLanguageModel from langchain_core.pydantic_v1 import Field, root_validator @@ -73,7 +76,7 @@ def _get_builtin_translator(vectorstore: VectorStore) -> Visitor: Qdrant: QdrantTranslator, MyScale: MyScaleTranslator, DeepLake: DeepLakeTranslator, - ElasticsearchStore: ElasticsearchTranslator, + ElasticsearchStoreCommunity: ElasticsearchTranslator, Milvus: MilvusTranslator, SupabaseVectorStore: SupabaseVectorTranslator, TimescaleVector: TimescaleVectorTranslator, @@ -98,6 +101,14 @@ def _get_builtin_translator(vectorstore: VectorStore) -> Visitor: except ImportError: pass + try: + from langchain_elasticsearch.vectorstores import ElasticsearchStore + + if isinstance(vectorstore, ElasticsearchStore): + return ElasticsearchTranslator() + except ImportError: + pass + raise ValueError( f"Self query retriever with Vector Store type {vectorstore.__class__}" f" not supported."