langchain[patch]: fix ElasticsearchStore reference for self query (#19907)

Initializing self query with an ElasticsearchStore from the partners
packages failed previously, see
https://github.com/langchain-ai/langchain/discussions/18976.
This commit is contained in:
Max Jakob 2024-04-02 17:39:12 +02:00 committed by GitHub
parent 3218463f6a
commit 22dbcc9441
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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."