diff --git a/core/src/index/knowhere/knowhere/index/vector_index/IndexHNSW.cpp b/core/src/index/knowhere/knowhere/index/vector_index/IndexHNSW.cpp index 3d14d1be8e..858f60e121 100644 --- a/core/src/index/knowhere/knowhere/index/vector_index/IndexHNSW.cpp +++ b/core/src/index/knowhere/knowhere/index/vector_index/IndexHNSW.cpp @@ -76,17 +76,21 @@ IndexHNSW::Load(const BinarySet& index_binary) { void IndexHNSW::Train(const DatasetPtr& dataset_ptr, const Config& config) { - GETTENSOR(dataset_ptr) + try { + GETTENSOR(dataset_ptr) - hnswlib::SpaceInterface* space; - if (config[Metric::TYPE] == Metric::L2) { - space = new hnswlib::L2Space(dim); - } else if (config[Metric::TYPE] == Metric::IP) { - space = new hnswlib::InnerProductSpace(dim); - normalize = true; + hnswlib::SpaceInterface* space; + if (config[Metric::TYPE] == Metric::L2) { + space = new hnswlib::L2Space(dim); + } else if (config[Metric::TYPE] == Metric::IP) { + space = new hnswlib::InnerProductSpace(dim); + normalize = true; + } + index_ = std::make_shared>(space, rows, config[IndexParams::M].get(), + config[IndexParams::efConstruction].get()); + } catch (std::exception& e) { + KNOWHERE_THROW_MSG(e.what()); } - index_ = std::make_shared>(space, rows, config[IndexParams::M].get(), - config[IndexParams::efConstruction].get()); } void