Skip to content

Handle zero vectors in quantized codecs to prevent crashes during merge and search#16100

Open
iprithv wants to merge 2 commits into
apache:mainfrom
iprithv:fix-quantized-zero-vector
Open

Handle zero vectors in quantized codecs to prevent crashes during merge and search#16100
iprithv wants to merge 2 commits into
apache:mainfrom
iprithv:fix-quantized-zero-vector

Conversation

@iprithv
Copy link
Copy Markdown
Contributor

@iprithv iprithv commented May 21, 2026

Quantized vector codecs (Lucene104ScalarQuantizedVectorsFormat) crash on zero vectors with COSINE similarity, fixed it!

This fixes division-by-zero and assertion failures when zero vectors
are indexed with COSINE similarity in scalar-quantized codecs:

- Add magnitude > 0 guard in normalizeVectors() to skip division for zero vectors
- Add divisor > 0 guard in addValue() to avoid adding NaN to dimensionSums
- Pass throwOnZero=false to all l2normalize() calls in quantized codec paths
- Relax isUnitVector assertions to allow zero vectors in scalarQuantize()
- Add test verifying merge + search works with zero vectors in quantized format

Fixes apache#15540
@github-actions github-actions Bot added this to the 11.0.0 milestone May 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant