fix precision for segcore reduce(#27325) (#28062)

Signed-off-by: MrPresent-Han <chun.han@zilliz.com>
This commit is contained in:
MrPresent-Han 2023-11-01 21:52:13 +08:00 committed by GitHub
parent af8ea0f3af
commit 854c0e8a16
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -44,7 +44,10 @@ struct SearchResultPair {
bool bool
operator>(const SearchResultPair& other) const { 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 primary_key_ < other.primary_key_;
} }
return distance_ > other.distance_; return distance_ > other.distance_;