From 789320a6dffb6cac0867eb32250cd9131eff37a5 Mon Sep 17 00:00:00 2001 From: Tai An Date: Sat, 22 Aug 2026 15:14:54 -0700 Subject: [PATCH] fix(local): compare score_threshold in the query's own score direction Recommend (best_score/sum_scores), discovery and context queries score through a sigmoid, so bigger is always better for them regardless of the collection's distance. The sort order already special-cased these query types on top of distance_to_order(), but the score_threshold comparison a few lines below branched on required_order alone. On a Euclidean or Manhattan collection it therefore cut with the operator meant for raw distances and dropped every point that should have passed. Hoist the decision into a single bigger_is_better flag used by both the sort and the threshold check, so the two cannot drift apart again. --- qdrant_client/local/local_collection.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/qdrant_client/local/local_collection.py b/qdrant_client/local/local_collection.py index 982da298e..527b70bcd 100644 --- a/qdrant_client/local/local_collection.py +++ b/qdrant_client/local/local_collection.py @@ -654,7 +654,10 @@ def search( required_order = distance_to_order(distance) - if required_order == DistanceOrder.BIGGER_IS_BETTER or isinstance( + # Recommend/discovery/context queries score through a sigmoid, so bigger is + # always better for them, whatever the collection's distance is. Both the sort + # order and the score_threshold comparison below have to follow this flag. + bigger_is_better = required_order == DistanceOrder.BIGGER_IS_BETTER or isinstance( query_vector, ( DiscoveryQuery, @@ -664,7 +667,9 @@ def search( MultiContextQuery, MultiRecoQuery, ), # sparse structures are not required, sparse always uses DOT - ): + ) + + if bigger_is_better: order = np.argsort(scores)[::-1] else: order = np.argsort(scores) @@ -684,7 +689,7 @@ def search( point_id = self.ids_inv[idx] if score_threshold is not None: - if required_order == DistanceOrder.BIGGER_IS_BETTER: + if bigger_is_better: if score < score_threshold: break else: