From 1a457df5a055c0aeaf398948d270c12388619dbf Mon Sep 17 00:00:00 2001 From: wxingda Date: Fri, 19 Apr 2024 17:36:31 +0800 Subject: [PATCH] return status in CreateVectorTable --- internal/engine/c_api/api_data/request.h | 6 +- .../index/impl/gamma_index_binary_ivf.cc | 24 ++-- .../engine/index/impl/gamma_index_ivfflat.cc | 15 ++- .../engine/index/impl/gamma_index_ivfpq.cc | 38 +++--- .../engine/index/impl/gamma_index_ivfpqfs.cc | 24 ++-- .../index/impl/gpu/gamma_index_ivfpq_gpu.cc | 13 +- internal/engine/search/engine.cc | 19 +-- internal/engine/table/table.cc | 9 +- internal/engine/vector/raw_vector_common.h | 6 +- internal/engine/vector/rocksdb_raw_vector.cc | 6 +- internal/engine/vector/rocksdb_wrapper.cc | 6 +- internal/engine/vector/vector_manager.cc | 123 ++++++++++-------- internal/engine/vector/vector_manager.h | 27 ++-- 13 files changed, 151 insertions(+), 165 deletions(-) diff --git a/internal/engine/c_api/api_data/request.h b/internal/engine/c_api/api_data/request.h index 9c02a2bd..6cc855b4 100644 --- a/internal/engine/c_api/api_data/request.h +++ b/internal/engine/c_api/api_data/request.h @@ -26,10 +26,8 @@ class Request : public RawData { } virtual ~Request() { - if (ranker_) { - delete ranker_; - ranker_ = nullptr; - } + delete ranker_; + ranker_ = nullptr; } virtual int Serialize(char **out, int *out_len); diff --git a/internal/engine/index/impl/gamma_index_binary_ivf.cc b/internal/engine/index/impl/gamma_index_binary_ivf.cc index d6a6f597..b97a8a2e 100644 --- a/internal/engine/index/impl/gamma_index_binary_ivf.cc +++ b/internal/engine/index/impl/gamma_index_binary_ivf.cc @@ -67,18 +67,12 @@ GammaIndexBinaryIVF::GammaIndexBinaryIVF() { } GammaIndexBinaryIVF::~GammaIndexBinaryIVF() { - if (rt_invert_index_ptr_) { - delete rt_invert_index_ptr_; - rt_invert_index_ptr_ = nullptr; - } - if (invlists) { - delete invlists; - invlists = nullptr; - } - if (quantizer) { - delete quantizer; // it will not be delete in parent class - quantizer = nullptr; - } + delete rt_invert_index_ptr_; + rt_invert_index_ptr_ = nullptr; + delete invlists; + invlists = nullptr; + delete quantizer; // it will not be delete in parent class + quantizer = nullptr; } Status GammaIndexBinaryIVF::Init(const std::string &model_parameters, @@ -117,10 +111,8 @@ Status GammaIndexBinaryIVF::Init(const std::string &model_parameters, this->nprobe = 20; - if (this->invlists) { - delete this->invlists; - this->invlists = nullptr; - } + delete this->invlists; + this->invlists = nullptr; bool ret = rt_invert_index_ptr_->Init(); diff --git a/internal/engine/index/impl/gamma_index_ivfflat.cc b/internal/engine/index/impl/gamma_index_ivfflat.cc index c38c6f21..71c7080f 100644 --- a/internal/engine/index/impl/gamma_index_ivfflat.cc +++ b/internal/engine/index/impl/gamma_index_ivfflat.cc @@ -199,10 +199,8 @@ Status GammaIndexIVFFlat::Init(const std::string &model_parameters, this->nlist, this->code_size, raw_vec->VidMgr(), raw_vec->Bitmap(), params.bucket_init_size, params.bucket_max_size); - if (this->invlists) { - delete this->invlists; - this->invlists = nullptr; - } + delete this->invlists; + this->invlists = nullptr; bool ret = rt_invert_index_ptr_->Init(); if (!ret) { @@ -442,7 +440,9 @@ int GammaIndexIVFFlat::Search(RetrievalContext *retrieval_context, int n, nprobe = retrieval_params->Nprobe(); } else { retrieval_params->SetNprobe(this->nprobe); - LOG(WARNING) << "nlist = " << this->nlist << "nprobe = " << retrieval_params->Nprobe() << "invalid, now use:" << this->nprobe; + LOG(WARNING) << "nlist = " << this->nlist + << "nprobe = " << retrieval_params->Nprobe() + << "invalid, now use:" << this->nprobe; } #else int nprobe = this->nprobe; @@ -455,7 +455,7 @@ int GammaIndexIVFFlat::Search(RetrievalContext *retrieval_context, int n, quantizer->search(n, x, nprobe, coarse_dis.get(), idx.get()); search_preassigned(retrieval_context, n, x, k, idx.get(), coarse_dis.get(), - distances, labels, nprobe, false); + distances, labels, nprobe, false); return 0; } @@ -482,7 +482,8 @@ void GammaIndexIVFFlat::search_preassigned(RetrievalContext *retrieval_context, retrieval_context->retrieval_params_ = new FlatRetrievalParameters(retrieval_params->ParallelOnQueries(), retrieval_params->GetDistanceComputeType()); - GammaFLATIndex::Search(retrieval_context, n, (const uint8_t*)x, k, distances, labels); + GammaFLATIndex::Search(retrieval_context, n, (const uint8_t *)x, k, + distances, labels); return; } faiss::MetricType metric_type; diff --git a/internal/engine/index/impl/gamma_index_ivfpq.cc b/internal/engine/index/impl/gamma_index_ivfpq.cc index cf1bf48f..4af79933 100644 --- a/internal/engine/index/impl/gamma_index_ivfpq.cc +++ b/internal/engine/index/impl/gamma_index_ivfpq.cc @@ -52,22 +52,14 @@ GammaIVFPQIndex::GammaIVFPQIndex() : indexed_vec_count_(0) { } GammaIVFPQIndex::~GammaIVFPQIndex() { - if (rt_invert_index_ptr_) { - delete rt_invert_index_ptr_; - rt_invert_index_ptr_ = nullptr; - } - if (invlists) { - delete invlists; - invlists = nullptr; - } - if (quantizer) { - delete quantizer; // it will not be delete in parent class - quantizer = nullptr; - } - if (opq_) { - delete opq_; - opq_ = nullptr; - } + delete rt_invert_index_ptr_; + rt_invert_index_ptr_ = nullptr; + delete invlists; + invlists = nullptr; + delete quantizer; // it will not be delete in parent class + quantizer = nullptr; + delete opq_; + opq_ = nullptr; CHECK_DELETE(model_param_); } @@ -132,8 +124,10 @@ Status GammaIVFPQIndex::Init(const std::string &model_parameters, if (training_threshold) { training_threshold_ = training_threshold; } else { - // shouldn't less than max_points_per_centroid because of pq.train() when nbit = 8 and ksub = 2^8 - training_threshold_ = std::max((int)nlist * min_points_per_centroid, max_points_per_centroid); + // shouldn't less than max_points_per_centroid because of pq.train() when + // nbit = 8 and ksub = 2^8 + training_threshold_ = + std::max((int)nlist * min_points_per_centroid, max_points_per_centroid); } ivfpq_param.training_threshold = training_threshold_; LOG(INFO) << ivfpq_param.ToString(); @@ -516,7 +510,9 @@ int GammaIVFPQIndex::Search(RetrievalContext *retrieval_context, int n, nprobe = retrieval_params->Nprobe(); } else { retrieval_params->SetNprobe(this->nprobe); - LOG(WARNING) << "nlist = " << this->nlist << "nprobe = " << retrieval_params->Nprobe() << "invalid, now use:" << this->nprobe; + LOG(WARNING) << "nlist = " << this->nlist + << "nprobe = " << retrieval_params->Nprobe() + << "invalid, now use:" << this->nprobe; } const float *xq = reinterpret_cast(x); @@ -611,8 +607,8 @@ size_t scan_one_list(GammaInvertedListScanner *scanner, idx_t key, void compute_dis(int k, const float *xi, float *simi, idx_t *idxi, float *recall_simi, idx_t *recall_idxi, int recall_num, - bool rerank, faiss::MetricType metric_type, - VectorReader *vec, RetrievalContext *retrieval_context) { + bool rerank, faiss::MetricType metric_type, VectorReader *vec, + RetrievalContext *retrieval_context) { if (rerank == true) { ScopeVectors scope_vecs; std::vector vids(recall_idxi, recall_idxi + recall_num); diff --git a/internal/engine/index/impl/gamma_index_ivfpqfs.cc b/internal/engine/index/impl/gamma_index_ivfpqfs.cc index 9996402a..f08d74d4 100644 --- a/internal/engine/index/impl/gamma_index_ivfpqfs.cc +++ b/internal/engine/index/impl/gamma_index_ivfpqfs.cc @@ -48,22 +48,14 @@ GammaIVFPQFastScanIndex::GammaIVFPQFastScanIndex() : indexed_vec_count_(0) { } GammaIVFPQFastScanIndex::~GammaIVFPQFastScanIndex() { - if (rt_invert_index_ptr_) { - delete rt_invert_index_ptr_; - rt_invert_index_ptr_ = nullptr; - } - if (invlists) { - delete invlists; - invlists = nullptr; - } - if (quantizer) { - delete quantizer; // it will not be delete in parent class - quantizer = nullptr; - } - if (opq_) { - delete opq_; - opq_ = nullptr; - } + delete rt_invert_index_ptr_; + rt_invert_index_ptr_ = nullptr; + delete invlists; + invlists = nullptr; + delete quantizer; // it will not be delete in parent class + quantizer = nullptr; + delete opq_; + opq_ = nullptr; CHECK_DELETE(model_param_); int ret = pthread_rwlock_destroy(&shared_mutex_); diff --git a/internal/engine/index/impl/gpu/gamma_index_ivfpq_gpu.cc b/internal/engine/index/impl/gpu/gamma_index_ivfpq_gpu.cc index 7074d8a7..1ea5f7ce 100644 --- a/internal/engine/index/impl/gpu/gamma_index_ivfpq_gpu.cc +++ b/internal/engine/index/impl/gpu/gamma_index_ivfpq_gpu.cc @@ -246,15 +246,10 @@ GammaIVFPQGPUIndex::~GammaIVFPQGPUIndex() { std::lock_guard lock(indexing_mutex_); b_exited_ = true; std::this_thread::sleep_for(std::chrono::seconds(2)); - if (cpu_index_) { - delete cpu_index_; - cpu_index_ = nullptr; - } - - if (gpu_index_) { - delete gpu_index_; - gpu_index_ = nullptr; - } + delete cpu_index_; + cpu_index_ = nullptr; + delete gpu_index_; + gpu_index_ = nullptr; for (auto &resource : resources_) { delete resource; diff --git a/internal/engine/search/engine.cc b/internal/engine/search/engine.cc index 695fd265..9cb0486c 100644 --- a/internal/engine/search/engine.cc +++ b/internal/engine/search/engine.cc @@ -490,8 +490,10 @@ Status Engine::CreateTable(TableInfo &table) { } } - if (vec_manager_->CreateVectorTable(table, meta_jp) != 0) { - std::string msg = space_name_ + " cannot create VectorTable!"; + Status status = vec_manager_->CreateVectorTable(table, meta_jp); + if (status != Status::OK()) { + std::string msg = + space_name_ + " cannot create VectorTable: " + status.ToString(); LOG(ERROR) << msg; vec_manager_->Close(); return Status::ParamError(msg); @@ -502,7 +504,7 @@ Status Engine::CreateTable(TableInfo &table) { meta_jp->GetObject("table", table_jp); disk_table_params.Parse(table_jp); } - Status status = table_->CreateTable(table, disk_table_params, docids_bitmap_); + status = table_->CreateTable(table, disk_table_params, docids_bitmap_); training_threshold_ = table.TrainingThreshold(); LOG(INFO) << space_name_ << " init training_threshold=" << training_threshold_; @@ -775,7 +777,7 @@ int Engine::RebuildIndex(int drop_before_rebuild, int limit_cpu, int describe) { std::map vector_indexes; if (!drop_before_rebuild) { - ret = + Status status = vec_manager_->CreateVectorIndexes(training_threshold_, vector_indexes); if (vec_manager_->TrainIndex(vector_indexes) != 0) { LOG(ERROR) << "RebuildIndex TrainIndex failed!"; @@ -795,10 +797,11 @@ int Engine::RebuildIndex(int drop_before_rebuild, int limit_cpu, int describe) { vec_manager_->DestroyVectorIndexes(); if (drop_before_rebuild) { - ret = vec_manager_->CreateVectorIndexes(training_threshold_, - vec_manager_->VectorIndexes()); - if (ret) { - LOG(ERROR) << "RebuildIndex CreateVectorIndexes failed, ret: " << ret; + Status status = vec_manager_->CreateVectorIndexes( + training_threshold_, vec_manager_->VectorIndexes()); + if (status != Status::OK()) { + LOG(ERROR) << "RebuildIndex CreateVectorIndexes failed: " + << status.ToString(); vec_manager_->DestroyVectorIndexes(); return ret; } diff --git a/internal/engine/table/table.cc b/internal/engine/table/table.cc index bdb798ee..55227761 100644 --- a/internal/engine/table/table.cc +++ b/internal/engine/table/table.cc @@ -108,10 +108,8 @@ Table::Table(const string &root_path, const string &space_name) Table::~Table() { bitmap_mgr_ = nullptr; CHECK_DELETE(table_params_); - if (storage_mgr_) { - delete storage_mgr_; - storage_mgr_ = nullptr; - } + delete storage_mgr_; + storage_mgr_ = nullptr; delete item_to_docid_; item_to_docid_ = nullptr; @@ -351,7 +349,8 @@ int Table::Update(const std::unordered_map &fields, int field_id = it->second; int offset = idx_attr_offset_[field_id]; - if (field.datatype == DataType::STRING || field.datatype == DataType::STRINGARRAY) { + if (field.datatype == DataType::STRING || + field.datatype == DataType::STRINGARRAY) { int len = field.value.size(); storage_mgr_->UpdateString(docid, name, field.value.c_str(), len); } else { diff --git a/internal/engine/vector/raw_vector_common.h b/internal/engine/vector/raw_vector_common.h index 1386cce9..453b0bce 100644 --- a/internal/engine/vector/raw_vector_common.h +++ b/internal/engine/vector/raw_vector_common.h @@ -46,10 +46,8 @@ class VIDMgr { ~VIDMgr() { if (multi_vids_) { for (size_t i = 0; i < docid2vid_.size(); i++) { - if (docid2vid_[i] != nullptr) { - delete[] docid2vid_[i]; - docid2vid_[i] = nullptr; - } + delete[] docid2vid_[i]; + docid2vid_[i] = nullptr; } } } diff --git a/internal/engine/vector/rocksdb_raw_vector.cc b/internal/engine/vector/rocksdb_raw_vector.cc index 19c248f4..b9b348d8 100644 --- a/internal/engine/vector/rocksdb_raw_vector.cc +++ b/internal/engine/vector/rocksdb_raw_vector.cc @@ -25,10 +25,8 @@ RocksDBRawVector::RocksDBRawVector(VectorMetaInfo *meta_info, } RocksDBRawVector::~RocksDBRawVector() { - if (db_) { - delete db_; - db_ = nullptr; - } + delete db_; + db_ = nullptr; } int RocksDBRawVector::InitStore(std::string &vec_name) { diff --git a/internal/engine/vector/rocksdb_wrapper.cc b/internal/engine/vector/rocksdb_wrapper.cc index 244edd2e..3c3d5356 100644 --- a/internal/engine/vector/rocksdb_wrapper.cc +++ b/internal/engine/vector/rocksdb_wrapper.cc @@ -16,10 +16,8 @@ namespace vearch { RocksDBWrapper::RocksDBWrapper() : db_(nullptr) {} RocksDBWrapper::~RocksDBWrapper() { - if (db_) { - delete db_; - db_ = nullptr; - } + delete db_; + db_ = nullptr; } Status RocksDBWrapper::Open(string db_path, size_t block_cache_size) { diff --git a/internal/engine/vector/vector_manager.cc b/internal/engine/vector/vector_manager.cc index f86ee48f..199de925 100644 --- a/internal/engine/vector/vector_manager.cc +++ b/internal/engine/vector/vector_manager.cc @@ -31,25 +31,29 @@ VectorManager::VectorManager(const VectorStorageType &store_type, VectorManager::~VectorManager() { Close(); } -int VectorManager::SetVectorStoreType(std::string &index_type, - std::string &store_type_str, - VectorStorageType &store_type) { +Status VectorManager::SetVectorStoreType(std::string &index_type, + std::string &store_type_str, + VectorStorageType &store_type) { if (store_type_str != "") { if (!strcasecmp("MemoryOnly", store_type_str.c_str())) { store_type = VectorStorageType::MemoryOnly; } else if (!strcasecmp("RocksDB", store_type_str.c_str())) { store_type = VectorStorageType::RocksDB; } else { - LOG(WARNING) << "NO support for store type " << store_type_str; - return -1; + std::stringstream msg; + msg << "NO support for store type " << store_type_str; + LOG(WARNING) << msg.str(); + return Status::NotSupported(msg.str()); } // ivfflat has raw vector data in index, so just use rocksdb to reduce // memory footprint if (index_type == "IVFFLAT" && strcasecmp("RocksDB", store_type_str.c_str())) { - LOG(ERROR) << "IVFFLAT should use RocksDB, now store_type = " - << store_type_str; - return -1; + std::stringstream msg; + msg << "IVFFLAT should use RocksDB, now store_type = " << store_type_str; + + LOG(ERROR) << msg.str(); + return Status::ParamError(msg.str()); } } else { if (index_type == "HNSW" || index_type == "FLAT") { @@ -60,25 +64,26 @@ int VectorManager::SetVectorStoreType(std::string &index_type, store_type_str = "RocksDB"; } } - return 0; + return Status::OK(); } -int VectorManager::CreateRawVector(struct VectorInfo &vector_info, - std::string &index_type, - std::map &vec_dups, - TableInfo &table, - utils::JsonParser &vectors_jp, - RawVector **vec) { +Status VectorManager::CreateRawVector(struct VectorInfo &vector_info, + std::string &index_type, + std::map &vec_dups, + TableInfo &table, + utils::JsonParser &vectors_jp, + RawVector **vec) { std::string &vec_name = vector_info.name; int dimension = vector_info.dimension; std::string &store_type_str = vector_info.store_type; VectorStorageType store_type = default_store_type_; - if (SetVectorStoreType(index_type, store_type_str, store_type)) { + Status status = SetVectorStoreType(index_type, store_type_str, store_type); + if (status != Status::OK()) { LOG(ERROR) << "set vector store type failed, store_type=" << store_type_str << ", index_type=" << index_type; - return -1; + return status; } std::string &store_param = vector_info.store_param; @@ -91,8 +96,7 @@ int VectorManager::CreateRawVector(struct VectorInfo &vector_info, std::string vec_root_path = root_path_ + "/vectors"; if (utils::make_dir(vec_root_path.c_str())) { - LOG(ERROR) << "make directory error, path=" << vec_root_path; - return -2; + return Status::IOError("make directory error, path=", vec_root_path); } VectorMetaInfo *meta_info = new VectorMetaInfo(vec_name, dimension, value_type); @@ -102,7 +106,7 @@ int VectorManager::CreateRawVector(struct VectorInfo &vector_info, Status status = store_params.Parse(store_param.c_str()); if (!status.ok()) { delete meta_info; - return status.code(); + return status; } } @@ -122,24 +126,25 @@ int VectorManager::CreateRawVector(struct VectorInfo &vector_info, if ((*vec) == nullptr) { LOG(ERROR) << "create raw vector error"; - return -1; + return Status::IOError("create raw vector error"); } LOG(INFO) << "create raw vector success, vec_name[" << vec_name << "] store_type[" << store_type_str << "]"; bool multi_vids = vec_dups[vec_name] > 1 ? true : false; int ret = (*vec)->Init(vec_name, multi_vids); if (ret != 0) { - LOG(ERROR) << "Raw vector " << vec_name << " init error, code [" << ret - << "]!"; + std::stringstream msg; + msg << "Raw vector " << vec_name << " init error, code [" << ret << "]!"; + LOG(ERROR) << msg.str(); RawVectorIO *rio = (*vec)->GetIO(); if (rio) { delete rio; rio = nullptr; } delete (*vec); - return -1; + return Status::IOError(msg.str()); } - return 0; + return Status::OK(); } void VectorManager::DestroyRawVectors() { @@ -156,7 +161,7 @@ void VectorManager::DestroyRawVectors() { LOG(INFO) << "Raw vector cleared."; } -int VectorManager::CreateVectorIndex( +Status VectorManager::CreateVectorIndex( std::string &index_type, std::string &index_params, RawVector *vec, int training_threshold, bool destroy_vec, std::map &vector_indexes) { @@ -167,8 +172,9 @@ int VectorManager::CreateVectorIndex( IndexModel *index_model = dynamic_cast(reflector().GetNewIndex(index_type)); if (index_model == nullptr) { - LOG(ERROR) << "Cannot get model=" << index_type - << ", vec_name=" << vec_name; + std::stringstream msg; + msg << "Cannot get model=" << index_type << ", vec_name=" << vec_name; + LOG(ERROR) << msg.str(); if (destroy_vec) { RawVectorIO *rio = vec->GetIO(); if (rio) { @@ -179,7 +185,7 @@ int VectorManager::CreateVectorIndex( delete vec; raw_vectors_[vec_name] = nullptr; } - return -1; + return Status::ParamError(msg.str()); } index_model->vector_ = vec; @@ -199,13 +205,13 @@ int VectorManager::CreateVectorIndex( index_model->vector_ = nullptr; delete index_model; index_model = nullptr; - return -1; + return status; } // init indexed count index_model->indexed_count_ = 0; vector_indexes[IndexName(vec_name, index_type)] = index_model; - return 0; + return Status::OK(); } void VectorManager::DestroyVectorIndexes() { @@ -227,25 +233,26 @@ void VectorManager::DescribeVectorIndexes() { } } -int VectorManager::CreateVectorIndexes( +Status VectorManager::CreateVectorIndexes( int training_threshold, std::map &vector_indexes) { - int ret = 0; for (const auto &[name, index] : raw_vectors_) { if (index != nullptr) { std::string &vec_name = index->MetaInfo()->Name(); for (size_t i = 0; i < index_types_.size(); ++i) { - ret = CreateVectorIndex(index_types_[i], index_params_[i], index, - training_threshold, false, vector_indexes); - if (ret) { - LOG(ERROR) << vec_name << " create index failed ret: " << ret; - return ret; + Status status = + CreateVectorIndex(index_types_[i], index_params_[i], index, + training_threshold, false, vector_indexes); + if (status != Status::OK()) { + LOG(ERROR) << vec_name + << " create index failed: " << status.ToString(); + return status; } } } } - return 0; + return Status::OK(); } void VectorManager::SetVectorIndexes( @@ -258,9 +265,10 @@ void VectorManager::SetVectorIndexes( } } -int VectorManager::CreateVectorTable(TableInfo &table, - utils::JsonParser *meta_jp) { - if (table_created_) return -1; +Status VectorManager::CreateVectorTable(TableInfo &table, + utils::JsonParser *meta_jp) { + Status status; + if (table_created_) return Status::ParamError("table is created"); std::map vec_dups; @@ -287,15 +295,18 @@ int VectorManager::CreateVectorTable(TableInfo &table, } for (size_t i = 0; i < vectors_infos.size(); i++) { - int ret = 0; + Status vec_status; RawVector *vec = nullptr; struct VectorInfo &vector_info = vectors_infos[i]; std::string &vec_name = vector_info.name; - ret = CreateRawVector(vector_info, index_types_[0], vec_dups, table, - vectors_jp, &vec); - if (ret) { - LOG(ERROR) << vec_name << " create vector failed ret:" << ret; - return ret; + vec_status = CreateRawVector(vector_info, index_types_[0], vec_dups, table, + vectors_jp, &vec); + if (vec_status != Status::OK()) { + std::stringstream msg; + msg << vec_name << " create vector failed:" << vec_status.ToString(); + LOG(ERROR) << msg.str(); + status = Status::ParamError(msg.str()); + return status; } raw_vectors_[vec_name] = vec; @@ -306,11 +317,12 @@ int VectorManager::CreateVectorTable(TableInfo &table, } for (size_t i = 0; i < index_types_.size(); ++i) { - ret = CreateVectorIndex(index_types_[i], index_params_[i], vec, - table.TrainingThreshold(), true, vector_indexes_); - if (ret) { - LOG(ERROR) << vec_name << " create index failed ret: " << ret; - return ret; + status = + CreateVectorIndex(index_types_[i], index_params_[i], vec, + table.TrainingThreshold(), true, vector_indexes_); + if (status != Status::OK()) { + LOG(ERROR) << vec_name << " create index failed: " << status.ToString(); + return status; } // update TrainingThreshold when TrainingThreshold = 0 if (!table.TrainingThreshold()) { @@ -325,7 +337,7 @@ int VectorManager::CreateVectorTable(TableInfo &table, table_created_ = true; LOG(INFO) << "create vectors and indexes success! models=" << utils::join(index_types_, ','); - return 0; + return Status::OK(); } int VectorManager::AddToStore( @@ -634,7 +646,8 @@ Status VectorManager::Search(GammaQuery &query, GammaResult *results) { if (cur_docid == start_docid) { common_docid_count++; // now just support WeightedRanker - WeightedRanker *ranker = dynamic_cast(query.condition->ranker); + WeightedRanker *ranker = + dynamic_cast(query.condition->ranker); float weight = 1.0 / vec_num; if (ranker != nullptr && ranker->weights.size() == vec_num) weight = ranker->weights[j]; diff --git a/internal/engine/vector/vector_manager.h b/internal/engine/vector/vector_manager.h index 392b2a24..0a983792 100644 --- a/internal/engine/vector/vector_manager.h +++ b/internal/engine/vector/vector_manager.h @@ -28,31 +28,34 @@ class VectorManager { const std::string &root_path); ~VectorManager(); - int SetVectorStoreType(std::string &index_type, std::string &store_type_str, - VectorStorageType &store_type); + Status SetVectorStoreType(std::string &index_type, + std::string &store_type_str, + VectorStorageType &store_type); - int CreateRawVector(struct VectorInfo &vector_info, std::string &index_type, - std::map &vec_dups, TableInfo &table, - utils::JsonParser &vectors_jp, RawVector **vec); + Status CreateRawVector(struct VectorInfo &vector_info, + std::string &index_type, + std::map &vec_dups, TableInfo &table, + utils::JsonParser &vectors_jp, RawVector **vec); void DestroyRawVectors(); - int CreateVectorIndex(std::string &index_type, std::string &index_params, - RawVector *vec, int training_threshold, - bool destroy_vec, - std::map &vector_indexes); + Status CreateVectorIndex(std::string &index_type, std::string &index_params, + RawVector *vec, int training_threshold, + bool destroy_vec, + std::map &vector_indexes); void DestroyVectorIndexes(); void DescribeVectorIndexes(); - int CreateVectorIndexes(int training_threshold, - std::map &vector_indexes); + Status CreateVectorIndexes( + int training_threshold, + std::map &vector_indexes); void SetVectorIndexes( std::map &rebuild_vector_indexes); - int CreateVectorTable(TableInfo &table, utils::JsonParser *jp); + Status CreateVectorTable(TableInfo &table, utils::JsonParser *jp); int AddToStore(int docid, std::unordered_map &fields);