mirror of
https://gitee.com/milvus-io/milvus.git
synced 2026-01-07 19:31:51 +08:00
Improve error message throwed from knowhere (#25473)
Signed-off-by: yah01 <yang.cen@zilliz.com>
This commit is contained in:
parent
96c987ed62
commit
cb721781f3
@ -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";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -82,7 +82,7 @@ VectorDiskAnnIndex<T>::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<T>::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<T>::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<uint8_t>
|
||||
VectorDiskAnnIndex<T>::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();
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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<uint8_t[]>(
|
||||
@ -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<knowhere::Binary>();
|
||||
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
|
||||
|
||||
@ -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) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user