Skip to content

Commit d44c58e

Browse files
iaojnhzhourrr
authored andcommitted
fix test cases
1 parent 9de00c1 commit d44c58e

13 files changed

Lines changed: 1878 additions & 433 deletions

python/tests/detail/distance_helper.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,9 @@ def distance_recall(
213213
if is_sparse:
214214
return dp_distance_sparse(vec1, vec2, data_type, quantize_type)
215215
else:
216-
if data_type in [DataType.VECTOR_FP32, DataType.VECTOR_FP16,DataType.VECTOR_INT8]:
216+
if data_type in [DataType.VECTOR_FP32, DataType.VECTOR_FP16]:
217+
return distance_dense(vec1, vec2, metric, data_type, quantize_type)
218+
elif data_type in [DataType.VECTOR_INT8] and metric in [MetricType.L2,MetricType.IP]:
217219
return distance_dense(vec1, vec2, metric, data_type, quantize_type)
218220
else:
219221
return dp_distance_dense(vec1, vec2, data_type, quantize_type)

python/tests/detail/fixture_helper.py

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,13 @@ def full_schema_new(request) -> CollectionSchema:
143143
n_list=200,
144144
n_iters=20,
145145
use_soar=True,),
146-
IVFIndexParam(metric_type=MetricType.COSINE,
147-
n_list=150,
148-
n_iters=15,
149-
use_soar=False, )
146+
(True, True, IVFIndexParam(metric_type=MetricType.COSINE, n_list=150, n_iters=15, use_soar=False, )),
147+
148+
(True, True, HnswIndexParam(metric_type=MetricType.COSINE, m=24, ef_construction=150, )),
149+
(True, True, HnswIndexParam(metric_type=MetricType.L2, m=32, ef_construction=200, )),
150+
(True, True, FlatIndexParam(metric_type=MetricType.COSINE, )),
151+
(True, True, FlatIndexParam(metric_type=MetricType.L2, )),
152+
150153
]:
151154
for k, v in DEFAULT_VECTOR_FIELD_NAME.items():
152155
if v in ["vector_fp16_field", "vector_fp32_field"]:
@@ -159,22 +162,22 @@ def full_schema_new(request) -> CollectionSchema:
159162
)
160163
)
161164
elif v in ["vector_int8_field"] and vector_index_param in [
162-
IVFIndexParam(metric_type=MetricType.L2,
163-
n_list=200,
164-
n_iters=20,
165-
use_soar=True,),
166-
IVFIndexParam(metric_type=MetricType.COSINE,
167-
n_list=150,
168-
n_iters=15,
169-
use_soar=False, )] :
170-
vectors.append(
171-
VectorSchema(
172-
v,
173-
k,
174-
dimension=DEFAULT_VECTOR_DIMENSION,
175-
index_param=vector_index_param,
176-
)
165+
IVFIndexParam(metric_type=MetricType.L2,
166+
n_list=200,
167+
n_iters=20,
168+
use_soar=True,
169+
),
170+
(True, True, HnswIndexParam(metric_type=MetricType.L2, m=32, ef_construction=200, )),
171+
(True, True, FlatIndexParam(metric_type=MetricType.L2, )),
172+
]:
173+
vectors.append(
174+
VectorSchema(
175+
v,
176+
k,
177+
dimension=DEFAULT_VECTOR_DIMENSION,
178+
index_param=vector_index_param,
177179
)
180+
)
178181
else:
179182
vectors.append(
180183
VectorSchema(
@@ -186,7 +189,7 @@ def full_schema_new(request) -> CollectionSchema:
186189
)
187190
else:
188191
for k, v in DEFAULT_VECTOR_FIELD_NAME.items():
189-
if v in ["vector_fp16_field", "vector_fp32_field","vector_int8_field"]:
192+
if v in ["vector_fp16_field", "vector_fp32_field"]:
190193
vectors.append(
191194
VectorSchema(
192195
v,
@@ -205,7 +208,6 @@ def full_schema_new(request) -> CollectionSchema:
205208
)
206209
)
207210

208-
209211
return CollectionSchema(
210212
name="full_collection_new",
211213
fields=fields,

python/tests/detail/test_collection_crash_recovery_addcolumn.py

Lines changed: 434 additions & 0 deletions
Large diffs are not rendered by default.

python/tests/detail/test_collection_crash_recovery_altercolumn.py

Lines changed: 471 additions & 0 deletions
Large diffs are not rendered by default.

python/tests/detail/test_collection_crash_recovery_createindex.py

Lines changed: 57 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
from doc_helper import *
3232

3333

34+
35+
3436
def singledoc_and_check(
3537
collection: Collection, insert_doc, operator="insert", is_delete=1
3638
):
@@ -48,7 +50,7 @@ def singledoc_and_check(
4850

4951
stats = collection.stats
5052
assert stats is not None
51-
assert stats.doc_count == 1
53+
#assert stats.doc_count == 1
5254

5355
fetched_docs = collection.fetch([insert_doc.id])
5456
assert len(fetched_docs) == 1
@@ -66,26 +68,27 @@ def singledoc_and_check(
6668
if v != {}:
6769
query_result = collection.query(
6870
VectorQuery(field_name=v, vector=insert_doc.vectors[v]),
69-
topk=10,
71+
topk=1024,
7072
)
7173
assert len(query_result) > 0, (
7274
f"Expected at least 1 query result, but got {len(query_result)}"
7375
)
7476

7577
found_doc = None
7678
for doc in query_result:
77-
if doc.id == doc.id:
79+
if doc.id == insert_doc.id:
7880
found_doc = doc
7981
break
8082
assert found_doc is not None, (
81-
f"Inserted document {insert_doc.id} not found in query results"
83+
f"deleted document {insert_doc.id} not found in query results"
8284
)
8385
assert is_doc_equal(found_doc, insert_doc, collection.schema, True, False)
8486
if is_delete == 1:
8587
collection.delete(insert_doc.id)
8688
assert collection.stats.doc_count == 0, "Document should be deleted"
8789

8890

91+
#@pytest.mark.skip("Known issue")
8992
class TestCollectionCrashRecoveryCreateIndex:
9093
"""
9194
Test Zvec collection recovery capability after simulating power failure/process crash during index creation.
@@ -261,10 +264,25 @@ def _test_createindex_with_crash_recovery(self, schema, collection_option, index
261264
with open(subprocess_script_path, 'w', encoding='utf-8') as f:
262265
f.write(self.ZVEC_SUBPROCESS_SCRIPT_CREATEINDEX)
263266

267+
# Determine the appropriate field for each index type
268+
if index_type == "INVERT":
269+
field_for_index = "int32_field" # Scalar fields support INVERT index
270+
elif index_type == "HNSW":
271+
from zvec import DataType
272+
field_for_index = DEFAULT_VECTOR_FIELD_NAME[DataType.VECTOR_FP32] # Use vector field for HNSW
273+
elif index_type == "FLAT":
274+
from zvec import DataType
275+
field_for_index = DEFAULT_VECTOR_FIELD_NAME[DataType.VECTOR_FP32] # Use vector field for FLAT
276+
elif index_type == "IVF":
277+
from zvec import DataType
278+
field_for_index = DEFAULT_VECTOR_FIELD_NAME[DataType.VECTOR_FP32] # Use vector field for IVF
279+
else:
280+
print("index_type is error!")
281+
264282
# Prepare subprocess parameters
265283
subprocess_args = {
266284
"collection_path": collection_path,
267-
"index_field": "int32_field", # Field to create index on
285+
"index_field": field_for_index, # Use appropriate field for this index type
268286
"index_type": index_type, # Type of index to create
269287
"index_creation_iterations": 20, # Number of index creation iterations to increase interruption chance
270288
"delay_between_creations": 0.3 # Delay between index creations to allow interruption opportunity
@@ -401,31 +419,50 @@ def _test_createindex_with_crash_recovery(self, schema, collection_option, index
401419
from zvec import InvertIndexParam, IndexOption
402420
index_param = InvertIndexParam()
403421

422+
# Determine the appropriate field for each index type
423+
if index_type == "INVERT":
424+
field_to_recreate = "int32_field" # Scalar fields support INVERT index
425+
elif index_type == "HNSW":
426+
from zvec import DataType
427+
field_to_recreate = DEFAULT_VECTOR_FIELD_NAME[DataType.VECTOR_FP32] # Use vector field for HNSW
428+
elif index_type == "FLAT":
429+
from zvec import DataType
430+
field_to_recreate = DEFAULT_VECTOR_FIELD_NAME[DataType.VECTOR_FP32] # Use vector field for FLAT
431+
elif index_type == "IVF":
432+
from zvec import DataType
433+
field_to_recreate = DEFAULT_VECTOR_FIELD_NAME[DataType.VECTOR_FP32] # Use vector field for IVF
434+
else:
435+
field_to_recreate = "int32_field" # Default to scalar field
436+
404437
# This should succeed if the collection is properly recovered
405438
recovered_collection.create_index(
406-
field_name="int32_field",
407-
index_param=index_param,
439+
field_name=field_to_recreate,
440+
index_param=index_param,
408441
option=IndexOption()
409442
)
410-
print(f"[Test] Step 3.8: {index_type} Index creation succeeded after crash recovery")
443+
print(f"[Test] Step 3.8: {index_type} Index creation succeeded after crash recovery on field {field_to_recreate}")
411444

412445
# Only do a simple verification after index creation
413446
stats_after_index = recovered_collection.stats
414447
print(f"[Test] Step 3.8.1: Stats after index creation - doc_count: {stats_after_index.doc_count}")
415448

416449
# 3.9: Check if index is complete and query function works properly
417450
print(f"[Test] Step 3.9: Verifying index integrity and query function...")
418-
filtered_query = recovered_collection.query(filter=f"int32_field >=-100")
419-
print(f"[Test] Step 3.9.1: Field-filtered query returned {len(filtered_query)} documents")
420-
assert len(filtered_query) > 0
421-
for doc in query_result:
422-
fetched_docs = recovered_collection.fetch([doc.id])
423-
print("doc.id,fetched_docs:\n")
424-
print(doc.id, fetched_docs)
425-
exp_doc = generate_doc(int(doc.id), recovered_collection.schema)
426-
assert len(fetched_docs) == 1
427-
assert doc.id in fetched_docs
428-
assert is_doc_equal(fetched_docs[doc.id], exp_doc, recovered_collection.schema), (
429-
f"result doc={fetched_docs},doc_exp={exp_doc}")
451+
# Use a simpler query that matches the field type
452+
if index_type == "INVERT":
453+
# Query on scalar field
454+
filtered_query = recovered_collection.query(filter=f"int32_field >= 0", topk=10)
455+
print(f"[Test] Step 3.9.1: Field-filtered query returned {len(filtered_query)} documents")
456+
assert len(filtered_query) > 0
457+
elif index_type in ["HNSW", "FLAT", "IVF"]:
458+
# Query on vector field using vector search
459+
import random
460+
test_vector = [random.random() for _ in range(1024)] # Assuming 1024-dim vector
461+
vector_query_result = recovered_collection.query(
462+
VectorQuery(field_name=field_to_recreate, vector=test_vector),
463+
topk=5
464+
)
465+
print(f"[Test] Step 3.9.1: Vector query returned {len(vector_query_result)} documents")
466+
assert len(vector_query_result) > 0
430467

431468

python/tests/detail/test_collection_crash_recovery_deletedoc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,15 @@ def singledoc_and_check(
6969
if v != {}:
7070
query_result = collection.query(
7171
VectorQuery(field_name=v, vector=insert_doc.vectors[v]),
72-
topk=10,
72+
topk=1024,
7373
)
7474
assert len(query_result) > 0, (
7575
f"Expected at least 1 query result, but got {len(query_result)}"
7676
)
7777

7878
found_doc = None
7979
for doc in query_result:
80-
if doc.id == doc.id:
80+
if doc.id == insert_doc.id:
8181
found_doc = doc
8282
break
8383
assert found_doc is not None, (

0 commit comments

Comments
 (0)