Skip to content

The agent engineering platform.

Using batches for update document with a new function in ChromaDB (#6561)

berkedilekoglu73b9ca54cbf8
diff --git a/libs/langchain/langchain/vectorstores/chroma.py b/libs/langchain/langchain/vectorstores/chroma.py
index 3b8edc2212..7994e2326d 100644
--- a/libs/langchain/langchain/vectorstores/chroma.py
+++ b/libs/langchain/langchain/vectorstores/chroma.py
@@ -541,19 +541,28 @@ class Chroma(VectorStore):
document_id (str): ID of the document to update.
document (Document): Document to update.
"""
- text = document.page_content
- metadata = document.metadata
+ return self.update_documents([document_id], [document])
+
+ def update_documents(self, ids: List[str], documents: List[Document]) -> None:
+ """Update a document in the collection.
+
+ Args:
+ ids (List[str]): List of ids of the document to update.
+ documents (List[Document]): List of documents to update.
+ """
+ text = [document.page_content for document in documents]
+ metadata = [document.metadata for document in documents]
if self._embedding_function is None:
raise ValueError(
"For update, you must specify an embedding function on creation."
)
- embeddings = self._embedding_function.embed_documents([text])
+ embeddings = self._embedding_function.embed_documents(text)
self._collection.update(
- ids=[document_id],
+ ids=ids,
embeddings=embeddings,
- documents=[text],
- metadatas=[metadata],
+ documents=text,
+ metadatas=metadata,
)
@classmethod