Skip to content

Fix L2Distance() return value in vector search query executed with index only optimization - #105495

Merged
alexey-milovidov merged 3 commits into
ClickHouse:masterfrom
shankar-iyer:fix_l2distance
May 31, 2026
Merged

alexey-milovidov merged 3 commits into
ClickHouse:masterfrom
shankar-iyer:fix_l2distance

Conversation

@shankar-iyer

@shankar-iyer shankar-iyer commented May 21, 2026 •

Copy link
Copy Markdown
Member

Resolves #102480

Changelog category

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry

  • A vector search query executed with the index only optimization now returns the correct value for L2Distance() if it is in the SELECT list. The function was incorrectly returning the L2-squared distance value. Note that the vector search query was returning the correctly ranked results, only applications explicitly retrieving and interpreting the L2Distance() value would have seen the squared value.

Version info

  • Merged into: 26.6.1.282

@shankar-iyer shankar-iyer changed the title Fix l2distance Fix L2Distance() return value in vector search query executed with index only optimization May 21, 2026
@clickhouse-gh

clickhouse-gh Bot commented May 21, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [7757c90]

Summary: ✅


AI Review

Summary

This PR fixes index-only vector search so L2Distance in the SELECT/ORDER BY path returns Euclidean distance (by applying sqrt to _distance), and it updates/adds stateless tests to verify the corrected values across rescoring modes and vector types. I did not find unresolved correctness, safety, or performance issues in the current diff.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label May 21, 2026
@shankar-iyer
shankar-iyer requested a review from rschu1ze May 21, 2026 09:26
@clickhouse-gh

clickhouse-gh Bot commented May 21, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.10% 84.10% +0.00%
Functions 91.40% 91.40% +0.00%
Branches 76.50% 76.50% +0.00%

Changed lines: 100.00% (11/11) · Uncovered code

Full report · Diff report

@shankar-iyer

Copy link
Copy Markdown
Member Author

Clean CI run!

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue May 31, 2026
Merged via the queue into ClickHouse:master with commit 9e14e12 May 31, 2026
327 of 328 checks passed
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label May 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-bugfix Pull request with bugfix, not backported by default pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

L2Distance returns squared L2 distance instead of Euclidean distance when rescoring optimization is active

4 participants