mirror of
https://github.com/hwchase17/langchain.git
synced 2025-07-13 08:27:03 +00:00
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
This commit is contained in:
parent
ffe6ca986e
commit
8858846607
@ -1084,6 +1084,35 @@ class Milvus(VectorStore):
|
|||||||
metadata=data.pop(self._metadata_field) if self._metadata_field else data,
|
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:
|
def get_pks(self, expr: str, **kwargs: Any) -> List[int] | None:
|
||||||
"""Get primary keys with expression
|
"""Get primary keys with expression
|
||||||
|
|
||||||
@ -1110,7 +1139,7 @@ class Milvus(VectorStore):
|
|||||||
pks = [item.get(self._primary_field) for item in query_result]
|
pks = [item.get(self._primary_field) for item in query_result]
|
||||||
return pks
|
return pks
|
||||||
|
|
||||||
def upsert(
|
def upsert( # type: ignore
|
||||||
self,
|
self,
|
||||||
ids: Optional[List[str]] = None,
|
ids: Optional[List[str]] = None,
|
||||||
documents: List[Document] | None = None,
|
documents: List[Document] | None = None,
|
||||||
|
Loading…
Reference in New Issue
Block a user