mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-19 13:23:35 +00:00
community: add len() implementation to Chroma (#19419)
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 <22008038+baskaryan@users.noreply.github.com>
This commit is contained in:
parent
e0a1278d2b
commit
2763d8cbe5
@ -795,3 +795,7 @@ class Chroma(VectorStore):
|
|||||||
ids: List of ids to delete.
|
ids: List of ids to delete.
|
||||||
"""
|
"""
|
||||||
self._collection.delete(ids=ids)
|
self._collection.delete(ids=ids)
|
||||||
|
|
||||||
|
def __len__(self) -> int:
|
||||||
|
"""Count the number of documents in the collection."""
|
||||||
|
return self._collection.count()
|
||||||
|
@ -21,6 +21,7 @@ def test_chroma() -> None:
|
|||||||
)
|
)
|
||||||
output = docsearch.similarity_search("foo", k=1)
|
output = docsearch.similarity_search("foo", k=1)
|
||||||
assert output == [Document(page_content="foo")]
|
assert output == [Document(page_content="foo")]
|
||||||
|
assert len(docsearch) == 3
|
||||||
|
|
||||||
|
|
||||||
async def test_chroma_async() -> None:
|
async def test_chroma_async() -> None:
|
||||||
|
Loading…
Reference in New Issue
Block a user