Skip to content

Fix overflow warning in nearest neighbors code#755

Merged
benfred merged 1 commit intomainfrom
fix_overflow_warning
May 7, 2026
Merged

Fix overflow warning in nearest neighbors code#755
benfred merged 1 commit intomainfrom
fix_overflow_warning

Conversation

@benfred
Copy link
Copy Markdown
Owner

@benfred benfred commented May 7, 2026

During the unittest we were seeing a warning saying

tests/knn_test.py::BM25Test::test_rank_items_batch
tests/knn_test.py::BM25Test::test_similar_items_filter
tests/knn_test.py::TFIDFTest::test_rank_items_batch
tests/knn_test.py::TFIDFTest::test_similar_items_filter
tests/knn_test.py::CosineTest::test_rank_items_batch
tests/knn_test.py::CosineTest::test_similar_items_filter
  /home/ben/code/implicit/implicit/utils.py:134: RuntimeWarning: overflow encountered in cast
    output_scores[i] = batch_scores[:N]

This is because the _batch_call was generating output in float32, but the KNN models were returning float64 results. Fix.

During the unittest we were seeing a warning saying

```
tests/knn_test.py::BM25Test::test_rank_items_batch
tests/knn_test.py::BM25Test::test_similar_items_filter
tests/knn_test.py::TFIDFTest::test_rank_items_batch
tests/knn_test.py::TFIDFTest::test_similar_items_filter
tests/knn_test.py::CosineTest::test_rank_items_batch
tests/knn_test.py::CosineTest::test_similar_items_filter
  /home/ben/code/implicit/implicit/utils.py:134: RuntimeWarning: overflow encountered in cast
    output_scores[i] = batch_scores[:N]
```

This is because the `_batch_call` was generating output in float32, but the
KNN models were returning float64 results. Fix.
@benfred benfred added the bug label May 7, 2026
@benfred benfred merged commit d3bbdb2 into main May 7, 2026
61 of 89 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant