From 50a9fcccb0906f37a61ace52f9b6490a03d796a4 Mon Sep 17 00:00:00 2001 From: charosen <529492700@qq.com> Date: Mon, 10 Jul 2023 14:25:35 +0800 Subject: [PATCH] feat(module): add param ids to ElasticVectorSearch.from_texts method (#7425) # add param ids to ElasticVectorSearch.from_texts method. - Description: add param ids to ElasticVectorSearch.from_texts method. - Issue: NA. It seems `add_texts` already supports passing in document ids, but param `ids` is omitted in `from_texts` classmethod, - Dependencies: None, - Tag maintainer: @rlancemartin, @eyurtsev please have a look, thanks ``` # ElasticVectorSearch add_texts def add_texts( self, texts: Iterable[str], metadatas: Optional[List[dict]] = None, refresh_indices: bool = True, ids: Optional[List[str]] = None, **kwargs: Any, ) -> List[str]: ... ``` ``` # ElasticVectorSearch from_texts @classmethod def from_texts( cls, texts: List[str], embedding: Embeddings, metadatas: Optional[List[dict]] = None, elasticsearch_url: Optional[str] = None, index_name: Optional[str] = None, refresh_indices: bool = True, **kwargs: Any, ) -> ElasticVectorSearch: ``` Co-authored-by: charosen --- langchain/vectorstores/elastic_vector_search.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/langchain/vectorstores/elastic_vector_search.py b/langchain/vectorstores/elastic_vector_search.py index ac38d37c2e..9cfe1235af 100644 --- a/langchain/vectorstores/elastic_vector_search.py +++ b/langchain/vectorstores/elastic_vector_search.py @@ -157,8 +157,8 @@ class ElasticVectorSearch(VectorStore, ABC): self, texts: Iterable[str], metadatas: Optional[List[dict]] = None, - refresh_indices: bool = True, ids: Optional[List[str]] = None, + refresh_indices: bool = True, **kwargs: Any, ) -> List[str]: """Run more texts through the embeddings and add to the vectorstore. @@ -166,6 +166,7 @@ class ElasticVectorSearch(VectorStore, ABC): Args: texts: Iterable of strings to add to the vectorstore. metadatas: Optional list of metadatas associated with the texts. + ids: Optional list of unique IDs. refresh_indices: bool to refresh ElasticSearch indices Returns: @@ -260,6 +261,7 @@ class ElasticVectorSearch(VectorStore, ABC): texts: List[str], embedding: Embeddings, metadatas: Optional[List[dict]] = None, + ids: Optional[List[str]] = None, elasticsearch_url: Optional[str] = None, index_name: Optional[str] = None, refresh_indices: bool = True, @@ -292,7 +294,7 @@ class ElasticVectorSearch(VectorStore, ABC): index_name = index_name or uuid.uuid4().hex vectorsearch = cls(elasticsearch_url, index_name, embedding, **kwargs) vectorsearch.add_texts( - texts, metadatas=metadatas, refresh_indices=refresh_indices + texts, metadatas=metadatas, ids=ids, refresh_indices=refresh_indices ) return vectorsearch