66from haystack .dataclasses import Document
77from haystack .errors import FilterError
88from haystack .testing .document_store import (
9+ CountDocumentsByFilterTest ,
910 CountDocumentsTest ,
11+ CountUniqueMetadataByFilterTest ,
1012 DeleteAllTest ,
1113 DeleteByFilterTest ,
1214 DeleteDocumentsTest ,
1315 FilterDocumentsTest ,
16+ GetMetadataFieldMinMaxTest ,
17+ GetMetadataFieldsInfoTest ,
18+ GetMetadataFieldUniqueValuesTest ,
1419 UpdateByFilterTest ,
1520)
1621
@@ -24,20 +29,23 @@ class TestFAISSDocumentStore(
2429 UpdateByFilterTest ,
2530 DeleteAllTest ,
2631 DeleteByFilterTest ,
32+ CountDocumentsByFilterTest ,
33+ CountUniqueMetadataByFilterTest ,
34+ GetMetadataFieldsInfoTest ,
35+ GetMetadataFieldMinMaxTest ,
36+ GetMetadataFieldUniqueValuesTest ,
2737):
2838 @pytest .fixture
2939 def document_store (self , tmp_path ):
3040 return FAISSDocumentStore (index_path = str (tmp_path / "test_index" ))
3141
3242 def test_write_documents (self , document_store ):
33-
3443 doc = Document (content = "test" )
3544 document_store .write_documents ([doc ])
3645 assert document_store .count_documents () == 1
3746 assert document_store .filter_documents ()[0 ].id == doc .id
3847
3948 def test_persistence (self , tmp_path ):
40-
4149 path = tmp_path / "persistent_index"
4250 ds = FAISSDocumentStore (index_path = str (path ), embedding_dim = 3 )
4351
@@ -73,7 +81,6 @@ def test_load_missing_files(self, tmp_path):
7381 ds .load (path )
7482
7583 def test_search_with_and_without_filters (self , document_store ):
76-
7784 # Setup documents with missing/varied embeddings to test edge cases
7885 doc1 = Document (content = "test1" , embedding = [0.1 , 0.2 , 0.3 ], meta = {"category" : "A" })
7986 doc2 = Document (content = "test2" , embedding = [0.4 , 0.5 , 0.6 ], meta = {"category" : "B" })
@@ -97,7 +104,6 @@ def test_search_with_and_without_filters(self, document_store):
97104
98105 def test_to_dict_from_dict (self ):
99106 ds = FAISSDocumentStore (index_path = "test_index" , index_string = "Flat" , embedding_dim = 128 )
100-
101107 data = ds .to_dict ()
102108 assert data ["type" ] == "haystack_integrations.document_stores.faiss.document_store.FAISSDocumentStore"
103109 assert data ["init_parameters" ]["index_path" ] == "test_index"
@@ -109,50 +115,7 @@ def test_to_dict_from_dict(self):
109115 assert ds_loaded .index_string == "Flat"
110116 assert ds_loaded .embedding_dim == 128
111117
112- def test_count_documents_by_filter (self , document_store ):
113-
114- docs = [
115- Document (content = "test1" , meta = {"category" : "A" }),
116- Document (content = "test2" , meta = {"category" : "B" }),
117- Document (content = "test3" , meta = {"category" : "A" }),
118- ]
119- document_store .write_documents (docs )
120-
121- count = document_store .count_documents_by_filter (
122- filters = {"field" : "meta.category" , "operator" : "==" , "value" : "A" }
123- )
124- assert count == 2
125-
126- def test_get_metadata_fields_info (self , document_store ):
127-
128- docs = [Document (content = "test1" , meta = {"category" : "A" , "count" : 1 , "is_active" : True })]
129- document_store .write_documents (docs )
130-
131- info = document_store .get_metadata_fields_info ()
132- assert "category" in info
133- assert info ["category" ]["type" ] == "keyword"
134- assert "count" in info
135- assert info ["count" ]["type" ] == "long"
136- assert "is_active" in info
137- assert info ["is_active" ]["type" ] == "boolean"
138-
139- def test_count_unique_metadata_by_filter (self , document_store ):
140-
141- docs = [
142- Document (content = "test1" , meta = {"category" : "A" , "status" : "active" }),
143- Document (content = "test2" , meta = {"category" : "B" , "status" : "inactive" }),
144- Document (content = "test3" , meta = {"category" : "A" , "status" : "active" }),
145- ]
146- document_store .write_documents (docs )
147-
148- counts = document_store .count_unique_metadata_by_filter (
149- filters = {"field" : "meta.category" , "operator" : "==" , "value" : "A" }, fields = ["meta.status" ]
150- )
151- assert "meta.status" in counts
152- assert counts ["meta.status" ] == 1 # Only "active" status for category A
153-
154118 def test_not_filter_with_empty_conditions_raises_filter_error (self , document_store ):
155119 document_store .write_documents ([Document (content = "test" , meta = {"category" : "A" })])
156-
157120 with pytest .raises (FilterError , match = "NOT operator expects at least one condition" ):
158121 document_store .filter_documents (filters = {"operator" : "NOT" , "conditions" : []})
0 commit comments