Skip to content

Commit 2c9fe4f

Browse files
author
Dmitry Yashunin
committed
Add warning that python filter works slow in multi-threaded mode
1 parent 978f713 commit 2c9fe4f

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

python_bindings/bindings.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,10 @@ class Index {
611611
if (num_threads <= 0)
612612
num_threads = num_threads_default;
613613

614+
if ((filter != nullptr) && (num_threads != 1)) {
615+
std::cout << "Warning: search with python filter works slow in multi-threaded mode. For best performance set num_threads=1\n";
616+
}
617+
614618
{
615619
py::gil_scoped_release l;
616620
get_input_array_shapes(buffer, &rows, &features);

python_bindings/tests/bindings_test_filter.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ def testRandomSelf(self):
4747
print("Querying only even elements")
4848
# Query the even elements for themselves and measure recall:
4949
filter_function = lambda id: id%2 == 0
50-
labels, distances = hnsw_index.knn_query(data, k=1, filter=filter_function)
50+
# Search with python filter works slow in multi-threaded mode, therefore we set num_threads=1
51+
labels, distances = hnsw_index.knn_query(data, k=1, filter=filter_function, num_threads=1)
5152
self.assertAlmostEqual(np.mean(labels.reshape(-1) == np.arange(len(data))), .5, 3)
5253
# Verify that there are only even elements:
5354
self.assertTrue(np.max(np.mod(labels, 2)) == 0)

0 commit comments

Comments
 (0)