From cf999b68dd813ec1c600891ba9e6e4144dd8d258 Mon Sep 17 00:00:00 2001 From: smellthemoon <64083300+smellthemoon@users.noreply.github.com> Date: Fri, 24 Feb 2023 17:59:45 +0800 Subject: [PATCH] Fix range search can not get status from knowhere (#22384) Signed-off-by: lixinguo Co-authored-by: lixinguo --- internal/core/src/common/Consts.h | 6 ++++-- internal/core/src/index/VectorDiskIndex.cpp | 5 +++++ internal/core/src/index/VectorMemIndex.cpp | 4 ++++ internal/core/src/query/SearchBruteForce.cpp | 14 +++++++++----- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/internal/core/src/common/Consts.h b/internal/core/src/common/Consts.h index 62c431b95..e8b5b569e 100644 --- a/internal/core/src/common/Consts.h +++ b/internal/core/src/common/Consts.h @@ -19,6 +19,8 @@ #include #include "Types.h" +#include "knowhere/comp/index_param.h" + const int64_t INVALID_FIELD_ID = -1; const int64_t INVALID_SEG_OFFSET = -1; const milvus::PkType INVALID_PK; // of std::monostate if not set. @@ -44,5 +46,5 @@ const int64_t DEFAULT_INDEX_FILE_SLICE_SIZE = 4; // megabytes const int DEFAULT_CPU_NUM = 1; -constexpr const char* RADIUS = "radius"; -constexpr const char* RANGE_FILTER = "range_filter"; +constexpr const char* RADIUS = knowhere::meta::RADIUS; +constexpr const char* RANGE_FILTER = knowhere::meta::RANGE_FILTER; diff --git a/internal/core/src/index/VectorDiskIndex.cpp b/internal/core/src/index/VectorDiskIndex.cpp index 55293996b..6c1a618c5 100644 --- a/internal/core/src/index/VectorDiskIndex.cpp +++ b/internal/core/src/index/VectorDiskIndex.cpp @@ -157,6 +157,11 @@ VectorDiskAnnIndex::Query(const DatasetPtr dataset, const SearchInfo& search_ CheckRangeSearchParam(search_config[RADIUS], search_config[RANGE_FILTER], GetMetricType()); } auto res = index_.RangeSearch(*dataset, search_config, bitset); + + if (!res.has_value()) { + PanicCodeInfo(ErrorCodeEnum::UnexpectedError, + "failed to range search, " + MatchKnowhereError(res.error())); + } return SortRangeSearchResult(res.value(), topk, num_queries, GetMetricType()); } else { auto res = index_.Search(*dataset, search_config, bitset); diff --git a/internal/core/src/index/VectorMemIndex.cpp b/internal/core/src/index/VectorMemIndex.cpp index 53c95f696..6ab4a527a 100644 --- a/internal/core/src/index/VectorMemIndex.cpp +++ b/internal/core/src/index/VectorMemIndex.cpp @@ -90,6 +90,10 @@ VectorMemIndex::Query(const DatasetPtr dataset, const SearchInfo& search_info, c CheckRangeSearchParam(search_conf[RADIUS], search_conf[RANGE_FILTER], GetMetricType()); } auto res = index_.RangeSearch(*dataset, search_conf, bitset); + if (!res.has_value()) { + PanicCodeInfo(ErrorCodeEnum::UnexpectedError, + "failed to range search, " + MatchKnowhereError(res.error())); + } return SortRangeSearchResult(res.value(), topk, num_queries, GetMetricType()); } else { auto res = index_.Search(*dataset, search_conf, bitset); diff --git a/internal/core/src/query/SearchBruteForce.cpp b/internal/core/src/query/SearchBruteForce.cpp index 13a9b9e11..765294dae 100644 --- a/internal/core/src/query/SearchBruteForce.cpp +++ b/internal/core/src/query/SearchBruteForce.cpp @@ -57,14 +57,18 @@ BruteForceSearch(const dataset::SearchDataset& dataset, sub_result.mutable_distances().resize(nq * topk); if (conf.contains(RADIUS)) { - config[RADIUS] = conf[RADIUS]; + config[RADIUS] = conf[RADIUS].get(); if (conf.contains(RANGE_FILTER)) { - config[RANGE_FILTER] = conf[RANGE_FILTER]; + config[RANGE_FILTER] = conf[RANGE_FILTER].get(); CheckRangeSearchParam(config[RADIUS], config[RANGE_FILTER], dataset.metric_type); } - auto result = SortRangeSearchResult( - knowhere::BruteForce::RangeSearch(base_dataset, query_dataset, config, bitset).value(), topk, nq, - dataset.metric_type); + auto res = knowhere::BruteForce::RangeSearch(base_dataset, query_dataset, config, bitset); + + if (!res.has_value()) { + PanicCodeInfo(ErrorCodeEnum::UnexpectedError, + "failed to range search, " + MatchKnowhereError(res.error())); + } + auto result = SortRangeSearchResult(res.value(), topk, nq, dataset.metric_type); std::copy_n(GetDatasetIDs(result), nq * topk, sub_result.get_seg_offsets()); std::copy_n(GetDatasetDistance(result), nq * topk, sub_result.get_distances()); } else { -- GitLab