From 8b25ecffff6837bcbd7646b02c422c26a0e47c29 Mon Sep 17 00:00:00 2001 From: zhagnlu <1542303831@qq.com> Date: Fri, 1 Mar 2024 18:09:02 +0800 Subject: [PATCH] fix: add pk sort for same distance of hybridsearch (#30901) #29923 Signed-off-by: luzhang Co-authored-by: luzhang --- internal/proxy/task_hybrid_search.go | 16 ++++++++++++++++ tests/python_client/testcases/test_search.py | 1 - 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/internal/proxy/task_hybrid_search.go b/internal/proxy/task_hybrid_search.go index 4c8b4cc74f..b4146684e9 100644 --- a/internal/proxy/task_hybrid_search.go +++ b/internal/proxy/task_hybrid_search.go @@ -551,14 +551,30 @@ func rankSearchResultData(ctx context.Context, continue } + compareKeys := func(keyI, keyJ interface{}) bool { + switch keyI.(type) { + case int64: + return keyI.(int64) < keyJ.(int64) + case string: + return keyI.(string) < keyJ.(string) + } + return false + } + // sort id by score var less func(i, j int) bool if metric.PositivelyRelated(metricType) { less = func(i, j int) bool { + if idSet[keys[i]] == idSet[keys[j]] { + return compareKeys(keys[i], keys[j]) + } return idSet[keys[i]] > idSet[keys[j]] } } else { less = func(i, j int) bool { + if idSet[keys[i]] == idSet[keys[j]] { + return compareKeys(keys[i], keys[j]) + } return idSet[keys[i]] < idSet[keys[j]] } } diff --git a/tests/python_client/testcases/test_search.py b/tests/python_client/testcases/test_search.py index bc6a5623c5..2204c34025 100644 --- a/tests/python_client/testcases/test_search.py +++ b/tests/python_client/testcases/test_search.py @@ -11035,7 +11035,6 @@ class TestCollectionHybridSearchValid(TestcaseBase): @pytest.mark.tags(CaseLabel.L1) @pytest.mark.parametrize("primary_field", [ct.default_int64_field_name, ct.default_string_field_name]) - @pytest.mark.xfail(reason="issue 29923") def test_hybrid_search_RRFRanker_default_parameter(self, primary_field): """ target: test hybrid search with default value to RRFRanker