From 45a74e1560f77fb6cf4c98827458b5da377aa446 Mon Sep 17 00:00:00 2001 From: Xu Peng Date: Wed, 17 Apr 2019 10:22:38 +0800 Subject: [PATCH] refactor(db): using index factory Former-commit-id: 7026fb087240214666a43f1c486d2683a5a1ecb2 --- cpp/src/db/DBImpl.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cpp/src/db/DBImpl.cpp b/cpp/src/db/DBImpl.cpp index a076606515..62821c556c 100644 --- a/cpp/src/db/DBImpl.cpp +++ b/cpp/src/db/DBImpl.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include "DBImpl.h" #include "DBMetaImpl.h" #include "Env.h" @@ -113,21 +114,20 @@ Status DBImpl::merge_files(const std::string& group_id, const meta::DateT& date, return status; } - faiss::IndexFlat innerIndex(group_file.dimension); - faiss::IndexIDMap index(&innerIndex); + std::shared_ptr index(faiss::index_factory(group_file.dimension, "IDMap,Flat")); meta::GroupFilesSchema updated; for (auto& file : files) { auto file_index = dynamic_cast(faiss::read_index(file.location.c_str())); - index.add_with_ids(file_index->ntotal, dynamic_cast(file_index->index)->xb.data(), + index->add_with_ids(file_index->ntotal, dynamic_cast(file_index->index)->xb.data(), file_index->id_map.data()); auto file_schema = file; file_schema.file_type = meta::GroupFileSchema::TO_DELETE; updated.push_back(file_schema); } - faiss::write_index(&index, group_file.location.c_str()); + faiss::write_index(index.get(), group_file.location.c_str()); group_file.file_type = meta::GroupFileSchema::RAW; updated.push_back(group_file); status = _pMeta->update_files(updated);