From 854c0e8a16baffcaa67867b9f5c146c138971101 Mon Sep 17 00:00:00 2001 From: MrPresent-Han <116052805+MrPresent-Han@users.noreply.github.com> Date: Wed, 1 Nov 2023 21:52:13 +0800 Subject: [PATCH] fix precision for segcore reduce(#27325) (#28062) Signed-off-by: MrPresent-Han --- internal/core/src/segcore/ReduceStructure.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/internal/core/src/segcore/ReduceStructure.h b/internal/core/src/segcore/ReduceStructure.h index 96956f006f..48655f2aa7 100644 --- a/internal/core/src/segcore/ReduceStructure.h +++ b/internal/core/src/segcore/ReduceStructure.h @@ -44,7 +44,10 @@ struct SearchResultPair { bool operator>(const SearchResultPair& other) const { - if (std::fabs(distance_ - other.distance_) < 0.000001f) { + //according to FLT_EPSILON in cfloat, 0.000000119 is the maximum flaw for float32 + //we use this to differentiate distances that are too close to each other to maintain the + //stable order for reduce + if (std::fabs(distance_ - other.distance_) < 0.000000119) { return primary_key_ < other.primary_key_; } return distance_ > other.distance_;