Skip to content

Commit

Permalink
Throw an exception when there are not k elements
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszsmolinski committed Oct 30, 2023
1 parent 333eaeb commit 76f5aff
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions python_bindings/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,9 @@ class BFIndex {
ParallelFor(0, rows, num_threads, [&](size_t row, size_t threadId) {
std::priority_queue<std::pair<dist_t, hnswlib::labeltype >> result = alg->searchKnn(
(void*)items.data(row), k, p_idFilter);
if (result.size() != k)
throw std::runtime_error(
"Cannot return the results in a contiguous 2D array. There are not enough elements.");
for (int i = k - 1; i >= 0; i--) {
auto& result_tuple = result.top();
data_numpy_d[row * k + i] = result_tuple.first;
Expand Down

0 comments on commit 76f5aff

Please sign in to comment.