Skip to content

Commit

Permalink
backward compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
shjunn committed Nov 4, 2024
1 parent 0ad9715 commit 7b31bfe
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
12 changes: 10 additions & 2 deletions libs/community/langchain_community/vectorstores/chroma.py
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,11 @@ 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"
chroma_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

Expand Down Expand Up @@ -823,8 +827,12 @@ def from_texts(
if ids is None:
ids = [str(uuid.uuid4()) for _ in texts]
if hasattr(
chroma_collection._client, "get_max_batch_size"
): # for Chroma 0.5.1 and above
or
hasattr(
chroma_collection._client, # type: ignore[has-type]
"get_max_batch_size", # type: ignore[has-type]
"max_batch_size", # type: ignore[has-type]
): # for Chroma 0.4.10 and above
from chromadb.utils.batch_utils import create_batches

Expand Down
10 changes: 9 additions & 1 deletion libs/partners/chroma/langchain_chroma/vectorstores.py
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,11 @@ 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"
chroma_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

Expand Down Expand Up @@ -1071,6 +1075,10 @@ def from_texts(
ids = [str(uuid.uuid4()) for _ in texts]
if hasattr(
chroma_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

Expand Down

0 comments on commit 7b31bfe

Please sign in to comment.