Skip to content

Commit

Permalink
Implement count_document for WeaviateDocumentStore (#267)
Browse files Browse the repository at this point in the history
* Implement count_document for WeaviateDocumentStore

* Start container in test workflow

* Ditch Windows and Mac on Weaviate CI as Docker images are not provided
  • Loading branch information
silvanocerza authored Jan 25, 2024
1 parent e39b2d2 commit 7e21bd8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
11 changes: 4 additions & 7 deletions .github/workflows/weaviate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,10 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
os: [ubuntu-latest]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]

steps:
- name: Support longpaths
if: matrix.os == 'windows-latest'
working-directory: .
run: git config --system core.longpaths true

- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
Expand All @@ -49,8 +44,10 @@ jobs:
run: pip install --upgrade hatch

- name: Lint
if: runner.os == 'Linux'
run: hatch run lint:all

- name: Run Weaviate container
run: docker-compose up -d

- name: Run tests
run: hatch run cov
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 7e21bd8

Please sign in to comment.