From 029febc208a17fdf07356b7ad2dbc6b1ccfd81f6 Mon Sep 17 00:00:00 2001 From: SHJUN <134789343+shjunn@users.noreply.github.com> Date: Wed, 6 Nov 2024 04:43:11 +0900 Subject: [PATCH] community: chroma error patch(attribute changed on chroma) (#27827) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There was a change of attribute name which was "max_batch_size". It's now "get_max_batch_size" method. I want to use "create_batches" which is right down below. Please check this PR link. reference: https://github.com/chroma-core/chroma/pull/2305 --------- Signed-off-by: Prithvi Kannan Co-authored-by: Prithvi Kannan <46332835+prithvikannan@users.noreply.github.com> Co-authored-by: Bagatur <22008038+baskaryan@users.noreply.github.com> Co-authored-by: Erick Friis Co-authored-by: Jun Yamog Co-authored-by: Bagatur Co-authored-by: ono-hiroki <86904208+ono-hiroki@users.noreply.github.com> Co-authored-by: Dobiichi-Origami <56953648+Dobiichi-Origami@users.noreply.github.com> Co-authored-by: Chester Curme Co-authored-by: Duy Huynh Co-authored-by: Rashmi Pawar <168514198+raspawar@users.noreply.github.com> Co-authored-by: sifatj <26035630+sifatj@users.noreply.github.com> Co-authored-by: Eric Pinzur <2641606+epinzur@users.noreply.github.com> Co-authored-by: Daniel Vu Dao Co-authored-by: Ofer Mendelevitch Co-authored-by: Stéphane Philippart --- libs/community/langchain_community/vectorstores/chroma.py | 8 +++++++- libs/partners/chroma/langchain_chroma/vectorstores.py | 4 ++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/libs/community/langchain_community/vectorstores/chroma.py b/libs/community/langchain_community/vectorstores/chroma.py index 40ba2415b6933d..1ab7ddad140d6d 100644 --- a/libs/community/langchain_community/vectorstores/chroma.py +++ b/libs/community/langchain_community/vectorstores/chroma.py @@ -753,6 +753,9 @@ def update_documents(self, ids: List[str], documents: List[Document]) -> None: embeddings = self._embedding_function.embed_documents(text) if hasattr( + self._collection._client, + "get_max_batch_size", # for Chroma 0.5.1 and above + ) or hasattr( self._collection._client, "max_batch_size" ): # for Chroma 0.4.10 and above from chromadb.utils.batch_utils import create_batches @@ -824,7 +827,10 @@ def from_texts( ids = [str(uuid.uuid4()) for _ in texts] if hasattr( chroma_collection._client, # type: ignore[has-type] - "max_batch_size", # type: ignore[has-type] + "get_max_batch_size", # for Chroma 0.5.1 and above + ) or hasattr( + chroma_collection._client, # type: ignore[has-type] + "max_batch_size", ): # for Chroma 0.4.10 and above from chromadb.utils.batch_utils import create_batches diff --git a/libs/partners/chroma/langchain_chroma/vectorstores.py b/libs/partners/chroma/langchain_chroma/vectorstores.py index 945057f4adb22d..35146fdcc76037 100644 --- a/libs/partners/chroma/langchain_chroma/vectorstores.py +++ b/libs/partners/chroma/langchain_chroma/vectorstores.py @@ -997,6 +997,8 @@ def update_documents(self, ids: List[str], documents: List[Document]) -> None: embeddings = self._embedding_function.embed_documents(text) if hasattr( + self._collection._client, "get_max_batch_size" + ) or hasattr( # for Chroma 0.5.1 and above self._collection._client, "max_batch_size" ): # for Chroma 0.4.10 and above from chromadb.utils.batch_utils import create_batches @@ -1070,6 +1072,8 @@ def from_texts( if ids is None: ids = [str(uuid.uuid4()) for _ in texts] if hasattr( + chroma_collection._client, "get_max_batch_size" + ) or hasattr( # for Chroma 0.5.1 and above chroma_collection._client, "max_batch_size" ): # for Chroma 0.4.10 and above from chromadb.utils.batch_utils import create_batches