From 747cd461980629376df3bdd9e4009cdc1672b733 Mon Sep 17 00:00:00 2001
From: Cai Yudong <yudong.cai@zilliz.com>
Date: Thu, 12 Jan 2023 14:57:36 +0800
Subject: [PATCH] Fix range search benchmark wrong with IP metric type (#632)

Signed-off-by: yudong.cai <yudong.cai@zilliz.com>
---
 unittest/benchmark/benchmark_base.h                      | 1 +
 .../benchmark/hdf5/benchmark_knowhere_float_range.cpp    | 9 +++++++--
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/unittest/benchmark/benchmark_base.h b/unittest/benchmark/benchmark_base.h
index 6b4e9d3be..c76d19127 100644
--- a/unittest/benchmark/benchmark_base.h
+++ b/unittest/benchmark/benchmark_base.h
@@ -24,6 +24,7 @@ class Benchmark_base {
  public:
     inline void
     normalize(float* arr, int32_t nq, int32_t dim) {
+#pragma omp parallel for
         for (int32_t i = 0; i < nq; i++) {
             double vecLen = 0.0, inv_vecLen = 0.0;
             for (int32_t j = 0; j < dim; j++) {
diff --git a/unittest/benchmark/hdf5/benchmark_knowhere_float_range.cpp b/unittest/benchmark/hdf5/benchmark_knowhere_float_range.cpp
index b0b78fa31..9bf5d08d4 100644
--- a/unittest/benchmark/hdf5/benchmark_knowhere_float_range.cpp
+++ b/unittest/benchmark/hdf5/benchmark_knowhere_float_range.cpp
@@ -117,8 +117,13 @@ class Benchmark_knowhere_float_range : public Benchmark_knowhere, public ::testi
         assert(metric_str_ == METRIC_IP_STR || metric_str_ == METRIC_L2_STR);
         metric_type_ = (metric_str_ == METRIC_IP_STR) ? knowhere::metric::IP : knowhere::metric::L2;
         knowhere::SetMetaMetricType(cfg_, metric_type_);
-        knowhere::SetMetaRadiusLowBound(cfg_, 0.0f);
-        knowhere::SetMetaRadiusHighBound(cfg_, *gt_radius_);
+        if (metric_type_ == knowhere::metric::IP) {
+            knowhere::SetMetaRadiusLowBound(cfg_, *gt_radius_);
+            knowhere::SetMetaRadiusHighBound(cfg_, 1.01f);
+        } else {
+            knowhere::SetMetaRadiusLowBound(cfg_, 0.0f);
+            knowhere::SetMetaRadiusHighBound(cfg_, *gt_radius_);
+        }
         knowhere::KnowhereConfig::SetSimdType(knowhere::KnowhereConfig::SimdType::AVX2);
         printf("faiss::distance_compute_blas_threshold: %ld\n", knowhere::KnowhereConfig::GetBlasThreshold());
     }