Reject non-finite cosine inputs - #689
Open
shoaib0657 wants to merge 1 commit into
Open
shoaib0657 wants to merge 1 commit into
shoaib0657 wants to merge 1 commit into
Conversation
shoaib0657
marked this pull request as ready for review
October 2, 2026 02:37
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Addresses #687.
Cosine indexes currently accept NaN and infinity, which can produce NaN distances. This checks the converted float32 batch before insertion or search and raises
ValueErrorif any component is non-finite. A rejected insertion batch leaves existing items unchanged.The check covers both
IndexandBFIndex, including finite float64 values that overflow during conversion. L2/IP behavior and normalization arithmetic are unchanged.Regression tests cover single vectors and batches, rejected updates, automatic labels, filters, conversion overflow, strided inputs, zero vectors, and save/load.
Validation
make test: 28 tests passed.make examples: all five examples passed.ctest: 16/16 passed with exceptions ON and OFF.Performance
In a local WSL2 test with 50,000 × 128 float32 vectors and one thread, median BFIndex insertion time increased from 20.36 ms to 22.75 ms. Timings varied, and query measurements were inconclusive.