chore: switch core tools to LOG_ERROR instead of cerr for better traceability when errors occur (#80)
This commit is contained in:
parent
1e09d0d34c
commit
2bfeac5034
|
|
@ -66,7 +66,7 @@ class Bench {
|
|||
|
||||
if (!reader.load_query(query_file, first_sep, second_sep, queries,
|
||||
sparse_data, taglists)) {
|
||||
cerr << "Load query error" << endl;
|
||||
LOG_ERROR("Load query error");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -134,7 +134,7 @@ class Bench {
|
|||
} else if (typeid(T) == typeid(int8_t)) {
|
||||
qmeta_.set_meta(IndexMeta::DataType::DT_INT8, dim_);
|
||||
} else {
|
||||
cerr << "unsupported type";
|
||||
LOG_ERROR("unsupported type");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -195,14 +195,14 @@ class Bench {
|
|||
std::shared_ptr<IndexFilter> filter_ptr = nullptr;
|
||||
if (filter_mode_ == FM_TAG) {
|
||||
if (batch_taglists_[idx].size() != 1) {
|
||||
cerr << "query tag list not equal to one!" << endl;
|
||||
LOG_ERROR("query tag list not equal to one!");
|
||||
return;
|
||||
}
|
||||
|
||||
int ret = filter_cache.filter(id_to_tags_list_, batch_taglists_[idx][0],
|
||||
tag_key_list_);
|
||||
if (ret != 0) {
|
||||
cerr << "prefilter failed, idx: " << idx << std::endl;
|
||||
LOG_ERROR("prefilter failed, idx: %d", idx);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -227,13 +227,13 @@ class Bench {
|
|||
}
|
||||
|
||||
if (ret != 0) {
|
||||
cerr << "Failed to knn search, ret=" << ret << " "
|
||||
<< IndexError::What(ret) << endl;
|
||||
LOG_ERROR("Failed to knn search, ret=%d %s", ret,
|
||||
IndexError::What(ret));
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
std::string mode = retrieval_mode_ == 1 ? "Dense" : "Sparse";
|
||||
cerr << "unsupported retrieval mode: " << mode << endl;
|
||||
LOG_ERROR("unsupported retrieval mode: %s", mode.c_str());
|
||||
}
|
||||
|
||||
uint64_t end = Monotime::MicroSeconds();
|
||||
|
|
@ -262,7 +262,7 @@ class Bench {
|
|||
}
|
||||
|
||||
if (search_result.doc_list_.empty()) {
|
||||
cerr << "Search results is empty" << endl;
|
||||
LOG_ERROR("Search results is empty");
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
@ -291,7 +291,7 @@ class Bench {
|
|||
}
|
||||
|
||||
if (search_result.doc_list_.empty()) {
|
||||
cerr << "Search results is empty for batch query " << i << endl;
|
||||
LOG_ERROR("Search results is empty for batch query %zu", i);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -370,7 +370,7 @@ class SparseBench {
|
|||
|
||||
if (!reader.load_query(query_file, first_sep, second_sep, queries,
|
||||
sparse_data, taglists)) {
|
||||
cerr << "Load query error" << endl;
|
||||
LOG_ERROR("Load query error");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -431,7 +431,7 @@ class SparseBench {
|
|||
} else if (typeid(T) == typeid(int8_t)) {
|
||||
qmeta_.set_data_type(IndexMeta::DataType::DT_INT8);
|
||||
} else {
|
||||
cerr << "unsupported type";
|
||||
LOG_ERROR("unsupported type");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -494,14 +494,14 @@ class SparseBench {
|
|||
std::shared_ptr<IndexFilter> filter_ptr = nullptr;
|
||||
if (filter_mode_ == FM_TAG) {
|
||||
if (batch_taglists_[idx].size() != 1) {
|
||||
cerr << "query tag list not equal to one!" << endl;
|
||||
LOG_ERROR("query tag list not equal to one!");
|
||||
return;
|
||||
}
|
||||
|
||||
int ret = filter_cache.filter(id_to_tags_list_, batch_taglists_[idx][0],
|
||||
tag_key_list_);
|
||||
if (ret != 0) {
|
||||
cerr << "prefilter failed, idx: " << idx << std::endl;
|
||||
LOG_ERROR("prefilter failed, idx: %d", idx);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -519,8 +519,7 @@ class SparseBench {
|
|||
int ret;
|
||||
if (batch_count_ == 1) {
|
||||
if (batch_sparse_counts_[idx].size() != 1) {
|
||||
cerr << "Sparse count size should be 1, since batch count is 1"
|
||||
<< endl;
|
||||
LOG_ERROR("Sparse count size should be 1, since batch count is 1");
|
||||
return;
|
||||
}
|
||||
ret = do_knn_search<T>(index, batch_sparse_counts_[idx][0],
|
||||
|
|
@ -533,8 +532,8 @@ class SparseBench {
|
|||
}
|
||||
|
||||
if (ret != 0) {
|
||||
cerr << "Failed to sparse knn search, ret=" << ret << " "
|
||||
<< IndexError::What(ret) << endl;
|
||||
LOG_ERROR("Failed to sparse knn search, ret=%d %s", ret,
|
||||
IndexError::What(ret));
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -567,7 +566,7 @@ class SparseBench {
|
|||
}
|
||||
|
||||
if (search_result.doc_list_.empty()) {
|
||||
cerr << "Search results is empty" << endl;
|
||||
LOG_ERROR("Search results is empty");
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
@ -617,7 +616,7 @@ class SparseBench {
|
|||
}
|
||||
|
||||
if (search_result.doc_list_.empty()) {
|
||||
cerr << "Search results is empty for batch query " << i << endl;
|
||||
LOG_ERROR("Search results is empty for batch query %zu", i);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -666,33 +665,33 @@ bool SparseBench<T>::STOP_NOW = false;
|
|||
bool check_config(YAML::Node &config_node) {
|
||||
auto common = config_node["IndexCommon"];
|
||||
if (!common) {
|
||||
cerr << "Can not find [IndexCommon] in config" << endl;
|
||||
LOG_ERROR("Can not find [IndexCommon] in config");
|
||||
return false;
|
||||
}
|
||||
if (!common["IndexConfig"]) {
|
||||
cerr << "Can not find [IndexConfig] in config" << endl;
|
||||
LOG_ERROR("Can not find [IndexConfig] in config");
|
||||
return false;
|
||||
}
|
||||
if (!common["IndexPath"]) {
|
||||
cerr << "Can not find [IndexPath] in config" << endl;
|
||||
LOG_ERROR("Can not find [IndexPath] in config");
|
||||
return false;
|
||||
}
|
||||
if (!common["TopK"]) {
|
||||
cerr << "Can not find [TopK] in config" << endl;
|
||||
LOG_ERROR("Can not find [TopK] in config");
|
||||
return false;
|
||||
}
|
||||
if (!common["QueryFile"]) {
|
||||
cerr << "Can not find [QueryFile] in config" << endl;
|
||||
LOG_ERROR("Can not find [QueryFile] in config");
|
||||
return false;
|
||||
}
|
||||
|
||||
auto query_config = config_node["QueryConfig"];
|
||||
if (!query_config) {
|
||||
cerr << "Can not find [QueryConfig] in config" << endl;
|
||||
LOG_ERROR("Can not find [QueryConfig] in config");
|
||||
return false;
|
||||
}
|
||||
if (!query_config["QueryParam"]) {
|
||||
cerr << "Can not find [QueryConfig.QueryParam] in config" << endl;
|
||||
LOG_ERROR("Can not find [QueryConfig.QueryParam] in config");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -713,7 +712,7 @@ int bench(std::string &query_type, size_t thread_count, size_t batch_count,
|
|||
string &index_dir, RetrievalMode retrieval_mode,
|
||||
FilterMode filter_mode) {
|
||||
if (filter_mode == FM_TAG && batch_count > 1) {
|
||||
cerr << "filter mode can not be run in batch mode" << endl;
|
||||
LOG_ERROR("filter mode can not be run in batch mode");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -747,7 +746,7 @@ int bench(std::string &query_type, size_t thread_count, size_t batch_count,
|
|||
bench.set_tag_lists(id_to_tags_list, tag_key_list);
|
||||
bench.run(index, query_param, iter_count, top_k);
|
||||
} else {
|
||||
cerr << "Can not recognize type: " << query_type << endl;
|
||||
LOG_ERROR("Can not recognize type: %s", query_type.c_str());
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
@ -760,7 +759,7 @@ int bench_sparse(std::string &query_type, size_t thread_count,
|
|||
core_interface::BaseIndexQueryParam::Pointer query_param,
|
||||
string &index_dir, FilterMode filter_mode) {
|
||||
if (filter_mode == FM_TAG && batch_count > 1) {
|
||||
cerr << "filter mode can not be run in batch mode" << endl;
|
||||
LOG_ERROR("filter mode can not be run in batch mode");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -782,7 +781,7 @@ int bench_sparse(std::string &query_type, size_t thread_count,
|
|||
bench.set_tag_lists(id_to_tags_list, tag_key_list);
|
||||
bench.run(index, query_param, iter_count, top_k);
|
||||
} else {
|
||||
cerr << "Can not recognize type: " << query_type << endl;
|
||||
LOG_ERROR("Can not recognize type: %s", query_type.c_str());
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
@ -798,8 +797,7 @@ int main(int argc, char *argv[]) {
|
|||
std::string error;
|
||||
for (int i = 2; i < argc; ++i) {
|
||||
if (!broker.emplace(argv[i], &error)) {
|
||||
cerr << "Failed to load plugin: " << argv[i] << " (" << error << ")"
|
||||
<< endl;
|
||||
LOG_ERROR("Failed to load plugin: %s (%s)", argv[i], error.c_str());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
|
@ -808,7 +806,7 @@ int main(int argc, char *argv[]) {
|
|||
try {
|
||||
config_node = YAML::LoadFile(argv[1]);
|
||||
} catch (...) {
|
||||
cerr << "Load YAML file[" << argv[1] << "] failed!" << endl;
|
||||
LOG_ERROR("Load YAML file[%s] failed!", argv[1]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -888,7 +886,7 @@ int main(int argc, char *argv[]) {
|
|||
core_interface::BaseIndexQueryParam::Pointer query_param;
|
||||
if (0 !=
|
||||
parse_and_load_index_param(config_node, index_dir, index, query_param)) {
|
||||
cerr << "Failed to parse and load index param" << endl;
|
||||
LOG_ERROR("Failed to parse and load index param");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
#include <zvec/ailego/utility/time_helper.h>
|
||||
#include "algorithm/flat/flat_utility.h"
|
||||
#include "algorithm/hnsw/hnsw_params.h"
|
||||
#include "zvec/ailego/logger/logger.h"
|
||||
#include "zvec/core/framework/index_dumper.h"
|
||||
#include "zvec/core/framework/index_factory.h"
|
||||
#include "zvec/core/framework/index_logger.h"
|
||||
|
|
@ -101,8 +102,8 @@ bool prepare_params(YAML::Node &&config_params, ailego::Params ¶ms) {
|
|||
ailego::Params sub_params;
|
||||
auto sub_node = it->second;
|
||||
if (!prepare_params(std::move(sub_node), sub_params)) {
|
||||
cerr << "parse params error with key[" << it->first.as<string>()
|
||||
<< "]" << endl;
|
||||
LOG_ERROR("parse params error with key[%s]",
|
||||
it->first.as<string>().c_str());
|
||||
return false;
|
||||
}
|
||||
params.set(it->first.as<string>(), sub_params);
|
||||
|
|
@ -115,39 +116,39 @@ bool prepare_params(YAML::Node &&config_params, ailego::Params ¶ms) {
|
|||
bool check_config(YAML::Node &config_root) {
|
||||
auto common = config_root["BuilderCommon"];
|
||||
if (!common) {
|
||||
cerr << "Can not find [BuilderClass] in config" << endl;
|
||||
LOG_ERROR("Can not find [BuilderClass] in config");
|
||||
return false;
|
||||
}
|
||||
if (!common["BuilderClass"]) {
|
||||
cerr << "Can not find [BuilderClass] in config" << endl;
|
||||
LOG_ERROR("Can not find [BuilderClass] in config");
|
||||
return false;
|
||||
}
|
||||
if (!common["BuildFile"]) {
|
||||
cerr << "Can not find [BuildFile] in config" << endl;
|
||||
LOG_ERROR("Can not find [BuildFile] in config");
|
||||
return false;
|
||||
}
|
||||
if (common["NeedTrain"] && common["NeedTrain"].as<bool>()) {
|
||||
if (!common["TrainFile"]) {
|
||||
cerr << "Can not find [TrainFile] in config" << endl;
|
||||
LOG_ERROR("Can not find [TrainFile] in config");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (common["UseTrainer"]) {
|
||||
if (!common["TrainerIndexPath"]) {
|
||||
cerr << "Can not find [TrainerIndexPath] in config" << endl;
|
||||
LOG_ERROR("Can not find [TrainerIndexPath] in config");
|
||||
return false;
|
||||
}
|
||||
if (!config_root["TrainerParams"]) {
|
||||
cerr << "Can not find [TrainerParams] in config" << endl;
|
||||
LOG_ERROR("Can not find [TrainerParams] in config");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (!common["DumpPath"]) {
|
||||
cerr << "Can not find [DumpPath] in config" << endl;
|
||||
LOG_ERROR("Can not find [DumpPath] in config");
|
||||
return false;
|
||||
}
|
||||
if (!config_root["BuilderParams"]) {
|
||||
cerr << "Can not find [BuilderParams] in config" << endl;
|
||||
LOG_ERROR("Can not find [BuilderParams] in config");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
|
@ -277,7 +278,7 @@ int do_build_sparse_by_streamer(IndexStreamer::Pointer &streamer,
|
|||
auto ctx = streamer->create_context();
|
||||
if (!ctx) {
|
||||
if (!error.exchange(true)) {
|
||||
cerr << "Failed to create streamer context";
|
||||
LOG_ERROR("Failed to create streamer context");
|
||||
errcode = IndexError_NoMemory;
|
||||
}
|
||||
return;
|
||||
|
|
@ -342,14 +343,14 @@ int do_build_sparse_by_streamer(IndexStreamer::Pointer &streamer,
|
|||
cond.wait_until(
|
||||
lk, std::chrono::system_clock::now() + std::chrono::seconds(15));
|
||||
if (error.load(std::memory_order_acquire)) {
|
||||
cerr << "Failed to build index while waiting finish\n";
|
||||
LOG_ERROR("Failed to build index while waiting finish");
|
||||
return errcode;
|
||||
}
|
||||
LOG_INFO("Built cnt %zu, finished percent %.3f%%", finished.load(),
|
||||
finished.load() * 100.0f / sparse_holder->count());
|
||||
}
|
||||
if (error.load(std::memory_order_acquire)) {
|
||||
cerr << "Failed to build index while waiting finish\n";
|
||||
LOG_ERROR("Failed to build index while waiting finish");
|
||||
return errcode;
|
||||
}
|
||||
pool.wait_finish();
|
||||
|
|
@ -360,30 +361,30 @@ int do_build_sparse_by_streamer(IndexStreamer::Pointer &streamer,
|
|||
int build_sparse_by_streamer(IndexStreamer::Pointer &streamer,
|
||||
YAML::Node &config_common) {
|
||||
if (!config_common["IndexPath"]) {
|
||||
cerr << "Miss params IndexPath for Streamer\n";
|
||||
LOG_ERROR("Miss params IndexPath for Streamer");
|
||||
return IndexError_InvalidArgument;
|
||||
}
|
||||
string path = config_common["IndexPath"].as<string>();
|
||||
|
||||
auto storage = IndexFactory::CreateStorage("MMapFileStorage");
|
||||
if (!storage) {
|
||||
cerr << "Failed to create storage\n";
|
||||
LOG_ERROR("Failed to create storage");
|
||||
return IndexError_NoExist;
|
||||
}
|
||||
ailego::Params params;
|
||||
int ret = storage->init(params);
|
||||
if (ret != 0) {
|
||||
cerr << "Storage Failed init" << endl;
|
||||
LOG_ERROR("Storage Failed init");
|
||||
return IndexError_Runtime;
|
||||
}
|
||||
ret = storage->open(path, true);
|
||||
if (ret != 0) {
|
||||
cerr << "Storage Failed to open" << endl;
|
||||
LOG_ERROR("Storage Failed to open");
|
||||
return IndexError_Runtime;
|
||||
}
|
||||
ret = streamer->open(storage);
|
||||
if (ret != 0) {
|
||||
cerr << "Failed to open storage" << endl;
|
||||
LOG_ERROR("Failed to open storage");
|
||||
return IndexError_Runtime;
|
||||
}
|
||||
|
||||
|
|
@ -413,7 +414,7 @@ int do_build_by_streamer(IndexStreamer::Pointer &streamer,
|
|||
IndexReformer::Pointer reformer;
|
||||
if (!meta.reformer_name().empty()) {
|
||||
if (retrieval_mode != RM_DENSE) {
|
||||
cerr << "Reformer not supported";
|
||||
LOG_ERROR("Reformer not supported");
|
||||
return IndexError_Runtime;
|
||||
} else {
|
||||
reformer = IndexFactory::CreateReformer(meta.reformer_name());
|
||||
|
|
@ -452,7 +453,7 @@ int do_build_by_streamer(IndexStreamer::Pointer &streamer,
|
|||
auto ctx = streamer->create_context();
|
||||
if (!ctx) {
|
||||
if (!error.exchange(true)) {
|
||||
cerr << "Failed to create streamer context";
|
||||
LOG_ERROR("Failed to create streamer context");
|
||||
errcode = IndexError_NoMemory;
|
||||
}
|
||||
return;
|
||||
|
|
@ -475,14 +476,14 @@ int do_build_by_streamer(IndexStreamer::Pointer &streamer,
|
|||
ret = add_to_streamer(key, holder->get_vector(id), qmeta, ctx);
|
||||
}
|
||||
} else {
|
||||
cerr << "Retrieval mode not supported";
|
||||
LOG_ERROR("Retrieval mode not supported");
|
||||
errcode = IndexError_Unsupported;
|
||||
return;
|
||||
}
|
||||
|
||||
if (ailego_unlikely(ret != 0)) {
|
||||
if (!error.exchange(true)) {
|
||||
LOG_ERROR("streamer add_impl failed\n");
|
||||
LOG_ERROR("streamer add_impl failed");
|
||||
errcode = ret;
|
||||
}
|
||||
return;
|
||||
|
|
@ -491,7 +492,7 @@ int do_build_by_streamer(IndexStreamer::Pointer &streamer,
|
|||
ret = streamer->remove_impl(holder->get_key(id - keep_docs), ctx);
|
||||
if (ailego_unlikely(ret != 0)) {
|
||||
if (!error.exchange(true)) {
|
||||
LOG_ERROR("streamer remove_impl failed\n");
|
||||
LOG_ERROR("streamer remove_impl failed");
|
||||
errcode = ret;
|
||||
}
|
||||
return;
|
||||
|
|
@ -511,14 +512,14 @@ int do_build_by_streamer(IndexStreamer::Pointer &streamer,
|
|||
cond.wait_until(
|
||||
lk, std::chrono::system_clock::now() + std::chrono::seconds(15));
|
||||
if (error.load(std::memory_order_acquire)) {
|
||||
cerr << "Failed to build index while waiting finish\n";
|
||||
LOG_ERROR("Failed to build index while waiting finish");
|
||||
return errcode;
|
||||
}
|
||||
LOG_INFO("Built cnt %zu, finished percent %.3f%%", finished.load(),
|
||||
finished.load() * 100.0f / holder->count());
|
||||
}
|
||||
if (error.load(std::memory_order_acquire)) {
|
||||
cerr << "Failed to build index while waiting finish\n";
|
||||
LOG_ERROR("Failed to build index while waiting finish");
|
||||
return errcode;
|
||||
}
|
||||
pool.wait_finish();
|
||||
|
|
@ -529,7 +530,7 @@ int do_build_by_streamer(IndexStreamer::Pointer &streamer,
|
|||
int build_by_streamer(IndexStreamer::Pointer &streamer,
|
||||
YAML::Node &config_common) {
|
||||
if (!config_common["IndexPath"]) {
|
||||
cerr << "Miss params IndexPath for Streamer\n";
|
||||
LOG_ERROR("Miss params IndexPath for Streamer");
|
||||
return IndexError_InvalidArgument;
|
||||
}
|
||||
string path = config_common["IndexPath"].as<string>();
|
||||
|
|
@ -538,23 +539,23 @@ int build_by_streamer(IndexStreamer::Pointer &streamer,
|
|||
|
||||
auto storage = IndexFactory::CreateStorage("MMapFileStorage");
|
||||
if (!storage) {
|
||||
cerr << "Failed to create storage\n";
|
||||
LOG_ERROR("Failed to create storage");
|
||||
return IndexError_NoExist;
|
||||
}
|
||||
ailego::Params params;
|
||||
int ret = storage->init(params);
|
||||
if (ret != 0) {
|
||||
cerr << "Storage Failed init";
|
||||
LOG_ERROR("Storage Failed init");
|
||||
return IndexError_Runtime;
|
||||
}
|
||||
ret = storage->open(path, true);
|
||||
if (ret != 0) {
|
||||
cerr << "Storage Failed to open" << endl;
|
||||
LOG_ERROR("Storage Failed to open");
|
||||
return IndexError_Runtime;
|
||||
}
|
||||
ret = streamer->open(storage);
|
||||
if (ret != 0) {
|
||||
cerr << "Failed to open storage" << endl;
|
||||
LOG_ERROR("Failed to open storage");
|
||||
return IndexError_Runtime;
|
||||
}
|
||||
|
||||
|
|
@ -589,25 +590,25 @@ IndexSparseHolder::Pointer convert_sparse_holder(
|
|||
|
||||
IndexConverter::Pointer converter = IndexFactory::CreateConverter(name);
|
||||
if (!converter) {
|
||||
cerr << "Failed to create sparse converter " << name << endl;
|
||||
LOG_ERROR("Failed to create sparse converter %s", name.c_str());
|
||||
return IndexSparseHolder::Pointer();
|
||||
}
|
||||
|
||||
int ret = converter->init(in_holder->index_meta(), params);
|
||||
if (ret != 0) {
|
||||
cerr << "Failed to init converter " << ret << endl;
|
||||
LOG_ERROR("Failed to init converter %d", ret);
|
||||
return IndexSparseHolder::Pointer();
|
||||
}
|
||||
|
||||
ret = converter->train(cast_holder);
|
||||
if (ret != 0) {
|
||||
cerr << "Failed to train sparse converter " << ret << endl;
|
||||
LOG_ERROR("Failed to train sparse converter %d", ret);
|
||||
return IndexSparseHolder::Pointer();
|
||||
}
|
||||
|
||||
ret = converter->transform(cast_holder);
|
||||
if (ret != 0) {
|
||||
cerr << "Failed to transform converter " << ret << endl;
|
||||
LOG_ERROR("Failed to transform converter %d", ret);
|
||||
return IndexSparseHolder::Pointer();
|
||||
}
|
||||
|
||||
|
|
@ -628,25 +629,25 @@ IndexHolder::Pointer convert_holder(const std::string &name,
|
|||
|
||||
IndexConverter::Pointer converter = IndexFactory::CreateConverter(name);
|
||||
if (!converter) {
|
||||
cerr << "Failed to create converter " << name << endl;
|
||||
LOG_ERROR("Failed to create converter %s", name.c_str());
|
||||
return IndexHolder::Pointer();
|
||||
}
|
||||
|
||||
int ret = converter->init(in_holder->index_meta(), params);
|
||||
if (ret != 0) {
|
||||
cerr << "Failed to init converter " << ret << endl;
|
||||
LOG_ERROR("Failed to init converter %d", ret);
|
||||
return IndexHolder::Pointer();
|
||||
}
|
||||
|
||||
ret = converter->train(cast_holder);
|
||||
if (ret != 0) {
|
||||
cerr << "Failed to train converter " << ret << endl;
|
||||
LOG_ERROR("Failed to train converter %d", ret);
|
||||
return IndexHolder::Pointer();
|
||||
}
|
||||
|
||||
ret = converter->transform(cast_holder);
|
||||
if (ret != 0) {
|
||||
cerr << "Failed to transform converter " << ret << endl;
|
||||
LOG_ERROR("Failed to transform converter %d", ret);
|
||||
return IndexHolder::Pointer();
|
||||
}
|
||||
|
||||
|
|
@ -659,7 +660,7 @@ int do_build_sparse(YAML::Node &config_root, YAML::Node &config_common) {
|
|||
string build_file = config_common["BuildFile"].as<string>();
|
||||
VecsIndexSparseHolder::Pointer build_holder(new VecsIndexSparseHolder);
|
||||
if (!build_holder->load(build_file)) {
|
||||
cerr << "Load input error: " << build_file << endl;
|
||||
LOG_ERROR("Load input error: %s", build_file.c_str());
|
||||
return -1;
|
||||
}
|
||||
IndexMeta meta;
|
||||
|
|
@ -672,7 +673,7 @@ int do_build_sparse(YAML::Node &config_root, YAML::Node &config_common) {
|
|||
metric_name = config_common["MetricName"].as<string>();
|
||||
if (config_root["MetricParams"] &&
|
||||
!prepare_params(config_root["MetricParams"], metric_params)) {
|
||||
cerr << "Failed to prepare metric params" << endl;
|
||||
LOG_ERROR("Failed to prepare metric params");
|
||||
return -1;
|
||||
}
|
||||
build_holder->set_metric(metric_name, metric_params);
|
||||
|
|
@ -686,7 +687,7 @@ int do_build_sparse(YAML::Node &config_root, YAML::Node &config_common) {
|
|||
converter_name = config_common["ConverterName"].as<string>();
|
||||
if (config_root["ConverterParams"] &&
|
||||
!prepare_params(config_root["ConverterParams"], converter_params)) {
|
||||
cerr << "Failed to prepare converter params" << endl;
|
||||
LOG_ERROR("Failed to prepare converter params");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
|
@ -711,7 +712,7 @@ int do_build_sparse(YAML::Node &config_root, YAML::Node &config_common) {
|
|||
streamer = IndexFactory::CreateStreamer(builder_class.c_str());
|
||||
}
|
||||
if (!builder && !streamer) {
|
||||
cerr << "Failed to create builder " << builder_class << endl;
|
||||
LOG_ERROR("Failed to create builder %s", builder_class.c_str());
|
||||
return -1;
|
||||
}
|
||||
cout << "Created builder " << builder_class << endl;
|
||||
|
|
@ -719,13 +720,13 @@ int do_build_sparse(YAML::Node &config_root, YAML::Node &config_common) {
|
|||
IndexSparseHolder::Pointer cv_build_holder = convert_sparse_holder(
|
||||
converter_name, converter_params, build_holder, meta);
|
||||
if (!cv_build_holder) {
|
||||
cerr << "Convert holder failed." << endl;
|
||||
LOG_ERROR("Convert holder failed.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
ailego::Params params;
|
||||
if (!prepare_params(config_root["BuilderParams"], params)) {
|
||||
cerr << "Failed to prepare params" << endl;
|
||||
LOG_ERROR("Failed to prepare params");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -733,7 +734,7 @@ int do_build_sparse(YAML::Node &config_root, YAML::Node &config_common) {
|
|||
int ret =
|
||||
builder ? builder->init(meta, params) : streamer->init(meta, params);
|
||||
if (ret < 0) {
|
||||
cerr << "Failed to init builder, ret=" << ret << endl;
|
||||
LOG_ERROR("Failed to init builder, ret=%d", ret);
|
||||
return -1;
|
||||
}
|
||||
ailego::ElapsedTime timer;
|
||||
|
|
@ -744,7 +745,7 @@ int do_build_sparse(YAML::Node &config_root, YAML::Node &config_common) {
|
|||
string train_file = config_common["TrainFile"].as<string>();
|
||||
VecsIndexSparseHolder::Pointer train_holder(new VecsIndexSparseHolder);
|
||||
if (!train_holder->load(train_file)) {
|
||||
cerr << "Load input error: " << train_file << endl;
|
||||
LOG_ERROR("Load input error: %s", train_file.c_str());
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -755,7 +756,7 @@ int do_build_sparse(YAML::Node &config_root, YAML::Node &config_common) {
|
|||
IndexSparseHolder::Pointer cv_train_holder = convert_sparse_holder(
|
||||
converter_name, converter_params, train_holder, meta);
|
||||
if (!cv_train_holder) {
|
||||
cerr << "Convert train holder failed." << endl;
|
||||
LOG_ERROR("Convert train holder failed.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -765,7 +766,7 @@ int do_build_sparse(YAML::Node &config_root, YAML::Node &config_common) {
|
|||
size_t train_time = timer.milli_seconds();
|
||||
|
||||
if (ret < 0) {
|
||||
cerr << "Failed to train in builder, ret=" << ret << endl;
|
||||
LOG_ERROR("Failed to train in builder, ret=%d", ret);
|
||||
return -1;
|
||||
}
|
||||
cout << "Train finished, consume " << train_time << "ms." << endl;
|
||||
|
|
@ -784,7 +785,7 @@ int do_build_sparse(YAML::Node &config_root, YAML::Node &config_common) {
|
|||
}
|
||||
size_t build_time = timer.milli_seconds();
|
||||
if (ret < 0) {
|
||||
cerr << "Failed to build in builder, ret=" << ret << endl;
|
||||
LOG_ERROR("Failed to build in builder, ret=%d", ret);
|
||||
return -1;
|
||||
}
|
||||
cout << "Build finished, consume " << build_time << "ms." << endl;
|
||||
|
|
@ -793,13 +794,13 @@ int do_build_sparse(YAML::Node &config_root, YAML::Node &config_common) {
|
|||
// DUMP
|
||||
IndexDumper::Pointer dumper = IndexFactory::CreateDumper("FileDumper");
|
||||
if (!dumper) {
|
||||
cerr << "Failed to create FileDumper." << endl;
|
||||
LOG_ERROR("Failed to create FileDumper.");
|
||||
return -1;
|
||||
}
|
||||
string dump_prefix = config_common["DumpPath"].as<string>();
|
||||
ret = dumper->create(dump_prefix);
|
||||
if (ret != 0) {
|
||||
cerr << "Failed to create in dumper, ret=" << ret << endl;
|
||||
LOG_ERROR("Failed to create in dumper, ret=%d", ret);
|
||||
return -1;
|
||||
}
|
||||
timer.reset();
|
||||
|
|
@ -808,7 +809,7 @@ int do_build_sparse(YAML::Node &config_root, YAML::Node &config_common) {
|
|||
if (ret == IndexError_NotImplemented) {
|
||||
LOG_WARN("Dump index not implemented");
|
||||
} else if (ret < 0) {
|
||||
cerr << "Failed to dump in builder, ret=" << ret << endl;
|
||||
LOG_ERROR("Failed to dump in builder, ret=%d", ret);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -823,7 +824,7 @@ int do_build_sparse(YAML::Node &config_root, YAML::Node &config_common) {
|
|||
|
||||
ret = dumper->close();
|
||||
if (ret != 0) {
|
||||
cerr << "Dumper failed to close, ret=" << ret << endl;
|
||||
LOG_ERROR("Dumper failed to close, ret=%d", ret);
|
||||
return -1;
|
||||
}
|
||||
std::cout << "Dump to [" << dump_prefix << "] finished, consume " << dump_time
|
||||
|
|
@ -854,7 +855,7 @@ int do_build(YAML::Node &config_root, YAML::Node &config_common) {
|
|||
string build_file = config_common["BuildFile"].as<string>();
|
||||
VecsIndexHolder::Pointer build_holder(new VecsIndexHolder);
|
||||
if (!build_holder->load(build_file)) {
|
||||
cerr << "Load input error: " << build_file << endl;
|
||||
LOG_ERROR("Load input error: %s", build_file.c_str());
|
||||
return -1;
|
||||
}
|
||||
IndexMeta meta;
|
||||
|
|
@ -867,7 +868,7 @@ int do_build(YAML::Node &config_root, YAML::Node &config_common) {
|
|||
metric_name = config_common["MetricName"].as<string>();
|
||||
if (config_root["MetricParams"] &&
|
||||
!prepare_params(config_root["MetricParams"], metric_params)) {
|
||||
cerr << "Failed to prepare metric params" << endl;
|
||||
LOG_ERROR("Failed to prepare metric params");
|
||||
return -1;
|
||||
}
|
||||
build_holder->set_metric(metric_name, metric_params);
|
||||
|
|
@ -880,7 +881,7 @@ int do_build(YAML::Node &config_root, YAML::Node &config_common) {
|
|||
converter_name = config_common["ConverterName"].as<string>();
|
||||
if (config_root["ConverterParams"] &&
|
||||
!prepare_params(config_root["ConverterParams"], converter_params)) {
|
||||
cerr << "Failed to prepare converter params" << endl;
|
||||
LOG_ERROR("Failed to prepare converter params");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
|
@ -914,7 +915,7 @@ int do_build(YAML::Node &config_root, YAML::Node &config_common) {
|
|||
streamer = IndexFactory::CreateStreamer(builder_class.c_str());
|
||||
}
|
||||
if (!builder && !streamer) {
|
||||
cerr << "Failed to create builder " << builder_class << endl;
|
||||
LOG_ERROR("Failed to create builder %s", builder_class.c_str());
|
||||
return -1;
|
||||
}
|
||||
cout << "Created builder " << builder_class << endl;
|
||||
|
|
@ -923,7 +924,7 @@ int do_build(YAML::Node &config_root, YAML::Node &config_common) {
|
|||
IndexHolder::Pointer cv_build_holder =
|
||||
convert_holder(converter_name, converter_params, build_holder, meta);
|
||||
if (!cv_build_holder) {
|
||||
cerr << "Convert holder failed." << endl;
|
||||
LOG_ERROR("Convert holder failed.");
|
||||
return -1;
|
||||
}
|
||||
meta.set_major_order(order);
|
||||
|
|
@ -936,7 +937,7 @@ int do_build(YAML::Node &config_root, YAML::Node &config_common) {
|
|||
params.set(PARAM_FLAT_USE_ID_MAP, false);
|
||||
}
|
||||
if (!prepare_params(config_root["BuilderParams"], params)) {
|
||||
cerr << "Failed to prepare params" << endl;
|
||||
LOG_ERROR("Failed to prepare params");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -944,7 +945,7 @@ int do_build(YAML::Node &config_root, YAML::Node &config_common) {
|
|||
int ret =
|
||||
builder ? builder->init(meta, params) : streamer->init(meta, params);
|
||||
if (ret < 0) {
|
||||
cerr << "Failed to init builder, ret=" << ret << endl;
|
||||
LOG_ERROR("Failed to init builder, ret=%d", ret);
|
||||
return -1;
|
||||
}
|
||||
ailego::ElapsedTime timer;
|
||||
|
|
@ -953,7 +954,7 @@ int do_build(YAML::Node &config_root, YAML::Node &config_common) {
|
|||
if (config_common["UseTrainer"] && config_common["UseTrainer"].as<bool>()) {
|
||||
ailego::Params trainer_params;
|
||||
if (!prepare_params(config_root["TrainerParams"], trainer_params)) {
|
||||
cerr << "Failed to prepare trainer params" << endl;
|
||||
LOG_ERROR("Failed to prepare trainer params");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -961,19 +962,19 @@ int do_build(YAML::Node &config_root, YAML::Node &config_common) {
|
|||
if (config_common["TrainerIndexPath"]) {
|
||||
train_index_path = config_common["TrainerIndexPath"].as<string>();
|
||||
if (train_index_path.empty()) {
|
||||
cerr << "invalid TrainerIndexPath format" << std::endl;
|
||||
LOG_ERROR("invalid TrainerIndexPath format");
|
||||
return -1;
|
||||
}
|
||||
cout << "Trainer index path: " << train_index_path << "\n";
|
||||
} else {
|
||||
cerr << "Need [TrainerIndexPath] config" << std::endl;
|
||||
LOG_ERROR("Need [TrainerIndexPath] config");
|
||||
return -1;
|
||||
}
|
||||
|
||||
IndexTrainer::Pointer trainer =
|
||||
IndexFactory::CreateTrainer("StratifiedClusterTrainer");
|
||||
if (trainer->init(meta, trainer_params) != 0) {
|
||||
cerr << "trainer init failed" << std::endl;
|
||||
LOG_ERROR("trainer init failed");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -981,17 +982,17 @@ int do_build(YAML::Node &config_root, YAML::Node &config_common) {
|
|||
IndexStorage::Pointer container =
|
||||
IndexFactory::CreateStorage("MMapFileReadStorage");
|
||||
if (!container) {
|
||||
cerr << "Failed to create MMapFileReadStorage" << endl;
|
||||
LOG_ERROR("Failed to create MMapFileReadStorage");
|
||||
return -1;
|
||||
}
|
||||
container->init(ailego::Params());
|
||||
if (container->open(train_index_path, false) != 0) {
|
||||
cerr << "MMapFileReadStorage failed to load "
|
||||
<< train_index_path.c_str() << endl;
|
||||
LOG_ERROR("MMapFileReadStorage failed to load %s",
|
||||
train_index_path.c_str());
|
||||
return -1;
|
||||
}
|
||||
if (trainer->load(container) != 0) {
|
||||
cerr << "Trainer failed to load container" << endl;
|
||||
LOG_ERROR("Trainer failed to load container");
|
||||
return -1;
|
||||
};
|
||||
} else {
|
||||
|
|
@ -999,7 +1000,7 @@ int do_build(YAML::Node &config_root, YAML::Node &config_common) {
|
|||
string train_file = config_common["TrainFile"].as<string>();
|
||||
VecsIndexHolder::Pointer train_holder(new VecsIndexHolder);
|
||||
if (!train_holder->load(train_file)) {
|
||||
cerr << "Load input error: " << train_file << endl;
|
||||
LOG_ERROR("Load input error: %s", train_file.c_str());
|
||||
return -1;
|
||||
}
|
||||
if (!metric_name.empty()) {
|
||||
|
|
@ -1011,7 +1012,7 @@ int do_build(YAML::Node &config_root, YAML::Node &config_common) {
|
|||
IndexHolder::Pointer cv_train_holder =
|
||||
convert_holder(converter_name, converter_params, train_holder, meta);
|
||||
if (!cv_train_holder) {
|
||||
cerr << "Convert train holder failed." << endl;
|
||||
LOG_ERROR("Convert train holder failed.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -1020,27 +1021,27 @@ int do_build(YAML::Node &config_root, YAML::Node &config_common) {
|
|||
|
||||
ret = trainer->train(cv_train_holder);
|
||||
if (ret != 0) {
|
||||
cerr << "trainer train_index failed with " << ret << std::endl;
|
||||
LOG_ERROR("trainer train_index failed with %d", ret);
|
||||
return -1;
|
||||
}
|
||||
|
||||
std::cout << "train data done!" << std::endl;
|
||||
IndexDumper::Pointer dumper = IndexFactory::CreateDumper("FileDumper");
|
||||
if (!dumper) {
|
||||
cerr << "Failed to create FileDumper." << endl;
|
||||
LOG_ERROR("Failed to create FileDumper.");
|
||||
return -1;
|
||||
}
|
||||
if (dumper->init(ailego::Params()) != 0) {
|
||||
cerr << "Failed to init FileDumper." << endl;
|
||||
LOG_ERROR("Failed to init FileDumper.");
|
||||
return -1;
|
||||
}
|
||||
ret = dumper->create(train_index_path);
|
||||
if (ret != 0) {
|
||||
cerr << "Failed to create in dumper, ret=" << ret << endl;
|
||||
LOG_ERROR("Failed to create in dumper, ret=%d", ret);
|
||||
return -1;
|
||||
}
|
||||
if (trainer->dump(dumper) != 0) {
|
||||
cerr << "trainer dump_index failed" << std::endl;
|
||||
LOG_ERROR("trainer dump_index failed");
|
||||
return -1;
|
||||
}
|
||||
dumper->close();
|
||||
|
|
@ -1049,7 +1050,7 @@ int do_build(YAML::Node &config_root, YAML::Node &config_common) {
|
|||
ret = builder->train(trainer);
|
||||
size_t train_time = timer.milli_seconds();
|
||||
if (ret < 0) {
|
||||
cerr << "Failed to train in builder, ret=" << ret << endl;
|
||||
LOG_ERROR("Failed to train in builder, ret=%d", ret);
|
||||
return -1;
|
||||
}
|
||||
cout << "Train finished, consume " << train_time << "ms." << endl;
|
||||
|
|
@ -1058,7 +1059,7 @@ int do_build(YAML::Node &config_root, YAML::Node &config_common) {
|
|||
string train_file = config_common["TrainFile"].as<string>();
|
||||
VecsIndexHolder::Pointer train_holder(new VecsIndexHolder);
|
||||
if (!train_holder->load(train_file)) {
|
||||
cerr << "Load input error: " << train_file << endl;
|
||||
LOG_ERROR("Load input error: %s", train_file.c_str());
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -1068,7 +1069,7 @@ int do_build(YAML::Node &config_root, YAML::Node &config_common) {
|
|||
IndexHolder::Pointer cv_train_holder =
|
||||
convert_holder(converter_name, converter_params, train_holder, meta);
|
||||
if (!cv_train_holder) {
|
||||
cerr << "Convert train holder failed." << endl;
|
||||
LOG_ERROR("Convert train holder failed.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -1077,7 +1078,7 @@ int do_build(YAML::Node &config_root, YAML::Node &config_common) {
|
|||
ret = builder->train(std::move(cv_train_holder));
|
||||
size_t train_time = timer.milli_seconds();
|
||||
if (ret < 0) {
|
||||
cerr << "Failed to train in builder, ret=" << ret << endl;
|
||||
LOG_ERROR("Failed to train in builder, ret=%d", ret);
|
||||
return -1;
|
||||
}
|
||||
cout << "Train finished, consume " << train_time << "ms." << endl;
|
||||
|
|
@ -1103,7 +1104,7 @@ int do_build(YAML::Node &config_root, YAML::Node &config_common) {
|
|||
}
|
||||
size_t build_time = timer.milli_seconds();
|
||||
if (ret < 0) {
|
||||
cerr << "Failed to build in builder, ret=" << ret << endl;
|
||||
LOG_ERROR("Failed to build in builder, ret=%d", ret);
|
||||
return -1;
|
||||
}
|
||||
cout << "Build finished, consume " << build_time << "ms." << endl;
|
||||
|
|
@ -1112,13 +1113,13 @@ int do_build(YAML::Node &config_root, YAML::Node &config_common) {
|
|||
// DUMP
|
||||
IndexDumper::Pointer dumper = IndexFactory::CreateDumper("FileDumper");
|
||||
if (!dumper) {
|
||||
cerr << "Failed to create FileDumper." << endl;
|
||||
LOG_ERROR("Failed to create FileDumper.");
|
||||
return -1;
|
||||
}
|
||||
string dump_prefix = config_common["DumpPath"].as<string>();
|
||||
ret = dumper->create(dump_prefix);
|
||||
if (ret != 0) {
|
||||
cerr << "Failed to create in dumper, ret=" << ret << endl;
|
||||
LOG_ERROR("Failed to create in dumper, ret=%d", ret);
|
||||
return -1;
|
||||
}
|
||||
timer.reset();
|
||||
|
|
@ -1127,7 +1128,7 @@ int do_build(YAML::Node &config_root, YAML::Node &config_common) {
|
|||
if (ret == IndexError_NotImplemented) {
|
||||
LOG_WARN("Dump index not implemented");
|
||||
} else if (ret < 0) {
|
||||
cerr << "Failed to dump in builder, ret=" << ret << endl;
|
||||
LOG_ERROR("Failed to dump in builder, ret=%d", ret);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -1142,7 +1143,7 @@ int do_build(YAML::Node &config_root, YAML::Node &config_common) {
|
|||
|
||||
ret = dumper->close();
|
||||
if (ret != 0) {
|
||||
cerr << "Dumper failed to close, ret=" << ret << endl;
|
||||
LOG_ERROR("Dumper failed to close, ret=%d", ret);
|
||||
return -1;
|
||||
}
|
||||
std::cout << "Dump to [" << dump_prefix << "] finished, consume " << dump_time
|
||||
|
|
@ -1178,8 +1179,7 @@ int main(int argc, char *argv[]) {
|
|||
std::string error;
|
||||
for (int i = 2; i < argc; ++i) {
|
||||
if (!broker.emplace(argv[i], &error)) {
|
||||
cerr << "Failed to load plugin: " << argv[i] << " (" << error << ")"
|
||||
<< endl;
|
||||
LOG_ERROR("Failed to load plugin: %s (%s)", argv[i], error.c_str());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
|
@ -1187,7 +1187,7 @@ int main(int argc, char *argv[]) {
|
|||
try {
|
||||
config_root = YAML::LoadFile(argv[1]);
|
||||
} catch (...) {
|
||||
cerr << "Load YAML file[" << argv[1] << "] failed!" << endl;
|
||||
LOG_ERROR("Load YAML file[%s] failed!", argv[1]);
|
||||
return -1;
|
||||
}
|
||||
if (!check_config(config_root)) {
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ class Recall {
|
|||
cout << "Loading internal ground truth file" << endl;
|
||||
|
||||
if (!load_gt_dense(index, gt_count)) {
|
||||
cerr << "Load ground truth file failed!" << endl;
|
||||
LOG_ERROR("Load ground truth file failed!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
@ -100,7 +100,7 @@ class Recall {
|
|||
string cmd = "mkdir -p " + output_;
|
||||
int ret = system(cmd.c_str());
|
||||
if (ret != 0) {
|
||||
std::cerr << "execute cmd " << cmd << " failed" << std::endl;
|
||||
LOG_ERROR("execute cmd %s failed, ret=%d", cmd.c_str(), ret);
|
||||
return;
|
||||
}
|
||||
struct stat sb;
|
||||
|
|
@ -152,7 +152,7 @@ class Recall {
|
|||
|
||||
if (!reader.load_query(query_file, first_sep, second_sep, linear_queries_,
|
||||
linear_sparse_data_, linear_taglists_)) {
|
||||
cerr << "Load query error" << endl;
|
||||
LOG_ERROR("Load query error");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -220,7 +220,7 @@ class Recall {
|
|||
} else if (typeid(T) == typeid(int8_t)) {
|
||||
qmeta_.set_meta(IndexMeta::DataType::DT_INT8, dim_);
|
||||
} else {
|
||||
cerr << "unsupported type";
|
||||
LOG_ERROR("unsupported type");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -239,7 +239,7 @@ class Recall {
|
|||
<< File::BaseName(external_gt_file) << "] done!" << endl;
|
||||
external_gt_file_enabled_ = true;
|
||||
} else {
|
||||
cerr << "Failed to load ground truth file!" << endl;
|
||||
LOG_ERROR("Failed to load ground truth file!");
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
|
@ -330,14 +330,14 @@ class Recall {
|
|||
std::shared_ptr<IndexFilter> filter_ptr = nullptr;
|
||||
if (filter_mode_ == FM_TAG) {
|
||||
if (batch_taglists_[i].size() != 1) {
|
||||
cerr << "query tag list not equal to one!" << endl;
|
||||
LOG_ERROR("query tag list not equal to one!");
|
||||
return;
|
||||
}
|
||||
|
||||
int ret = filter_cache.filter(id_to_tags_list_, batch_taglists_[i][0],
|
||||
tag_key_list_);
|
||||
if (ret != 0) {
|
||||
cerr << "prefilter failed, idx: " << i << std::endl;
|
||||
LOG_ERROR("prefilter failed, idx: %zu", i);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -362,7 +362,8 @@ class Recall {
|
|||
core_interface::SearchResult search_result;
|
||||
int ret = index->Search(query_data, query_param, &search_result);
|
||||
if (ret < 0) {
|
||||
cerr << "Failed to linear search, ret=" << ret << endl;
|
||||
LOG_ERROR("Failed to linear search, ret=%d %s", ret,
|
||||
IndexError::What(ret));
|
||||
error.exchange(true);
|
||||
return;
|
||||
}
|
||||
|
|
@ -423,8 +424,8 @@ class Recall {
|
|||
gtf.close();
|
||||
|
||||
if (!File::Rename(gt_file_temp, gt_file)) {
|
||||
cerr << "failed to rename ground truth file, src: " << gt_file_temp
|
||||
<< ", dst: " << gt_file << endl;
|
||||
LOG_ERROR("failed to rename ground truth file, src: %s, dst: %s",
|
||||
gt_file_temp.c_str(), gt_file.c_str());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
@ -434,7 +435,7 @@ class Recall {
|
|||
<< timer.milli_seconds() / 1000 << "s." << endl;
|
||||
} else {
|
||||
if (!gtf.open(gt_file.c_str(), true)) {
|
||||
cerr << "Failed to open ground truth file[" << gt_file << "]" << endl;
|
||||
LOG_ERROR("Failed to open ground truth file[%s]", gt_file.c_str());
|
||||
return false;
|
||||
}
|
||||
size_t file_size = gtf.size();
|
||||
|
|
@ -449,7 +450,7 @@ class Recall {
|
|||
size_t one_query_line_size = sizeof(int) + GT_PAIR_SIZE * gt_count_input;
|
||||
|
||||
if (gt_count != gt_count_input || file_size % one_query_line_size != 0) {
|
||||
cerr << "Ground truth file[" << gt_file << "] content error!" << endl;
|
||||
LOG_ERROR("Ground truth file[%s] content error!", gt_file.c_str());
|
||||
gtf.close();
|
||||
return false;
|
||||
}
|
||||
|
|
@ -607,14 +608,14 @@ class Recall {
|
|||
std::shared_ptr<IndexFilter> filter_ptr = nullptr;
|
||||
if (filter_mode_ == FM_TAG) {
|
||||
if (batch_taglists_[idx].size() != 1) {
|
||||
cerr << "query tag list not equal to one!" << endl;
|
||||
LOG_ERROR("query tag list not equal to one!");
|
||||
return;
|
||||
}
|
||||
|
||||
int ret = filter_cache.filter(id_to_tags_list_, batch_taglists_[idx][0],
|
||||
tag_key_list_);
|
||||
if (ret != 0) {
|
||||
cerr << "prefilter failed, idx: " << idx << std::endl;
|
||||
LOG_ERROR("prefilter failed, idx: %zu", idx);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -655,8 +656,8 @@ class Recall {
|
|||
int ret =
|
||||
index->Search(single_query_data, query_param_clone, &search_result);
|
||||
if (ret < 0) {
|
||||
cerr << "Failed to knn_search batch, ret=" << ret << " "
|
||||
<< IndexError::What(ret) << endl;
|
||||
LOG_ERROR("Failed to knn_search batch, ret=%d %s", ret,
|
||||
IndexError::What(ret));
|
||||
return;
|
||||
}
|
||||
auto &knn_res = search_result.doc_list_;
|
||||
|
|
@ -666,8 +667,8 @@ class Recall {
|
|||
core_interface::SearchResult search_result;
|
||||
int ret = index->Search(query_data, query_param_clone, &search_result);
|
||||
if (ret < 0) {
|
||||
cerr << "Failed to knn_search, ret=" << ret << " "
|
||||
<< IndexError::What(ret) << endl;
|
||||
LOG_ERROR("Failed to knn_search, ret=%d %s", ret,
|
||||
IndexError::What(ret));
|
||||
return;
|
||||
}
|
||||
auto &knn_res = search_result.doc_list_;
|
||||
|
|
@ -770,8 +771,7 @@ class SparseRecall {
|
|||
vector<vector<T>> *queries_output,
|
||||
vector<vector<T>> *sparse_features_output) {
|
||||
if (!queries_output || !sparse_features_output) {
|
||||
std::cerr << "input should not be empty in transfrom queries"
|
||||
<< std::endl;
|
||||
LOG_ERROR("input should not be empty in transfrom queries");
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
|
@ -815,7 +815,7 @@ class SparseRecall {
|
|||
cout << "Loading internal ground truth file" << endl;
|
||||
|
||||
if (!load_gt_sparse(index, gt_count)) {
|
||||
cerr << "Load ground truth file failed!" << endl;
|
||||
LOG_ERROR("Load ground truth file failed!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
@ -833,7 +833,7 @@ class SparseRecall {
|
|||
string cmd = "mkdir -p " + output_;
|
||||
int ret = system(cmd.c_str());
|
||||
if (ret != 0) {
|
||||
std::cerr << "execute cmd " << cmd << " failed" << std::endl;
|
||||
LOG_ERROR("execute cmd %s failed, ret=%d", cmd.c_str(), ret);
|
||||
return;
|
||||
}
|
||||
struct stat sb;
|
||||
|
|
@ -885,7 +885,7 @@ class SparseRecall {
|
|||
|
||||
if (!reader.load_query(query_file, first_sep, second_sep, linear_queries_,
|
||||
linear_sparse_data_, linear_taglists_)) {
|
||||
cerr << "Load query error" << endl;
|
||||
LOG_ERROR("Load query error");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -934,7 +934,7 @@ class SparseRecall {
|
|||
} else if (typeid(T) == typeid(int8_t)) {
|
||||
qmeta_.set_data_type(IndexMeta::DataType::DT_INT8);
|
||||
} else {
|
||||
cerr << "unsupported type";
|
||||
LOG_ERROR("unsupported type");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -988,14 +988,14 @@ class SparseRecall {
|
|||
std::shared_ptr<IndexFilter> filter_ptr = nullptr;
|
||||
if (filter_mode_ == FM_TAG) {
|
||||
if (batch_taglists_[i].size() != 1) {
|
||||
cerr << "query tag list not equal to one!" << endl;
|
||||
LOG_ERROR("query tag list not equal to one!");
|
||||
return;
|
||||
}
|
||||
|
||||
int ret = filter_cache.filter(id_to_tags_list_, batch_taglists_[i][0],
|
||||
tag_key_list_);
|
||||
if (ret != 0) {
|
||||
cerr << "prefilter failed, idx: " << i << std::endl;
|
||||
LOG_ERROR("prefilter failed, idx: %zu", i);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -1022,7 +1022,7 @@ class SparseRecall {
|
|||
core_interface::SearchResult search_result;
|
||||
int ret = index->Search(query_data, query_param, &search_result);
|
||||
if (ret < 0) {
|
||||
cerr << "Failed to sparse linear search, ret=" << ret << endl;
|
||||
LOG_ERROR("Failed to sparse linear search, ret=%d", ret);
|
||||
error.exchange(true);
|
||||
return;
|
||||
}
|
||||
|
|
@ -1084,8 +1084,8 @@ class SparseRecall {
|
|||
gtf.close();
|
||||
|
||||
if (!File::Rename(gt_file_temp, gt_file)) {
|
||||
cerr << "failed to rename ground truth file, src: " << gt_file_temp
|
||||
<< ", dst: " << gt_file << endl;
|
||||
LOG_ERROR("failed to rename ground truth file, src: %s, dst: %s",
|
||||
gt_file_temp.c_str(), gt_file.c_str());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
@ -1095,7 +1095,7 @@ class SparseRecall {
|
|||
<< timer.milli_seconds() / 1000 << "s." << endl;
|
||||
} else {
|
||||
if (!gtf.open(gt_file.c_str(), true)) {
|
||||
cerr << "Failed to open ground truth file[" << gt_file << "]" << endl;
|
||||
LOG_ERROR("Failed to open ground truth file[%s]", gt_file.c_str());
|
||||
return false;
|
||||
}
|
||||
size_t file_size = gtf.size();
|
||||
|
|
@ -1110,7 +1110,7 @@ class SparseRecall {
|
|||
size_t one_query_line_size = sizeof(int) + GT_PAIR_SIZE * gt_count_input;
|
||||
|
||||
if (gt_count != gt_count_input || file_size % one_query_line_size != 0) {
|
||||
cerr << "Ground truth file[" << gt_file << "] content error!" << endl;
|
||||
LOG_ERROR("Ground truth file[%s] content error!", gt_file.c_str());
|
||||
gtf.close();
|
||||
return false;
|
||||
}
|
||||
|
|
@ -1157,7 +1157,7 @@ class SparseRecall {
|
|||
<< File::BaseName(external_gt_file) << "] done!" << endl;
|
||||
external_gt_file_enabled_ = true;
|
||||
} else {
|
||||
cerr << "Failed to load ground truth file!" << endl;
|
||||
LOG_ERROR("Failed to load ground truth file!");
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
|
@ -1314,14 +1314,14 @@ class SparseRecall {
|
|||
std::shared_ptr<IndexFilter> filter_ptr = nullptr;
|
||||
if (filter_mode_ == FM_TAG) {
|
||||
if (batch_taglists_[idx].size() != 1) {
|
||||
cerr << "query tag list not equal to one!" << endl;
|
||||
LOG_ERROR("query tag list not equal to one!");
|
||||
return;
|
||||
}
|
||||
|
||||
int ret = filter_cache.filter(id_to_tags_list_, batch_taglists_[idx][0],
|
||||
tag_key_list_);
|
||||
if (ret != 0) {
|
||||
cerr << "prefilter failed, idx: " << idx << std::endl;
|
||||
LOG_ERROR("prefilter failed, idx: %zu", idx);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -1363,8 +1363,8 @@ class SparseRecall {
|
|||
int ret =
|
||||
index->Search(single_query_data, query_param_clone, &search_result);
|
||||
if (ret < 0) {
|
||||
cerr << "Failed to sparse_knn_search batch, ret=" << ret << " "
|
||||
<< IndexError::What(ret) << endl;
|
||||
LOG_ERROR("Failed to sparse_knn_search batch, ret=%d %s", ret,
|
||||
IndexError::What(ret));
|
||||
return;
|
||||
}
|
||||
auto &knn_res = search_result.doc_list_;
|
||||
|
|
@ -1374,8 +1374,8 @@ class SparseRecall {
|
|||
core_interface::SearchResult search_result;
|
||||
int ret = index->Search(query_data, query_param_clone, &search_result);
|
||||
if (ret < 0) {
|
||||
cerr << "Failed to sparse_knn_search, ret=" << ret << " "
|
||||
<< IndexError::What(ret) << endl;
|
||||
LOG_ERROR("Failed to sparse_knn_search, ret=%d %s", ret,
|
||||
IndexError::What(ret));
|
||||
return;
|
||||
}
|
||||
auto &knn_res = search_result.doc_list_;
|
||||
|
|
@ -1442,33 +1442,33 @@ bool SparseRecall<T>::STOP_NOW = false;
|
|||
bool check_config(YAML::Node &config_node) {
|
||||
auto common = config_node["IndexCommon"];
|
||||
if (!common) {
|
||||
cerr << "Can not find [IndexCommon] in config" << endl;
|
||||
LOG_ERROR("Can not find [IndexCommon] in config");
|
||||
return false;
|
||||
}
|
||||
if (!common["IndexConfig"]) {
|
||||
cerr << "Can not find [IndexConfig] in config" << endl;
|
||||
LOG_ERROR("Can not find [IndexConfig] in config");
|
||||
return false;
|
||||
}
|
||||
if (!common["IndexPath"]) {
|
||||
cerr << "Can not find [IndexPath] in config" << endl;
|
||||
LOG_ERROR("Can not find [IndexPath] in config");
|
||||
return false;
|
||||
}
|
||||
if (!common["TopK"]) {
|
||||
cerr << "Can not find [TopK] in config" << endl;
|
||||
LOG_ERROR("Can not find [TopK] in config");
|
||||
return false;
|
||||
}
|
||||
if (!common["QueryFile"]) {
|
||||
cerr << "Can not find [QueryFile] in config" << endl;
|
||||
LOG_ERROR("Can not find [QueryFile] in config");
|
||||
return false;
|
||||
}
|
||||
|
||||
auto query_config = config_node["QueryConfig"];
|
||||
if (!query_config) {
|
||||
cerr << "Can not find [QueryConfig] in config" << endl;
|
||||
LOG_ERROR("Can not find [QueryConfig] in config");
|
||||
return false;
|
||||
}
|
||||
if (!query_config["QueryParam"]) {
|
||||
cerr << "Can not find [QueryConfig.QueryParam] in config" << endl;
|
||||
LOG_ERROR("Can not find [QueryConfig.QueryParam] in config");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
|
@ -1560,7 +1560,7 @@ int recall_dense(std::string &query_type, size_t thread_count,
|
|||
|
||||
recall.run_dense(index, query_param, top_k, gt_count);
|
||||
} else {
|
||||
cerr << "Can not recognize type: " << query_type << endl;
|
||||
LOG_ERROR("Can not recognize type: %s", query_type.c_str());
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
@ -1592,7 +1592,7 @@ int recall_sparse(std::string &query_type, size_t thread_count,
|
|||
std::vector<uint64_t> tag_key_list;
|
||||
// Load tag lists if available
|
||||
if (load_taglists(index_dir, id_to_tags_list, tag_key_list) != 0) {
|
||||
cerr << "Failed to load tag lists" << endl;
|
||||
LOG_ERROR("Failed to load tag lists");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -1600,7 +1600,7 @@ int recall_sparse(std::string &query_type, size_t thread_count,
|
|||
|
||||
recall.run_sparse(index, query_param, top_k, gt_count);
|
||||
} else {
|
||||
cerr << "Can not recognize type: " << query_type << endl;
|
||||
LOG_ERROR("Can not recognize type: %s", query_type.c_str());
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
@ -1618,13 +1618,13 @@ int get_recall_precision(string &recall_precision_string) {
|
|||
g_recall_precision = std::stof(recall_precision_string);
|
||||
std::cout << "Recall Score Precesion: " << g_recall_precision << std::endl;
|
||||
} catch (const std::invalid_argument &e) {
|
||||
std::cerr << "Exeception in getting recall precision: " << e.what()
|
||||
<< ", value: " << recall_precision_string << std::endl;
|
||||
LOG_ERROR("Exeception in getting recall precision: %s, value: %s", e.what(),
|
||||
recall_precision_string.c_str());
|
||||
return -1;
|
||||
} catch (const std::out_of_range &e) {
|
||||
std::cerr << "Out of range exception in getting recall precision: "
|
||||
<< e.what() << ", value: " << recall_precision_string
|
||||
<< std::endl;
|
||||
LOG_ERROR(
|
||||
"Out of range exception in getting recall precision: %s, value: %s",
|
||||
e.what(), recall_precision_string.c_str());
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -1641,8 +1641,7 @@ int main(int argc, char *argv[]) {
|
|||
std::string error;
|
||||
for (int i = 2; i < argc; ++i) {
|
||||
if (!broker.emplace(argv[i], &error)) {
|
||||
cerr << "Failed to load plugin: " << argv[i] << " (" << error << ")"
|
||||
<< endl;
|
||||
LOG_ERROR("Failed to load plugin: %s (%s)", argv[i], error.c_str());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
|
@ -1651,7 +1650,7 @@ int main(int argc, char *argv[]) {
|
|||
try {
|
||||
config_node = YAML::LoadFile(argv[1]);
|
||||
} catch (...) {
|
||||
cerr << "Load YAML file[" << argv[1] << "] failed!" << endl;
|
||||
LOG_ERROR("Load YAML file[%s] failed!", argv[1]);
|
||||
return -1;
|
||||
}
|
||||
if (!check_config(config_node)) {
|
||||
|
|
@ -1698,8 +1697,8 @@ int main(int argc, char *argv[]) {
|
|||
: "";
|
||||
|
||||
if (!get_recall_precision(recall_precision_string)) {
|
||||
cerr << "Get recall precision failed, value: " << recall_precision_string
|
||||
<< endl;
|
||||
LOG_ERROR("Get recall precision failed, value: %s",
|
||||
recall_precision_string.c_str());
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -1761,7 +1760,7 @@ int main(int argc, char *argv[]) {
|
|||
core_interface::BaseIndexQueryParam::Pointer query_param;
|
||||
if (parse_and_load_index_param(config_node, index_dir, index, query_param) !=
|
||||
0) {
|
||||
cerr << "Failed to parse and load index param" << endl;
|
||||
LOG_ERROR("Failed to parse and load index param");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -1777,7 +1776,7 @@ int main(int argc, char *argv[]) {
|
|||
query_param, index_dir, log_dir, filter_mode);
|
||||
} else {
|
||||
std::string mode = retrieval_mode == 1 ? "Dense" : "Sparse";
|
||||
cerr << "unsupported retrieval mode: " << mode << endl;
|
||||
LOG_ERROR("unsupported retrieval mode: %s", mode.c_str());
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue