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 <hai.jin@zilliz.com>

Co-authored-by: JinHai-CN <hai.jin@zilliz.com>
This commit is contained in:
shana0325 2020-04-26 11:29:20 +08:00 committed by GitHub
parent d22f3c2c5f
commit 53133aafac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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<float>* 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<float>* 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<hnswlib::HierarchicalNSW<float>>(space, rows, config[IndexParams::M].get<int64_t>(),
config[IndexParams::efConstruction].get<int64_t>());
} catch (std::exception& e) {
KNOWHERE_THROW_MSG(e.what());
}
index_ = std::make_shared<hnswlib::HierarchicalNSW<float>>(space, rows, config[IndexParams::M].get<int64_t>(),
config[IndexParams::efConstruction].get<int64_t>());
}
void