Skip to content

Conversation

@meiravgri
Copy link
Collaborator

@meiravgri meiravgri commented Jan 8, 2026

Extended the L2 query blob to include both y_sum (sum of query values) and y_sum_squares (sum of squared query values) to support asymmetric L2 distance computation.

Motivation

L2 squared distance is computed as:

||x - y||² = Σx_i² - 2 * IP(x, y) + Σy_i²

Where the inner product with a quantized storage vector is:

IP(x, y) = min * y_sum + delta * Σ(q_i * y_i)

The y_sum term is required to compute IP(x, y), which in turn is needed for the L2 distance formula. Previously only y_sum_squares was stored in the query blob.

Changes

Query blob layout update for L2:

  • Before: | query_values[dim] | y_sum_squares |
  • After: | query_values[dim] | y_sum | y_sum_squares |

Query blob size for L2:

  • Before: (dim + 1) * sizeof(DataType)
  • After: (dim + 2) * sizeof(DataType)

Code improvements:

  • Merged sum_fast() and sum_squares_fast() into a single assign_query_metadata() function
  • Single pass over the query vector instead of two passes for L2
  • Uses 4-accumulator loop unrolling for performance
  • Added sq8::SUM_QUERY and sq8::SUM_SQUARES_QUERY metadata indices

Files Modified

  • src/VecSim/spaces/computer/preprocessors.h
  • src/VecSim/types/sq8.h

Notes

  • IP/Cosine query blob layout remains unchanged: | query_values[dim] | y_sum |

@meiravgri meiravgri changed the title Extended the L2 query blob to include both y_sum MOD-13451 Add pre-computed sum to L2 query blob in QuantPreprocessor Jan 8, 2026
@meiravgri meiravgri requested a review from dor-forer January 8, 2026 10:43
@codecov
Copy link

codecov bot commented Jan 8, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.13%. Comparing base (51d5247) to head (165d6bf).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #883   +/-   ##
=======================================
  Coverage   97.13%   97.13%           
=======================================
  Files         129      129           
  Lines        7611     7614    +3     
=======================================
+ Hits         7393     7396    +3     
  Misses        218      218           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@meiravgri meiravgri enabled auto-merge January 8, 2026 11:16
@meiravgri meiravgri added this pull request to the merge queue Jan 8, 2026
Merged via the queue into main with commit f6df960 Jan 8, 2026
18 checks passed
@meiravgri meiravgri deleted the meiravg_add_sum_to_l2 branch January 8, 2026 11:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants