Skip to content

fix(linalg): correct multivector distance aggregation - #8710

Merged
yanghua merged 2 commits into
lance-format:mainfrom
ddupg:fix/ddu-348-multivec-distance
Aug 30, 2026
Merged

fix(linalg): correct multivector distance aggregation#8710
yanghua merged 2 commits into
lance-format:mainfrom
ddupg:fix/ddu-348-multivec-distance

Conversation

@ddupg

@ddupg ddupg commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Background

While implementing distributed batch vector search in lance-ray#5263, I compared the indexed and flat search paths in Lance Core and found that they used different multivector distance baselines.

For a query with M sub-vectors, the indexed path used:

M - sum(max similarity)

while the flat path used:

1 - sum(max similarity)

The results therefore differed by M - 1; for example, a perfect match with M = 2 returned 0 from the indexed path but -1 from the flat path.

Changes

  • For float metrics, directly compute distance(Q, V) = sum_i min_j d(q_i, v_j).
  • For Hamming, use the same aggregation, distance(Q, V) = sum_i min_j hamming(q_i, v_j), without an outer 1 - ... conversion.
  • Add unit and end-to-end coverage for flat, indexed, and partially indexed search paths.

Testing

  • cargo test -p lance-linalg
  • test_multivec_ann and test_multivec_search_paths

@github-actions github-actions Bot added A-python Python bindings A-index Vector index, linalg, tokenizer bug Something isn't working labels Aug 24, 2026
@ddupg
ddupg force-pushed the fix/ddu-348-multivec-distance branch from 0d63488 to 33ededc Compare August 24, 2026 04:31
@ddupg
ddupg marked this pull request as ready for review August 24, 2026 04:31
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Aug 24, 2026
@codecov

codecov Bot commented Aug 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@ddupg
ddupg force-pushed the fix/ddu-348-multivec-distance branch from 33ededc to 13a3068 Compare August 25, 2026 08:19
@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Aug 25, 2026
@ddupg
ddupg force-pushed the fix/ddu-348-multivec-distance branch from 13a3068 to eb48602 Compare August 25, 2026 08:22

@lance-gatekeeper lance-gatekeeper Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gate recommendation: approve.

This preserves the additive late-interaction contract by summing each query sub-vector’s nearest stored-vector distance. That directly matches indexed scoring, corrects Hamming ordering, and is cleaner than retaining metric-specific similarity baselines. The regression covers flat, partially indexed, and fully indexed search paths.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Aug 25, 2026

@yanghua yanghua left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@yanghua
yanghua merged commit f603c55 into lance-format:main Aug 30, 2026
35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-index Vector index, linalg, tokenizer A-python Python bindings bug Something isn't working K-approved Latest Gatekeeper recommendation permits acceptance.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants