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: