Skip to content

Commit

Permalink
Implement count_document for WeaviateDocumentStore
Browse files Browse the repository at this point in the history
  • Loading branch information
silvanocerza committed Jan 25, 2024
1 parent f0d4709 commit 1fa169f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,9 @@ def from_dict(cls, data: Dict[str, Any]) -> "WeaviateDocumentStore":
)

def count_documents(self) -> int:
return 0
collection_name = self._collection_settings["class"]
res = self._client.query.aggregate(collection_name).with_meta_count().do()
return res.get("data", {}).get("Aggregate", {}).get(collection_name, [{}])[0].get("meta", {}).get("count", 0)

def filter_documents(self, filters: Optional[Dict[str, Any]] = None) -> List[Document]: # noqa: ARG002
return []
Expand Down
7 changes: 6 additions & 1 deletion integrations/weaviate/tests/test_document_store.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from unittest.mock import MagicMock, patch

import pytest
from haystack.testing.document_store import CountDocumentsTest
from haystack_integrations.document_stores.weaviate.document_store import (
DOCUMENT_COLLECTION_PROPERTIES,
WeaviateDocumentStore,
Expand All @@ -16,7 +17,7 @@
)


class TestWeaviateDocumentStore:
class TestWeaviateDocumentStore(CountDocumentsTest):
@pytest.fixture
def document_store(self, request) -> WeaviateDocumentStore:
# Use a different index for each test so we can run them in parallel
Expand Down Expand Up @@ -197,3 +198,7 @@ def test_from_dict(self, _mock_weaviate):
assert document_store._additional_config.grpc_port_experimental == 12345
assert document_store._additional_config.connection_config.session_pool_connections == 20
assert document_store._additional_config.connection_config.session_pool_maxsize == 20

def test_count_not_empty(self, document_store):
# Skipped for the time being as we don't support writing documents
pass

0 comments on commit 1fa169f

Please sign in to comment.