20
20
import logging
21
21
import random
22
22
import re
23
+ from chromadb .test .utils .wait_for_version_increase import wait_for_version_increase
23
24
24
25
25
26
def _filter_where_clause (clause : Where , metadata : Optional [Metadata ]) -> bool :
@@ -175,18 +176,26 @@ def _filter_embedding_set(
175
176
176
177
177
178
@settings (
179
+ deadline = 90000 ,
178
180
suppress_health_check = [
179
181
HealthCheck .function_scoped_fixture ,
180
182
HealthCheck .large_base_example ,
181
- ]
183
+ HealthCheck .filter_too_much ,
184
+ ],
182
185
) # type: ignore
183
186
@given (
184
187
collection = collection_st ,
185
188
record_set = recordset_st ,
186
189
filters = st .lists (strategies .filters (collection_st , recordset_st ), min_size = 1 ),
190
+ should_compact = st .booleans (),
187
191
)
188
192
def test_filterable_metadata_get (
189
- caplog , api : ServerAPI , collection : strategies .Collection , record_set , filters
193
+ caplog ,
194
+ api : ServerAPI ,
195
+ collection : strategies .Collection ,
196
+ record_set ,
197
+ filters ,
198
+ should_compact : bool ,
190
199
) -> None :
191
200
caplog .set_level (logging .ERROR )
192
201
@@ -197,25 +206,38 @@ def test_filterable_metadata_get(
197
206
embedding_function = collection .embedding_function ,
198
207
)
199
208
209
+ initial_version = coll .get_model ()["version" ]
210
+
200
211
coll .add (** record_set )
212
+
213
+ if not NOT_CLUSTER_ONLY :
214
+ # Only wait for compaction if the size of the collection is
215
+ # some minimal size
216
+ if should_compact and len (invariants .wrap (record_set ["ids" ])) > 10 :
217
+ # Wait for the model to be updated
218
+ wait_for_version_increase (api , collection .name , initial_version )
219
+
201
220
for filter in filters :
202
221
result_ids = coll .get (** filter )["ids" ]
203
222
expected_ids = _filter_embedding_set (record_set , filter )
204
223
assert sorted (result_ids ) == sorted (expected_ids )
205
224
206
225
207
226
@settings (
227
+ deadline = 90000 ,
208
228
suppress_health_check = [
209
229
HealthCheck .function_scoped_fixture ,
210
230
HealthCheck .large_base_example ,
211
- ]
231
+ HealthCheck .filter_too_much ,
232
+ ],
212
233
) # type: ignore
213
234
@given (
214
235
collection = collection_st ,
215
236
record_set = recordset_st ,
216
237
filters = st .lists (strategies .filters (collection_st , recordset_st ), min_size = 1 ),
217
238
limit = st .integers (min_value = 1 , max_value = 10 ),
218
239
offset = st .integers (min_value = 0 , max_value = 10 ),
240
+ should_compact = st .booleans (),
219
241
)
220
242
def test_filterable_metadata_get_limit_offset (
221
243
caplog ,
@@ -225,6 +247,7 @@ def test_filterable_metadata_get_limit_offset(
225
247
filters ,
226
248
limit ,
227
249
offset ,
250
+ should_compact : bool ,
228
251
) -> None :
229
252
caplog .set_level (logging .ERROR )
230
253
@@ -240,7 +263,17 @@ def test_filterable_metadata_get_limit_offset(
240
263
embedding_function = collection .embedding_function ,
241
264
)
242
265
266
+ initial_version = coll .get_model ()["version" ]
267
+
243
268
coll .add (** record_set )
269
+
270
+ if not NOT_CLUSTER_ONLY :
271
+ # Only wait for compaction if the size of the collection is
272
+ # some minimal size
273
+ if should_compact and len (invariants .wrap (record_set ["ids" ])) > 10 :
274
+ # Wait for the model to be updated
275
+ wait_for_version_increase (api , collection .name , initial_version )
276
+
244
277
for filter in filters :
245
278
# add limit and offset to filter
246
279
filter ["limit" ] = limit
@@ -251,10 +284,12 @@ def test_filterable_metadata_get_limit_offset(
251
284
252
285
253
286
@settings (
287
+ deadline = 90000 ,
254
288
suppress_health_check = [
255
289
HealthCheck .function_scoped_fixture ,
256
290
HealthCheck .large_base_example ,
257
- ]
291
+ HealthCheck .filter_too_much ,
292
+ ],
258
293
)
259
294
@given (
260
295
collection = collection_st ,
@@ -263,13 +298,15 @@ def test_filterable_metadata_get_limit_offset(
263
298
strategies .filters (collection_st , recordset_st , include_all_ids = True ),
264
299
min_size = 1 ,
265
300
),
301
+ should_compact = st .booleans (),
266
302
)
267
303
def test_filterable_metadata_query (
268
304
caplog : pytest .LogCaptureFixture ,
269
305
api : ServerAPI ,
270
306
collection : strategies .Collection ,
271
307
record_set : strategies .RecordSet ,
272
308
filters : List [strategies .Filter ],
309
+ should_compact : bool ,
273
310
) -> None :
274
311
caplog .set_level (logging .ERROR )
275
312
@@ -279,9 +316,18 @@ def test_filterable_metadata_query(
279
316
metadata = collection .metadata , # type: ignore
280
317
embedding_function = collection .embedding_function ,
281
318
)
319
+ initial_version = coll .get_model ()["version" ]
282
320
normalized_record_set = invariants .wrap_all (record_set )
283
321
284
322
coll .add (** record_set )
323
+
324
+ if not NOT_CLUSTER_ONLY :
325
+ # Only wait for compaction if the size of the collection is
326
+ # some minimal size
327
+ if should_compact and len (invariants .wrap (record_set ["ids" ])) > 10 :
328
+ # Wait for the model to be updated
329
+ wait_for_version_increase (api , collection .name , initial_version )
330
+
285
331
total_count = len (normalized_record_set ["ids" ])
286
332
# Pick a random vector
287
333
random_query : Embedding
0 commit comments