Skip to content

Fix DBSF reversing ranking order for Euclidean distance metrics (#10611) - #10620

Open
Anurag-M1 wants to merge 1 commit into
qdrant:devfrom
Anurag-M1:fix/dbsf-euclidean-metric-order
Open

Anurag-M1 wants to merge 1 commit into
qdrant:devfrom
Anurag-M1:fix/dbsf-euclidean-metric-order

Conversation

@Anurag-M1

Copy link
Copy Markdown

All Submissions:

  • My PR targets the dev branch (not master) and my branch was created from dev.
  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?

Changes to Core Features:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you successfully ran tests with your changes locally?

Description

Fixes #10611

When fusing scores from multiple retrievers with Distribution-Based Score Fusion (DBSF), normalization (distr_norm and min_max_norm) was previously computed as $(s - min) / (max - min)$, implicitly assuming that higher raw scores always mean better similarity (Order::LargeBetter).

For distance metrics such as Euclidean (L2) or Manhattan, smaller values indicate closer/better points (Order::SmallBetter). Normalizing with $(s - min) / (max - min)$ inverted the score ordering: points with the lowest distance (best match) received normalized scores near 0.0, while the farthest points received scores near 1.0. Consequently, fusing identical Euclidean retrievers completely reversed the result ranking order (the worst point became top-1).

Key Changes:

  1. lib/segment/src/common/score_fusion.rs:

    • Added source_orders: Vec<Order> support to ScoreFusion with constructor ScoreFusion::dbsf_with_orders(...).
    • Updated normalization routines (norm, min_max_norm, distr_norm) to accept the source metric Order.
    • When Order::SmallBetter, scores are normalized inversely as $(max - score) / (max - min)$ so closer points correctly receive normalized scores approaching 1.0.
    • Added automatic fallback order detection in score_fusion: if explicit source_orders are not supplied, inspects whether the input list is ascending (first.score < last.score), as Qdrant searches return results pre-sorted best-to-worst.
    • Added comprehensive unit tests:
      • test_dbsf_euclid_identical_retrievers: verifies that fusing identical Euclidean score lists preserves ranking order.
      • test_dbsf_small_better_ordering: verifies single and multi-point normalization for Order::SmallBetter.
      • test_dbsf_hybrid_large_and_small_better: verifies hybrid fusion between Order::LargeBetter (cosine/dot) and Order::SmallBetter (Euclidean).
      • test_min_max_norm_small_better: unit tests for min_max_norm under both orderings.
  2. lib/collection/src/collection/query.rs:

    • In intermediates_to_final_list, resolved prefetch source orders via shard_query::query_result_order(prefetch.query.as_ref(), &collection_params).
    • Passed resolved source_orders to ScoreFusion::dbsf_with_orders(source_orders) when Fusion::Dbsf is invoked.

Verification

  • cargo test -p segment -- common::score_fusion: 5/5 unit tests passed.
  • cargo clippy -p segment -p collection -- -D warnings: passed with 0 warnings.
  • Code formatted with rustfmt (--edition 2024).

…nt#10611)

DBSF (Distribution-Based Score Fusion) normalized scores assuming higher scores are always better (Order::LargeBetter). For distance metrics where smaller values indicate closer matches (Order::SmallBetter, such as Euclidean and Manhattan), this inverted relative score magnitudes and reversed result rankings, violating search idempotence when fusing identical retrievers.

- Update ScoreFusion to support source-level source_orders.
- Make norm, min_max_norm, and distr_norm aware of Order::SmallBetter, inverting score normalization to map closest distances to high normalized scores.
- Automatically infer Order::SmallBetter when source results are ordered ascending.
- Propagate prefetch metric orders in collection query fusion.
- Add unit tests reproducing the identical Euclidean retriever fusion and hybrid scoring.

Closes qdrant#10611.
@coderabbitai

coderabbitai Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: CHILL

Plan: Advanced

Run ID: 307c8562-dcce-43b1-ac47-f8d70a69a5a1

📥 Commits

Reviewing files that changed from the base of the PR and between 17a0747 and 4e3539d.

📒 Files selected for processing (2)
  • lib/collection/src/collection/query.rs
  • lib/segment/src/common/score_fusion.rs

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

DBSF now tracks the ordering direction of each prefetch result. Collection queries derive these orders from query configuration and pass them to ScoreFusion. Normalization preserves LargeBetter ordering and inverts scores for SmallBetter metrics. Tests cover explicit and inferred orders, Euclidean fusion, hybrid metrics, and min-max normalization.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: generall

Merge Risk: ⚪ Minimal · up to 4e353

The metric-order wiring preserves Euclidean distance ordering for reachable configured vector queries, with no unresolved merge-blocking risk identified.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 72.73% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 11 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: fixing DBSF ranking reversal for Euclidean distance metrics.
Description check ✅ Passed The description directly explains the DBSF normalization issue, the metric-order changes, affected files, tests, and verification results.
Linked Issues check ✅ Passed Issue #10611 requires DBSF to preserve the ranking of identical Euclidean retrievers and support mixed metric directions. ScoreFusion now accepts per-source Order values, inverts normalization for…
Out of Scope Changes check ✅ Passed The changes stay within Issue #10611. They modify DBSF normalization, propagate metric order from collection prefetches, and add tests for the affected fusion behavior. No unrelated product behavior i…
  • Fix all pre-merge checks with AI

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

I’m a rabbit with scores in a row
Small distances now properly glow
DBSF keeps the trail
No rankings derail
And fused points hop where they should go

Comment @coderabbitai help to get the list of available commands.

@qdrant-cloud-bot qdrant-cloud-bot added the area/segment lib/segment — storage, vector & payload index internals label Sep 28, 2026
@lorenzozanee lorenzozanee mentioned this pull request Oct 2, 2026
4 of 6 tasks

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/segment lib/segment — storage, vector & payload index internals

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants