99from haystack import Document
1010from haystack .document_stores .errors import DuplicateDocumentError
1111from haystack .document_stores .types import DuplicatePolicy
12- from haystack .testing .document_store import DocumentStoreBaseExtendedTests
12+ from haystack .testing .document_store import (
13+ CountDocumentsByFilterTest ,
14+ CountUniqueMetadataByFilterTest ,
15+ DocumentStoreBaseExtendedTests ,
16+ FilterableDocsFixtureMixin ,
17+ GetMetadataFieldMinMaxTest ,
18+ GetMetadataFieldsInfoTest ,
19+ GetMetadataFieldUniqueValuesTest ,
20+ )
1321
1422from haystack_integrations .document_stores .arcadedb import ArcadeDBDocumentStore
1523
@@ -48,7 +56,15 @@ def test_to_dict_from_dict(self):
4856 reason = "Set ARCADEDB_PASSWORD (e.g. via repo secret in CI) to run integration tests." ,
4957)
5058@pytest .mark .integration
51- class TestArcadeDBDocumentStore (DocumentStoreBaseExtendedTests ):
59+ class TestArcadeDBDocumentStore (
60+ CountDocumentsByFilterTest ,
61+ CountUniqueMetadataByFilterTest ,
62+ DocumentStoreBaseExtendedTests ,
63+ FilterableDocsFixtureMixin ,
64+ GetMetadataFieldMinMaxTest ,
65+ GetMetadataFieldsInfoTest ,
66+ GetMetadataFieldUniqueValuesTest
67+ ):
5268 """
5369 Run Haystack DocumentStore mixin tests against ArcadeDBDocumentStore.
5470
@@ -124,32 +140,6 @@ def test_embedding_retrieval(self, document_store: ArcadeDBDocumentStore):
124140 assert len (results ) <= 3
125141 assert results [0 ].score is not None
126142
127- def test_count_documents_by_filter (self , document_store : ArcadeDBDocumentStore ):
128- """Counts only documents matching the provided filter."""
129- docs = [
130- Document (id = "1" , content = "Doc 1" , meta = {"category" : "news" , "status" : "published" , "priority" : 3 }),
131- Document (id = "2" , content = "Doc 2" , meta = {"category" : "docs" , "status" : "draft" , "priority" : 1 }),
132- Document (id = "3" , content = "Doc 3" , meta = {"category" : "news" , "status" : "published" , "priority" : 5 }),
133- ]
134- document_store .write_documents (docs )
135-
136- count = document_store .count_documents_by_filter (
137- {"field" : "meta.status" , "operator" : "==" , "value" : "published" }
138- )
139-
140- assert count == 2
141-
142- def test_count_documents_by_filter_no_matches (self , document_store : ArcadeDBDocumentStore ):
143- """Returns zero when no documents match the filter."""
144- docs = [
145- Document (id = "1" , content = "Doc 1" , meta = {"category" : "news" }),
146- ]
147- document_store .write_documents (docs )
148-
149- count = document_store .count_documents_by_filter ({"field" : "meta.status" , "operator" : "==" , "value" : "sports" })
150-
151- assert count == 0
152-
153143 def test_count_documents_by_empty_filter (self , document_store : ArcadeDBDocumentStore ):
154144 """Counts all documents when an empty filter is provided."""
155145 docs = [
@@ -161,23 +151,6 @@ def test_count_documents_by_empty_filter(self, document_store: ArcadeDBDocumentS
161151
162152 assert count == 1
163153
164- def test_count_unique_metadata_by_filter (self , document_store : ArcadeDBDocumentStore ):
165- """Counts unique values per field across documents matching the filter."""
166- docs = [
167- Document (id = "1" , content = "Doc 1" , meta = {"category" : "news" , "status" : "published" , "priority" : 1 }),
168- Document (id = "2" , content = "Doc 2" , meta = {"category" : "docs" , "status" : "published" , "priority" : 2 }),
169- Document (id = "3" , content = "Doc 3" , meta = {"category" : "news" , "status" : "published" , "priority" : 2 }),
170- Document (id = "4" , content = "Doc 4" , meta = {"category" : "faq" , "status" : "draft" , "priority" : 3 }),
171- ]
172- document_store .write_documents (docs )
173-
174- counts = document_store .count_unique_metadata_by_filter (
175- {"field" : "meta.status" , "operator" : "==" , "value" : "published" },
176- ["category" , "priority" ],
177- )
178-
179- assert counts == {"category" : 2 , "priority" : 2 }
180-
181154 def test_count_unique_metadata_by_filter_empty_fields (self , document_store : ArcadeDBDocumentStore ):
182155 """Returns an empty dict when no metadata fields are requested."""
183156 docs = [
@@ -192,57 +165,6 @@ def test_count_unique_metadata_by_filter_empty_fields(self, document_store: Arca
192165
193166 assert counts == {}
194167
195- def test_count_unique_metadata_by_empty_filter (self , document_store : ArcadeDBDocumentStore ):
196- """Counts unique values across all documents when filter is empty."""
197- docs = [
198- Document (id = "1" , content = "Doc 1" , meta = {"category" : "news" }),
199- ]
200- document_store .write_documents (docs )
201-
202- counts = document_store .count_unique_metadata_by_filter ({}, ["category" ])
203-
204- assert counts == {"category" : 1 }
205-
206- def test_get_metadata_fields_info (self , document_store : ArcadeDBDocumentStore ):
207- """Returns correct Haystack type strings for all metadata field types."""
208- docs = [
209- Document (
210- id = "1" , content = "Doc 1" , meta = {"category" : "news" , "status" : "published" , "priority" : 1 , "active" : True }
211- ),
212- Document (
213- id = "2" , content = "Doc 2" , meta = {"category" : "docs" , "status" : "draft" , "priority" : 2.5 , "active" : False }
214- ),
215- ]
216- document_store .write_documents (docs )
217-
218- fields_info = document_store .get_metadata_fields_info ()
219-
220- assert fields_info == {
221- "content" : {"type" : "text" },
222- "category" : {"type" : "keyword" },
223- "status" : {"type" : "keyword" },
224- "priority" : {"type" : "long" },
225- "active" : {"type" : "boolean" },
226- }
227-
228- def test_get_metadata_fields_info_empty_store (self , document_store : ArcadeDBDocumentStore ):
229- """Returns an empty dict when the store contains no documents."""
230- result = document_store .get_metadata_fields_info ()
231- assert result == {}
232-
233- def test_get_metadata_field_min_max (self , document_store : ArcadeDBDocumentStore ):
234- """Returns the correct min and max for a numeric metadata field."""
235- docs = [
236- Document (id = "1" , content = "Doc 1" , meta = {"priority" : 3 }),
237- Document (id = "2" , content = "Doc 2" , meta = {"priority" : 1 }),
238- Document (id = "3" , content = "Doc 3" , meta = {"priority" : 7 }),
239- ]
240- document_store .write_documents (docs )
241-
242- result = document_store .get_metadata_field_min_max ("priority" )
243-
244- assert result == {"min" : 1 , "max" : 7 }
245-
246168 def test_get_metadata_field_min_max_nonexistent_field (self , document_store : ArcadeDBDocumentStore ):
247169 """Returns None for both min and max when the field does not exist."""
248170 docs = [Document (id = "1" , content = "Doc 1" , meta = {"category" : "news" })]
@@ -252,23 +174,6 @@ def test_get_metadata_field_min_max_nonexistent_field(self, document_store: Arca
252174
253175 assert result == {"min" : None , "max" : None }
254176
255- def test_get_metadata_field_unique_values (self , document_store : ArcadeDBDocumentStore ):
256- """Returns values matching the search term and the correct total count."""
257- docs = [
258- Document (id = "1" , content = "Doc 1" , meta = {"category" : "alpha" }),
259- Document (id = "2" , content = "Doc 2" , meta = {"category" : "beta" }),
260- Document (id = "3" , content = "Doc 3" , meta = {"category" : "alphabet" }),
261- Document (id = "4" , content = "Doc 4" , meta = {"category" : "gamma" }),
262- ]
263- document_store .write_documents (docs )
264-
265- values , total_count = document_store .get_metadata_field_unique_values (
266- "category" , search_term = "alp" , from_ = 0 , size = 10
267- )
268-
269- assert sorted (values ) == ["alpha" , "alphabet" ]
270- assert total_count == 2
271-
272177 def test_get_metadata_field_unique_values_pagination (self , document_store : ArcadeDBDocumentStore ):
273178 """Respects size limit while total reflects the full unpaginated count."""
274179 docs = [
0 commit comments