This is an automated email from the ASF dual-hosted git repository.
JingsongLi pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/paimon-rust.git
The following commit(s) were added to refs/heads/main by this push:
new 599cbd35 [core] Preserve score order when fusing hybrid ranks (#1489)
599cbd35 is described below
commit 599cbd35c09b23108388c35e6482369a94bfb472
Author: Jingsong Lee <[email protected]>
AuthorDate: Sun Nov 22 10:24:09 2026 +0800
[core] Preserve score order when fusing hybrid ranks (#1489)
---
crates/paimon/src/table/hybrid_search_builder.rs | 20 +++++++++++++++-----
1 file changed, 15 insertions(+), 5 deletions(-)
diff --git a/crates/paimon/src/table/hybrid_search_builder.rs
b/crates/paimon/src/table/hybrid_search_builder.rs
index 0cfbe7c6..dab23db5 100644
--- a/crates/paimon/src/table/hybrid_search_builder.rs
+++ b/crates/paimon/src/table/hybrid_search_builder.rs
@@ -1382,7 +1382,7 @@ fn ranked_row_ids(result: &ScoredRowIds) -> Vec<(u64,
f32)> {
best_scores
.entry(row_id)
.and_modify(|old: &mut f32| {
- if score > *old {
+ if score.total_cmp(old).is_gt() {
*old = score;
}
})
@@ -1392,8 +1392,7 @@ fn ranked_row_ids(result: &ScoredRowIds) -> Vec<(u64,
f32)> {
let mut ranked: Vec<_> = best_scores.into_iter().collect();
ranked.sort_by(|(left_id, left_score), (right_id, right_score)| {
right_score
- .partial_cmp(left_score)
- .unwrap_or(std::cmp::Ordering::Equal)
+ .total_cmp(left_score)
.then_with(|| left_id.cmp(right_id))
});
ranked
@@ -1414,8 +1413,7 @@ fn top_k(scores: HashMap<u64, f32>, limit: usize) ->
ScoredRowIds {
let mut entries: Vec<_> = scores.into_iter().collect();
entries.sort_by(|(left_id, left_score), (right_id, right_score)| {
right_score
- .partial_cmp(left_score)
- .unwrap_or(std::cmp::Ordering::Equal)
+ .total_cmp(left_score)
.then_with(|| left_id.cmp(right_id))
});
entries.truncate(limit);
@@ -1449,6 +1447,18 @@ mod tests {
assert_eq!(ranked.row_ids, vec![2]);
}
+ #[test]
+ fn rank_based_fusion_preserves_vector_top_k_score_order() {
+ let route = route_result(vec![1, 2, 3], vec![-0.0, 0.0, 0.0], 1.0);
+ let expected = route.result.top_k(1).row_ids;
+ assert_eq!(expected, vec![2]);
+
+ for ranker in [HybridSearchRanker::Rrf, HybridSearchRanker::Mrr] {
+ let ranked = rank_results(ranker, std::slice::from_ref(&route), 1);
+ assert_eq!(ranked.row_ids, expected);
+ }
+ }
+
#[test]
fn test_weighted_score_min_max_normalizes_per_route() {
let ranked = rank_results(