@@ -42,53 +42,7 @@ def clear_chroma_system_cache():
4242 SharedSystemClient .clear_system_cache ()
4343
4444
45- class TestDocumentStore (
46- CountDocumentsTest ,
47- DeleteDocumentsTest ,
48- FilterDocumentsTest ,
49- FilterableDocsFixtureMixin ,
50- UpdateByFilterTest ,
51- DeleteAllTest ,
52- DeleteByFilterTest ,
53- CountDocumentsByFilterTest ,
54- CountUniqueMetadataByFilterTest ,
55- GetMetadataFieldsInfoTest ,
56- GetMetadataFieldMinMaxTest ,
57- GetMetadataFieldUniqueValuesTest ,
58- ):
59- """
60- Common test cases will be provided by `DocumentStoreBaseTests` but
61- you can add more to this class.
62- """
63-
64- @pytest .fixture
65- def document_store (self , embedding_function ) -> ChromaDocumentStore :
66- """
67- This is the most basic requirement for the child class: provide
68- an instance of this document store so the base class can use it.
69- """
70- with mock .patch (
71- "haystack_integrations.document_stores.chroma.document_store.get_embedding_function"
72- ) as get_func :
73- get_func .return_value = embedding_function
74- return ChromaDocumentStore (embedding_function = "test_function" , collection_name = str (uuid .uuid1 ()))
75-
76- def assert_documents_are_equal (self , received : list [Document ], expected : list [Document ]):
77- """
78- Assert that two lists of Documents are equal.
79- This is used in every test, if a Document Store implementation has a different behaviour
80- it should override this method.
81-
82- This can happen for example when the Document Store sets a score to returned Documents.
83- Since we can't know what the score will be, we can't compare the Documents reliably.
84- """
85- received .sort (key = operator .attrgetter ("id" ))
86- expected .sort (key = operator .attrgetter ("id" ))
87-
88- for doc_received , doc_expected in zip (received , expected , strict = True ):
89- assert doc_received .content == doc_expected .content
90- assert doc_received .meta == doc_expected .meta
91-
45+ class TestDocumentStoreUnit :
9246 def test_init_in_memory (self ):
9347 store = ChromaDocumentStore ()
9448
@@ -122,17 +76,6 @@ def test_invalid_initialization_both_host_and_persist_path(self):
12276 store = ChromaDocumentStore (persist_path = "./path/to/local/store" , host = "localhost" )
12377 store ._ensure_initialized ()
12478
125- def test_client_settings_applied (self , clear_chroma_system_cache ):
126- """
127- Chroma's in-memory client uses a singleton pattern with an internal cache.
128- Once a client is created with certain settings, Chroma rejects creating another
129- with different settings in the same process. We clear the cache before and after
130- this test to avoid conflicts with other tests that use default settings.
131- """
132- store = ChromaDocumentStore (client_settings = {"anonymized_telemetry" : False })
133- store ._ensure_initialized ()
134- assert store ._client .get_settings ().anonymized_telemetry is False
135-
13679 def test_to_dict (self , request ):
13780 ds = ChromaDocumentStore (
13881 collection_name = request .node .name ,
@@ -182,6 +125,66 @@ def test_same_collection_name_reinitialization(self):
182125 ChromaDocumentStore ("test_1" )
183126 ChromaDocumentStore ("test_1" )
184127
128+
129+ @pytest .mark .integration
130+ class TestDocumentStore (
131+ CountDocumentsTest ,
132+ DeleteDocumentsTest ,
133+ FilterDocumentsTest ,
134+ FilterableDocsFixtureMixin ,
135+ UpdateByFilterTest ,
136+ DeleteAllTest ,
137+ DeleteByFilterTest ,
138+ CountDocumentsByFilterTest ,
139+ CountUniqueMetadataByFilterTest ,
140+ GetMetadataFieldsInfoTest ,
141+ GetMetadataFieldMinMaxTest ,
142+ GetMetadataFieldUniqueValuesTest ,
143+ ):
144+ """
145+ Common test cases will be provided by `DocumentStoreBaseTests` but
146+ you can add more to this class.
147+ """
148+
149+ @pytest .fixture
150+ def document_store (self , embedding_function ) -> ChromaDocumentStore :
151+ """
152+ This is the most basic requirement for the child class: provide
153+ an instance of this document store so the base class can use it.
154+ """
155+ with mock .patch (
156+ "haystack_integrations.document_stores.chroma.document_store.get_embedding_function"
157+ ) as get_func :
158+ get_func .return_value = embedding_function
159+ return ChromaDocumentStore (embedding_function = "test_function" , collection_name = str (uuid .uuid1 ()))
160+
161+ def assert_documents_are_equal (self , received : list [Document ], expected : list [Document ]):
162+ """
163+ Assert that two lists of Documents are equal.
164+ This is used in every test, if a Document Store implementation has a different behaviour
165+ it should override this method.
166+
167+ This can happen for example when the Document Store sets a score to returned Documents.
168+ Since we can't know what the score will be, we can't compare the Documents reliably.
169+ """
170+ received .sort (key = operator .attrgetter ("id" ))
171+ expected .sort (key = operator .attrgetter ("id" ))
172+
173+ for doc_received , doc_expected in zip (received , expected , strict = True ):
174+ assert doc_received .content == doc_expected .content
175+ assert doc_received .meta == doc_expected .meta
176+
177+ def test_client_settings_applied (self , clear_chroma_system_cache ):
178+ """
179+ Chroma's in-memory client uses a singleton pattern with an internal cache.
180+ Once a client is created with certain settings, Chroma rejects creating another
181+ with different settings in the same process. We clear the cache before and after
182+ this test to avoid conflicts with other tests that use default settings.
183+ """
184+ store = ChromaDocumentStore (client_settings = {"anonymized_telemetry" : False })
185+ store ._ensure_initialized ()
186+ assert store ._client .get_settings ().anonymized_telemetry is False
187+
185188 def test_distance_metric_initialization (self ):
186189 store = ChromaDocumentStore ("test_2" , distance_function = "cosine" )
187190 store ._ensure_initialized ()
@@ -445,7 +448,6 @@ def test_comparison_less_than_equal_with_none(self, document_store, filterable_d
445448 def test_not_operator (self , document_store , filterable_docs ):
446449 pass
447450
448- @pytest .mark .integration
449451 def test_search (self ):
450452 document_store = ChromaDocumentStore ()
451453 documents = [
@@ -491,7 +493,6 @@ def test_delete_all_documents_index_recreation(self, document_store: ChromaDocum
491493 document_store .write_documents (docs )
492494 assert document_store .count_documents () == 2
493495
494- @pytest .mark .integration
495496 def test_search_embeddings (self , document_store : ChromaDocumentStore ):
496497 query_embedding = TEST_EMBEDDING_1
497498 documents = [
@@ -515,6 +516,7 @@ def test_search_embeddings(self, document_store: ChromaDocumentStore):
515516 assert len (result_empty_filters [0 ]) == 2
516517
517518
519+ @pytest .mark .integration
518520class TestMetadataOperations :
519521 """Test new metadata query operations for ChromaDocumentStore"""
520522
0 commit comments