From 690f0fcb7768a06301cf8b804680b86a947c252f Mon Sep 17 00:00:00 2001 From: Leo <75311991+leo062644@users.noreply.github.com> Date: Wed, 11 Nov 2026 00:28:47 +0800 Subject: [PATCH 1/2] test(python): migrate index count tests to the 0.8 API --- tests/python/test_index_counts.py | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/tests/python/test_index_counts.py b/tests/python/test_index_counts.py index a9448d9a..8e4004e7 100644 --- a/tests/python/test_index_counts.py +++ b/tests/python/test_index_counts.py @@ -18,7 +18,7 @@ def check_counts(index, capacity, stored, active): @pytest.mark.parametrize( "kind,bits", [("ivf", 1), ("ivf", 4), ("ivf", 32), ("hnsw", 1), ("hnsw", 9)] - + [("symqg", bits) for bits in (0, 4, 8)], + + [("symqg", bits) for bits in (32, 4, 8)], ) def test_count_contract_through_lifecycle(tmp_path, kind, bits): metric = "l2" @@ -28,20 +28,27 @@ def test_count_contract_through_lifecycle(tmp_path, kind, bits): centroid = np.zeros((1, dim), np.float32) assignments = np.zeros(count + 4, np.uint32) if kind == "ivf": - index = IvfIndex(dim, count, 1, bits, metric=metric) - capacity = count + index = IvfIndex(dim, 1, nbits=bits, metric=metric) + capacity = 0 elif kind == "hnsw": - index = HnswIndex(dim, 64, M=8, ef_construction=40, nbits=bits, metric=metric) + index = HnswIndex( + dim, num_clusters=1, M=8, ef_construction=40, nbits=bits, metric=metric + ) + index.resize(64) capacity = 64 else: - index = SymqgIndex(dim, max_degree=32, quantization_bits=bits, metric=metric) + index = SymqgIndex( + dim, max_degree=32, ef_construction=40, nbits=bits, metric=metric + ) capacity = 0 check_counts(index, capacity, 0, 0) if kind == "symqg": - index.build(data[:count], ef_construction=40, num_threads=1) - capacity = count + index.add(data[:count], num_threads=1) else: - index.build(data[:count], centroid, assignments[:count]) + index.set_centroids(centroid) + index.add(data[:count], cluster_ids=assignments[:count], num_threads=1) + if kind != "hnsw": + capacity = count check_counts(index, capacity, count, count) path = tmp_path / "counts.index" @@ -66,7 +73,7 @@ def test_count_contract_through_lifecycle(tmp_path, kind, bits): capacity = 80 check_counts(index, capacity, count, count - 3) - ids = index.add(data[count : count + 3], assignments[:3]) + ids = index.add(data[count : count + 3], cluster_ids=assignments[:3], num_threads=1) np.testing.assert_array_equal(ids, np.arange(count, count + 3)) stored = count + 3 if kind == "ivf": @@ -87,7 +94,9 @@ def test_count_contract_through_lifecycle(tmp_path, kind, bits): hits, _ = index.search(data[:1], k=1, **args) assert np.all(hits == np.iinfo(np.uint32).max) - np.testing.assert_array_equal(index.add(data[-1:], assignments[:1]), [stored]) + np.testing.assert_array_equal( + index.add(data[-1:], cluster_ids=assignments[:1], num_threads=1), [stored] + ) stored += 1 if kind == "ivf": capacity = stored From 86814a916ed6dcb6fb8aff00e07e9ed1f25a6152 Mon Sep 17 00:00:00 2001 From: Leo <75311991+leo062644@users.noreply.github.com> Date: Wed, 11 Nov 2026 12:57:00 +0800 Subject: [PATCH 2/2] test(python): apply index-count review suggestions Keep default threading for the two later add calls and place capacity updates in their respective initialization branches. --- tests/python/test_index_counts.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/python/test_index_counts.py b/tests/python/test_index_counts.py index 8e4004e7..fc48a184 100644 --- a/tests/python/test_index_counts.py +++ b/tests/python/test_index_counts.py @@ -44,11 +44,12 @@ def test_count_contract_through_lifecycle(tmp_path, kind, bits): check_counts(index, capacity, 0, 0) if kind == "symqg": index.add(data[:count], num_threads=1) + capacity = count else: index.set_centroids(centroid) index.add(data[:count], cluster_ids=assignments[:count], num_threads=1) - if kind != "hnsw": - capacity = count + if kind == "ivf": + capacity = count check_counts(index, capacity, count, count) path = tmp_path / "counts.index" @@ -73,7 +74,7 @@ def test_count_contract_through_lifecycle(tmp_path, kind, bits): capacity = 80 check_counts(index, capacity, count, count - 3) - ids = index.add(data[count : count + 3], cluster_ids=assignments[:3], num_threads=1) + ids = index.add(data[count : count + 3], cluster_ids=assignments[:3]) np.testing.assert_array_equal(ids, np.arange(count, count + 3)) stored = count + 3 if kind == "ivf": @@ -95,7 +96,7 @@ def test_count_contract_through_lifecycle(tmp_path, kind, bits): assert np.all(hits == np.iinfo(np.uint32).max) np.testing.assert_array_equal( - index.add(data[-1:], cluster_ids=assignments[:1], num_threads=1), [stored] + index.add(data[-1:], cluster_ids=assignments[:1]), [stored] ) stored += 1 if kind == "ivf":