From cb721781f3b99bcdb9c72f5bbd0b741f65e359a7 Mon Sep 17 00:00:00 2001 From: yah01 Date: Tue, 11 Jul 2023 17:26:29 +0800 Subject: [PATCH] Improve error message throwed from knowhere (#25473) Signed-off-by: yah01 --- internal/core/src/common/Utils.h | 40 ++++++++++---------- internal/core/src/index/VectorDiskIndex.cpp | 23 ++++++----- internal/core/src/index/VectorMemIndex.cpp | 25 ++++++------ internal/core/src/index/VectorMemNMIndex.cpp | 12 +++--- internal/core/src/query/SearchBruteForce.cpp | 7 ++-- 5 files changed, 58 insertions(+), 49 deletions(-) diff --git a/internal/core/src/common/Utils.h b/internal/core/src/common/Utils.h index 3c79d77bf7..d90a72deba 100644 --- a/internal/core/src/common/Utils.h +++ b/internal/core/src/common/Utils.h @@ -165,46 +165,46 @@ PositivelyRelated(const knowhere::MetricType& metric_type) { } inline std::string -MatchKnowhereError(knowhere::Status status) { +KnowhereStatusString(knowhere::Status status) { switch (status) { case knowhere::Status::invalid_args: - return "err: invalid args"; + return "invalid args"; case knowhere::Status::invalid_param_in_json: - return "err: invalid param in json"; + return "invalid param in json"; case knowhere::Status::out_of_range_in_json: - return "err: out of range in json"; + return "out of range in json"; case knowhere::Status::type_conflict_in_json: - return "err: type conflict in json"; + return "type conflict in json"; case knowhere::Status::invalid_metric_type: - return "err: invalid metric type"; + return "invalid metric type"; case knowhere::Status::empty_index: - return "err: empty index"; + return "empty index"; case knowhere::Status::not_implemented: - return "err: not implemented"; + return "not implemented"; case knowhere::Status::index_not_trained: - return "err: index not trained"; + return "index not trained"; case knowhere::Status::index_already_trained: - return "err: index already trained"; + return "index already trained"; case knowhere::Status::faiss_inner_error: - return "err: faiss inner error"; + return "faiss inner error"; case knowhere::Status::hnsw_inner_error: - return "err: hnsw inner error"; + return "hnsw inner error"; case knowhere::Status::malloc_error: - return "err: malloc error"; + return "malloc error"; case knowhere::Status::diskann_inner_error: - return "err: diskann inner error"; + return "diskann inner error"; case knowhere::Status::diskann_file_error: - return "err: diskann file error"; + return "diskann file error"; case knowhere::Status::invalid_value_in_json: - return "err: invalid value in json"; + return "invalid value in json"; case knowhere::Status::arithmetic_overflow: - return "err: arithmetic overflow"; + return "arithmetic overflow"; case knowhere::Status::raft_inner_error: - return "err: raft inner error"; + return "raft inner error"; case knowhere::Status::invalid_binary_set: - return "err: invalid binary set"; + return "invalid binary set"; default: - return "not match the error type in knowhere"; + return "unexpected status"; } } diff --git a/internal/core/src/index/VectorDiskIndex.cpp b/internal/core/src/index/VectorDiskIndex.cpp index 1b24cfbfd4..821fc59aac 100644 --- a/internal/core/src/index/VectorDiskIndex.cpp +++ b/internal/core/src/index/VectorDiskIndex.cpp @@ -82,7 +82,7 @@ VectorDiskAnnIndex::Load(const Config& config) { if (stat != knowhere::Status::success) PanicCodeInfo( ErrorCodeEnum::UnexpectedError, - "failed to Deserialize index, " + MatchKnowhereError(stat)); + "failed to Deserialize index, " + KnowhereStatusString(stat)); SetDim(index_.Dim()); } @@ -178,7 +178,7 @@ VectorDiskAnnIndex::BuildWithDataset(const DatasetPtr& dataset, auto stat = index_.Build(*ds_ptr, build_config); if (stat != knowhere::Status::success) PanicCodeInfo(ErrorCodeEnum::BuildIndexError, - "failed to build index, " + MatchKnowhereError(stat)); + "failed to build index, " + KnowhereStatusString(stat)); local_chunk_manager->RemoveDir( storage::GetSegmentRawDataPathPrefix(local_chunk_manager, segment_id)); @@ -235,17 +235,19 @@ VectorDiskAnnIndex::Query(const DatasetPtr dataset, if (!res.has_value()) { PanicCodeInfo(ErrorCodeEnum::UnexpectedError, - "failed to range search, " + - MatchKnowhereError(res.error())); + fmt::format("failed to range search: {}: {}", + KnowhereStatusString(res.error()), + res.what())); } return ReGenRangeSearchResult( res.value(), topk, num_queries, GetMetricType()); } else { auto res = index_.Search(*dataset, search_config, bitset); if (!res.has_value()) { - PanicCodeInfo( - ErrorCodeEnum::UnexpectedError, - "failed to search, " + MatchKnowhereError(res.error())); + PanicCodeInfo(ErrorCodeEnum::UnexpectedError, + fmt::format("failed to search: {}: {}", + KnowhereStatusString(res.error()), + res.what())); } return res.value(); } @@ -287,9 +289,10 @@ std::vector VectorDiskAnnIndex::GetVector(const DatasetPtr dataset) const { auto res = index_.GetVectorByIds(*dataset); if (!res.has_value()) { - PanicCodeInfo( - ErrorCodeEnum::UnexpectedError, - "failed to get vector, " + MatchKnowhereError(res.error())); + PanicCodeInfo(ErrorCodeEnum::UnexpectedError, + fmt::format("failed to get vector: {}: {}", + KnowhereStatusString(res.error()), + res.what())); } auto index_type = GetIndexType(); auto tensor = res.value()->GetTensor(); diff --git a/internal/core/src/index/VectorMemIndex.cpp b/internal/core/src/index/VectorMemIndex.cpp index 7757640baf..e9e08ea0d1 100644 --- a/internal/core/src/index/VectorMemIndex.cpp +++ b/internal/core/src/index/VectorMemIndex.cpp @@ -64,8 +64,9 @@ VectorMemIndex::Serialize(const Config& config) { knowhere::BinarySet ret; auto stat = index_.Serialize(ret); if (stat != knowhere::Status::success) - PanicCodeInfo(ErrorCodeEnum::UnexpectedError, - "failed to serialize index, " + MatchKnowhereError(stat)); + PanicCodeInfo( + ErrorCodeEnum::UnexpectedError, + "failed to serialize index, " + KnowhereStatusString(stat)); Disassemble(ret); return ret; @@ -78,7 +79,7 @@ VectorMemIndex::LoadWithoutAssemble(const BinarySet& binary_set, if (stat != knowhere::Status::success) PanicCodeInfo( ErrorCodeEnum::UnexpectedError, - "failed to Deserialize index, " + MatchKnowhereError(stat)); + "failed to Deserialize index, " + KnowhereStatusString(stat)); SetDim(index_.Dim()); } @@ -119,7 +120,7 @@ VectorMemIndex::BuildWithDataset(const DatasetPtr& dataset, auto stat = index_.Build(*dataset, index_config); if (stat != knowhere::Status::success) PanicCodeInfo(ErrorCodeEnum::BuildIndexError, - "failed to build index, " + MatchKnowhereError(stat)); + "failed to build index, " + KnowhereStatusString(stat)); rc.ElapseFromBegin("Done"); SetDim(index_.Dim()); } @@ -171,7 +172,7 @@ VectorMemIndex::AddWithDataset(const DatasetPtr& dataset, auto stat = index_.Add(*dataset, index_config); if (stat != knowhere::Status::success) PanicCodeInfo(ErrorCodeEnum::BuildIndexError, - "failed to append index, " + MatchKnowhereError(stat)); + "failed to append index, " + KnowhereStatusString(stat)); rc.ElapseFromBegin("Done"); } @@ -199,17 +200,19 @@ VectorMemIndex::Query(const DatasetPtr dataset, auto res = index_.RangeSearch(*dataset, search_conf, bitset); if (!res.has_value()) { PanicCodeInfo(ErrorCodeEnum::UnexpectedError, - "failed to range search, " + - MatchKnowhereError(res.error())); + fmt::format("failed to range search: {}: {}", + KnowhereStatusString(res.error()), + res.what())); } return ReGenRangeSearchResult( res.value(), topk, num_queries, GetMetricType()); } else { auto res = index_.Search(*dataset, search_conf, bitset); if (!res.has_value()) { - PanicCodeInfo( - ErrorCodeEnum::UnexpectedError, - "failed to search, " + MatchKnowhereError(res.error())); + PanicCodeInfo(ErrorCodeEnum::UnexpectedError, + fmt::format("failed to search: {}: {}", + KnowhereStatusString(res.error()), + res.what())); } return res.value(); } @@ -250,7 +253,7 @@ VectorMemIndex::GetVector(const DatasetPtr dataset) const { if (!res.has_value()) { PanicCodeInfo( ErrorCodeEnum::UnexpectedError, - "failed to get vector, " + MatchKnowhereError(res.error())); + "failed to get vector, " + KnowhereStatusString(res.error())); } auto index_type = GetIndexType(); auto tensor = res.value()->GetTensor(); diff --git a/internal/core/src/index/VectorMemNMIndex.cpp b/internal/core/src/index/VectorMemNMIndex.cpp index e7890b5d52..90fee05bb4 100644 --- a/internal/core/src/index/VectorMemNMIndex.cpp +++ b/internal/core/src/index/VectorMemNMIndex.cpp @@ -31,8 +31,9 @@ VectorMemNMIndex::Serialize(const Config& config) { knowhere::BinarySet ret; auto stat = index_.Serialize(ret); if (stat != knowhere::Status::success) - PanicCodeInfo(ErrorCodeEnum::UnexpectedError, - "failed to serialize index, " + MatchKnowhereError(stat)); + PanicCodeInfo( + ErrorCodeEnum::UnexpectedError, + "failed to serialize index, " + KnowhereStatusString(stat)); auto deleter = [&](uint8_t*) {}; // avoid repeated deconstruction auto raw_data = std::shared_ptr( @@ -111,8 +112,9 @@ VectorMemNMIndex::LoadRawData() { knowhere::BinarySet bs; auto stat = index_.Serialize(bs); if (stat != knowhere::Status::success) - PanicCodeInfo(ErrorCodeEnum::UnexpectedError, - "failed to Serialize index, " + MatchKnowhereError(stat)); + PanicCodeInfo( + ErrorCodeEnum::UnexpectedError, + "failed to Serialize index, " + KnowhereStatusString(stat)); auto bptr = std::make_shared(); auto deleter = [&](uint8_t*) {}; // avoid repeated deconstruction @@ -124,7 +126,7 @@ VectorMemNMIndex::LoadRawData() { if (stat != knowhere::Status::success) PanicCodeInfo( ErrorCodeEnum::UnexpectedError, - "failed to Deserialize index, " + MatchKnowhereError(stat)); + "failed to Deserialize index, " + KnowhereStatusString(stat)); } } // namespace milvus::index diff --git a/internal/core/src/query/SearchBruteForce.cpp b/internal/core/src/query/SearchBruteForce.cpp index fb55590b0f..30f9f07fb7 100644 --- a/internal/core/src/query/SearchBruteForce.cpp +++ b/internal/core/src/query/SearchBruteForce.cpp @@ -74,8 +74,9 @@ BruteForceSearch(const dataset::SearchDataset& dataset, if (!res.has_value()) { PanicCodeInfo(ErrorCodeEnum::UnexpectedError, - "failed to range search, " + - MatchKnowhereError(res.error())); + fmt::format("failed to range search: {}: {}", + KnowhereStatusString(res.error()), + res.what())); } auto result = ReGenRangeSearchResult( res.value(), topk, nq, dataset.metric_type); @@ -95,7 +96,7 @@ BruteForceSearch(const dataset::SearchDataset& dataset, if (stat != knowhere::Status::success) { throw std::invalid_argument("invalid metric type, " + - MatchKnowhereError(stat)); + KnowhereStatusString(stat)); } } } catch (std::exception& e) {