Skip to content

Commit

Permalink
langchain[patch]: fix ElasticsearchStore reference for self query (#1…
Browse files Browse the repository at this point in the history
…9907)

Initializing self query with an ElasticsearchStore from the partners
packages failed previously, see
#18976.
  • Loading branch information
maxjakob authored and hinthornw committed Apr 26, 2024
1 parent 404c33e commit 32f464f
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions libs/langchain/langchain/retrievers/self_query/base.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -8,7 +9,6 @@
DashVector,
DeepLake,
Dingo,
ElasticsearchStore,
Milvus,
MongoDBAtlasVectorSearch,
MyScale,
Expand All @@ -22,6 +22,9 @@
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
Expand Down Expand Up @@ -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,
Expand All @@ -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."
Expand Down

0 comments on commit 32f464f

Please sign in to comment.