From 88588466071a9dde3a4c26c813e30b9db7842eca Mon Sep 17 00:00:00 2001 From: Eugene Yurtsev Date: Thu, 11 Jul 2024 21:51:18 -0400 Subject: [PATCH] milvus[patch]: Fix Milvus vectorstore for newer versions of langchain-core (#24152) Fix for: https://github.com/langchain-ai/langchain/issues/24116 This keeps the old behavior of add_documents and add_texts --- .../langchain_milvus/vectorstores/milvus.py | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/libs/partners/milvus/langchain_milvus/vectorstores/milvus.py b/libs/partners/milvus/langchain_milvus/vectorstores/milvus.py index 78bf7a98527..5a5acda13f6 100644 --- a/libs/partners/milvus/langchain_milvus/vectorstores/milvus.py +++ b/libs/partners/milvus/langchain_milvus/vectorstores/milvus.py @@ -1084,6 +1084,35 @@ class Milvus(VectorStore): metadata=data.pop(self._metadata_field) if self._metadata_field else data, ) + def add_documents(self, documents: List[Document], **kwargs: Any) -> List[str]: + """Run more documents through the embeddings and add to the vectorstore. + + Args: + documents: Documents to add to the vectorstore. + + Returns: + List of IDs of the added texts. + """ + # TODO: Handle the case where the user doesn't provide ids on the Collection + texts = [doc.page_content for doc in documents] + metadatas = [doc.metadata for doc in documents] + return self.add_texts(texts, metadatas, **kwargs) + + async def aadd_documents( + self, documents: List[Document], **kwargs: Any + ) -> List[str]: + """Run more documents through the embeddings and add to the vectorstore. + + Args: + documents: Documents to add to the vectorstore. + + Returns: + List of IDs of the added texts. + """ + texts = [doc.page_content for doc in documents] + metadatas = [doc.metadata for doc in documents] + return await self.aadd_texts(texts, metadatas, **kwargs) + def get_pks(self, expr: str, **kwargs: Any) -> List[int] | None: """Get primary keys with expression @@ -1110,7 +1139,7 @@ class Milvus(VectorStore): pks = [item.get(self._primary_field) for item in query_result] return pks - def upsert( + def upsert( # type: ignore self, ids: Optional[List[str]] = None, documents: List[Document] | None = None,