Skip to content

Commit

Permalink
community: add len() implementation to Chroma (#19419)
Browse files Browse the repository at this point in the history
Thank you for contributing to LangChain!

- [x] **Add len() implementation to Chroma**: "package: community"


- [x] **PR message**: 
- **Description:** add an implementation of the __len__() method for the
Chroma vectostore, for convenience.
- **Issue:** no exposed method to know the size of a Chroma vectorstore
    - **Dependencies:** None
    - **Twitter handle:** lowrank_adrian


- [x] **Add tests and docs**

- [x] **Lint and test**

---------

Co-authored-by: Bagatur <[email protected]>
  • Loading branch information
adrian-valente and baskaryan authored Mar 26, 2024
1 parent e0a1278 commit 2763d8c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
4 changes: 4 additions & 0 deletions libs/community/langchain_community/vectorstores/chroma.py
Original file line number Diff line number Diff line change
Expand Up @@ -795,3 +795,7 @@ def delete(self, ids: Optional[List[str]] = None, **kwargs: Any) -> None:
ids: List of ids to delete.
"""
self._collection.delete(ids=ids)

def __len__(self) -> int:
"""Count the number of documents in the collection."""
return self._collection.count()
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def test_chroma() -> None:
)
output = docsearch.similarity_search("foo", k=1)
assert output == [Document(page_content="foo")]
assert len(docsearch) == 3


async def test_chroma_async() -> None:
Expand Down

0 comments on commit 2763d8c

Please sign in to comment.