From 95ed825368d32ede6c8777d157dd75d7127ad31b Mon Sep 17 00:00:00 2001 From: TarunSinghChauhan Date: Tue, 25 Aug 2026 03:08:55 +0000 Subject: [PATCH] Fix score_threshold applied backwards for Recommend/Discover/Context on Euclidean/Manhattan collections In local/in-memory mode, LocalCollection.search() has an isinstance override that correctly treats Recommend (best_score/sum_scores), Discover, and Context queries as bigger-is-better (since they use sigmoid-based synthetic scores), regardless of the collection's underlying distance metric. This override was applied to the sort direction but not repeated for the score_threshold comparison a few lines below, which branched on required_order alone. On a Euclidean or Manhattan collection this caused the threshold check to use the comparison direction meant for raw distances, breaking the loop on the very first (best-scoring) point and returning zero results for any non-extreme threshold. Extracted the override into a single bigger_is_better variable used consistently by both the sort and the threshold check. Fixes #1370. --- qdrant_client/local/local_collection.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/qdrant_client/local/local_collection.py b/qdrant_client/local/local_collection.py index b21c18414..a8c993e63 100644 --- a/qdrant_client/local/local_collection.py +++ b/qdrant_client/local/local_collection.py @@ -697,7 +697,12 @@ def search( required_order = distance_to_order(distance) - if required_order == DistanceOrder.BIGGER_IS_BETTER or isinstance( + # Recommend (best_score/sum_scores), Discover, and Context queries always + # compute a sigmoid-based synthetic score where bigger is always better, + # regardless of the collection's underlying distance metric. This override + # must be applied consistently everywhere required_order is used for these + # query types - both for sort direction and for score_threshold comparison. + bigger_is_better = required_order == DistanceOrder.BIGGER_IS_BETTER or isinstance( query_vector, ( DiscoveryQuery, @@ -707,7 +712,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) @@ -727,7 +734,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: