Conversation
…, fix typos, add edge case tests Co-authored-by: bhaktofmahakal <113044681+bhaktofmahakal@users.noreply.github.com>
…es, add near-zero test Co-authored-by: bhaktofmahakal <113044681+bhaktofmahakal@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Analyze codebase and identify system weaknesses
Harden vector core: validate empty/zero-magnitude vectors, fix NaN propagation
Mar 7, 2026
Copilot
AI
changed the title
Harden vector core: validate empty/zero-magnitude vectors, fix NaN propagation
fix(vector-core): harden cosine similarity against zero-magnitude and empty vectors
Mar 7, 2026
…alidation with scalar path Address review feedback from Copilot and Greptile reviewers on PR HelixDB#881: - Change cosine_similarity_avx2 return type from f64 to Result<f64, VectorError> - Add zero/near-zero magnitude check (f64::EPSILON threshold) in AVX2 path - Add NaN/Infinity guard in AVX2 path - Ensures consistent behavior across scalar and SIMD code paths Co-authored-by: bhaktofmahakal <113044681+bhaktofmahakal@users.noreply.github.com>
Copilot
AI
changed the title
fix(vector-core): harden cosine similarity against zero-magnitude and empty vectors
fix(vector-core): harden cosine similarity — input validation, zero-magnitude handling, AVX2 parity
Mar 7, 2026
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.
Description
cosine_similaritysilently returnedOk(-1.0)for zero-magnitude vectors instead of erroring, and the AVX2 path had no validation at all (wrong return type, no magnitude/NaN guards). Empty vectors could be inserted into the HNSW index, propagating NaN through downstream distance calculations.vector_distance.rsErr(InvalidVectorData)(was: proceed to divide-by-zero)Err(InvalidVectorData)viaf64::EPSILONthreshold (was:Ok(-1.0))println!("mis-match in vector dimensions!")cosine_similarity_avx2: changed return typef64→Result<f64, VectorError>, added same magnitude + NaN guards as scalar pathvector_core.rsinsert()andsearch()entry pointsget_all_vectorskey length check:prefix + 16→prefix + 16 + 8(id + level)filter.is_none() || filter.unwrap()...→filter.as_ref().map_or(true, ...)"emtpy"→"empty"(2 occurrences)select_neighborsTests — 12 new edge case tests
test_hvector_distance_maxto use opposite vectors (was zero-magnitude)Related Issues
Checklist when merging to main
rustfmthelix-cli/Cargo.tomlandhelixdb/Cargo.tomlAdditional Notes
The
Cleanup artifactsCI job fails with HTTP 403 — this is a workflow permissions issue in the repo infrastructure, unrelated to these code changes.4 files changed, +125/−42. All 1411 lib tests pass.
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.