From 53133aafac1d016034e50630ae244504d9e30f9c Mon Sep 17 00:00:00 2001 From: shana0325 <33335490+shana0325@users.noreply.github.com> Date: Sun, 26 Apr 2020 11:29:20 +0800 Subject: [PATCH] train func add catch excetpion (#2096) * train func add catch excetpion Signed-off-by: shana0325 <645842705@qq.com> * Fix lint error Signed-off-by: JinHai-CN Co-authored-by: JinHai-CN --- .../knowhere/index/vector_index/IndexHNSW.cpp | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) 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