Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/svsbench/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def search(
search_buffer_optimization: svs.VamanaSearchBufferOptimization = svs.VamanaSearchBufferOptimization.All,
shuffle: bool = False,
seed: int = 42,
) -> tuple[np.ndarray, np.ndarray, float]:
) -> tuple[list[np.ndarray], list[np.ndarray], list[float]]:
logger.info({"search_args": locals()})
logger.info(utils.read_system_config())
if query_path is None:
Expand Down Expand Up @@ -221,6 +221,9 @@ def search(
permutation = np.random.default_rng(seed).permutation(index.size)
ground_truth = np.argsort(permutation)[ground_truth].astype(dtype=dtype, casting="same_value")

results_all = []
distances_all = []
recalls_all = []
for batch_size_idx, batch_size in enumerate(batch_sizes):
index.num_threads = min(max_threads, batch_size)
if search_window_sizes is None:
Expand Down Expand Up @@ -345,7 +348,10 @@ def search(
},
}
)
return results, distances, recall
results_all.append(results)
distances_all.append(distances)
recalls_all.append(recall)
return results_all, distances_all, recalls_all


def main(argv: str | None = None) -> None:
Expand Down
8 changes: 4 additions & 4 deletions tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def test_search(
pytest.skip("Not supported")
if svs_type != index_svs_type:
compress = True
_, _, recall = search(
_, _, recalls = search(
idx_dir=index_dir,
svs_type=svs_type,
distance=svs.DistanceType.L2,
Expand All @@ -43,7 +43,7 @@ def test_search(
load_from_static=not index_dynamic,
)
# Search parameters are calibrated to recall 0.9
assert recall > 0.8
assert recalls[0] > 0.8


def test_search_with_separate_data_dir():
Expand Down Expand Up @@ -71,7 +71,7 @@ def test_search_with_shuffle(tmp_vecs, query_path, tmp_path):
seed=seed,
)
idx_dir = save(build_result[0], tmp_path)
_, _, recall = search(
_, _, recalls = search(
idx_dir=idx_dir,
svs_type=svs_type,
distance=distance,
Expand All @@ -81,4 +81,4 @@ def test_search_with_shuffle(tmp_vecs, query_path, tmp_path):
seed=seed,
)
# Search parameters are calibrated to recall 0.9
assert recall > 0.8
assert recalls[0] > 0.8
Loading