Add status error output (#22325)

Signed-off-by: lixinguo <xinguo.li@zilliz.com>
Co-authored-by: lixinguo <xinguo.li@zilliz.com>
pull/22366/head
smellthemoon 2023-02-22 15:51:44 +08:00 committed by GitHub
parent 3cb9a44ed8
commit 7a4dfcc72b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 55 additions and 9 deletions

View File

@ -19,6 +19,7 @@
#include "config/ConfigChunkManager.h"
#include "exceptions/EasyAssert.h"
#include "knowhere/dataset.h"
#include "knowhere/expected.h"
namespace milvus {
inline DatasetPtr
@ -123,4 +124,46 @@ PositivelyRelated(const knowhere::MetricType& metric_type) {
return IsMetricType(metric_type, knowhere::metric::IP);
}
inline std::string
MatchKnowhereError(knowhere::Status status) {
switch (status) {
case knowhere::Status::invalid_args:
return "err: invalid args";
case knowhere::Status::invalid_param_in_json:
return "err: invalid param in json";
case knowhere::Status::out_of_range_in_json:
return "err: out of range in json";
case knowhere::Status::type_conflict_in_json:
return "err: type conflict in json";
case knowhere::Status::invalid_metric_type:
return "err: invalid metric type";
case knowhere::Status::empty_index:
return "err: empty index";
case knowhere::Status::not_implemented:
return "err: not implemented";
case knowhere::Status::index_not_trained:
return "err: index not trained";
case knowhere::Status::index_already_trained:
return "err: index already trained";
case knowhere::Status::faiss_inner_error:
return "err: faiss inner error";
case knowhere::Status::annoy_inner_error:
return "err: annoy inner error";
case knowhere::Status::hnsw_inner_error:
return "err: hnsw inner error";
case knowhere::Status::malloc_error:
return "err: malloc error";
case knowhere::Status::diskann_inner_error:
return "err: diskann inner error";
case knowhere::Status::diskann_file_error:
return "err: diskann file error";
case knowhere::Status::invalid_value_in_json:
return "err: invalid value in json";
case knowhere::Status::arithmetic_overflow:
return "err: arithmetic overflow";
default:
return "not match the error type in knowhere";
}
}
} // namespace milvus

View File

@ -161,7 +161,7 @@ VectorDiskAnnIndex<T>::Query(const DatasetPtr dataset, const SearchInfo& search_
} else {
auto res = index_.Search(*dataset, search_config, bitset);
if (!res.has_value()) {
PanicCodeInfo(ErrorCodeEnum::UnexpectedError, "failed to search");
PanicCodeInfo(ErrorCodeEnum::UnexpectedError, "failed to search, " + MatchKnowhereError(res.error()));
}
return res.value();
}

View File

@ -26,6 +26,7 @@
#include "common/Slice.h"
#include "common/Consts.h"
#include "common/RangeSearchHelper.h"
#include "common/Utils.h"
namespace milvus::index {
@ -41,7 +42,7 @@ 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");
PanicCodeInfo(ErrorCodeEnum::UnexpectedError, "failed to serialize index, " + MatchKnowhereError(stat));
milvus::Disassemble(ret);
return ret;
@ -52,7 +53,7 @@ VectorMemIndex::Load(const BinarySet& binary_set, const Config& config) {
milvus::Assemble(const_cast<BinarySet&>(binary_set));
auto stat = index_.Deserialize(binary_set);
if (stat != knowhere::Status::success)
PanicCodeInfo(ErrorCodeEnum::UnexpectedError, "failed to Deserialize index");
PanicCodeInfo(ErrorCodeEnum::UnexpectedError, "failed to Deserialize index, " + MatchKnowhereError(stat));
SetDim(index_.Dim());
}
@ -66,7 +67,7 @@ VectorMemIndex::BuildWithDataset(const DatasetPtr& dataset, const Config& config
knowhere::TimeRecorder rc("BuildWithoutIds", 1);
auto stat = index_.Build(*dataset, index_config);
if (stat != knowhere::Status::success)
PanicCodeInfo(ErrorCodeEnum::BuildIndexError, "failed to build index");
PanicCodeInfo(ErrorCodeEnum::BuildIndexError, "failed to build index, " + MatchKnowhereError(stat));
rc.ElapseFromBegin("Done");
SetDim(index_.Dim());
}
@ -93,7 +94,7 @@ VectorMemIndex::Query(const DatasetPtr dataset, const SearchInfo& search_info, c
} else {
auto res = index_.Search(*dataset, search_conf, bitset);
if (!res.has_value()) {
PanicCodeInfo(ErrorCodeEnum::UnexpectedError, "failed to search");
PanicCodeInfo(ErrorCodeEnum::UnexpectedError, "failed to search, " + MatchKnowhereError(res.error()));
}
return res.value();
}

View File

@ -15,6 +15,7 @@
// limitations under the License.
#include "common/Slice.h"
#include "common/Utils.h"
#include "common/BitsetView.h"
#include "index/VectorMemNMIndex.h"
#include "log/Log.h"
@ -30,7 +31,7 @@ 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");
PanicCodeInfo(ErrorCodeEnum::UnexpectedError, "failed to serialize index, " + MatchKnowhereError(stat));
auto deleter = [&](uint8_t*) {}; // avoid repeated deconstruction
auto raw_data = std::shared_ptr<uint8_t[]>(static_cast<uint8_t*>(raw_data_.data()), deleter);
@ -87,7 +88,7 @@ VectorMemNMIndex::LoadRawData() {
knowhere::BinarySet bs;
auto stat = index_.Serialize(bs);
if (stat != knowhere::Status::success)
PanicCodeInfo(ErrorCodeEnum::UnexpectedError, "failed to Serialize index");
PanicCodeInfo(ErrorCodeEnum::UnexpectedError, "failed to Serialize index, " + MatchKnowhereError(stat));
auto bptr = std::make_shared<knowhere::Binary>();
auto deleter = [&](uint8_t*) {}; // avoid repeated deconstruction
@ -96,7 +97,7 @@ VectorMemNMIndex::LoadRawData() {
bs.Append(RAW_DATA, bptr);
stat = index_.Deserialize(bs);
if (stat != knowhere::Status::success)
PanicCodeInfo(ErrorCodeEnum::UnexpectedError, "failed to Deserialize index");
PanicCodeInfo(ErrorCodeEnum::UnexpectedError, "failed to Deserialize index, " + MatchKnowhereError(stat));
}
} // namespace milvus::index

View File

@ -14,6 +14,7 @@
#include "common/Consts.h"
#include "common/RangeSearchHelper.h"
#include "common/Utils.h"
#include "SearchBruteForce.h"
#include "SubSearchResult.h"
#include "knowhere/comp/brute_force.h"
@ -72,7 +73,7 @@ BruteForceSearch(const dataset::SearchDataset& dataset,
sub_result.mutable_distances().data(), config, bitset);
if (stat != knowhere::Status::success) {
throw std::invalid_argument("invalid metric type");
throw std::invalid_argument("invalid metric type, " + MatchKnowhereError(stat));
}
}
} catch (std::exception& e) {