Skip to content

Commit 76f5aff

Browse files
Throw an exception when there are not k elements
1 parent 333eaeb commit 76f5aff

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

python_bindings/bindings.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,9 @@ class BFIndex {
874874
ParallelFor(0, rows, num_threads, [&](size_t row, size_t threadId) {
875875
std::priority_queue<std::pair<dist_t, hnswlib::labeltype >> result = alg->searchKnn(
876876
(void*)items.data(row), k, p_idFilter);
877+
if (result.size() != k)
878+
throw std::runtime_error(
879+
"Cannot return the results in a contiguous 2D array. There are not enough elements.");
877880
for (int i = k - 1; i >= 0; i--) {
878881
auto& result_tuple = result.top();
879882
data_numpy_d[row * k + i] = result_tuple.first;

0 commit comments

Comments
 (0)