mirror of
https://gitee.com/milvus-io/milvus.git
synced 2026-01-01 00:15:30 +08:00
* General proto api for NNS libraries Signed-off-by: groot <yihua.mo@zilliz.com> * refactor confadapter Signed-off-by: Nicky <nicky.xj.lin@gmail.com> * fix unittest failures Signed-off-by: groot <yihua.mo@zilliz.com> * update test_add Signed-off-by: zhenwu <zw@zilliz.com> * update knowhere Signed-off-by: Nicky <nicky.xj.lin@gmail.com> * update test cases Signed-off-by: Xiaohai Xu <xiaohaix@student.unimelb.edu.au> * Update cases * C++ sdk for json parameters Signed-off-by: groot <yihua.mo@zilliz.com> * update unittest Signed-off-by: Nicky <nicky.xj.lin@gmail.com> * fix unittest failures Signed-off-by: groot <yihua.mo@zilliz.com> * fix case Signed-off-by: del-zhenwu <zw@zilliz.com> * modify test_index.py Signed-off-by: shengjh <jianghong.sheng@zilliz.com> * update Signed-off-by: Nicky <nicky.xj.lin@gmail.com> * update sptag Signed-off-by: Nicky <nicky.xj.lin@gmail.com> * update... Signed-off-by: Nicky <nicky.xj.lin@gmail.com> * Build Pass Signed-off-by: xiaojun.lin <xiaojun.lin@zilliz.com> * knowhere/wrapper ut pass Signed-off-by: xiaojun.lin <xiaojun.lin@zilliz.com> * update util Signed-off-by: Xiaohai Xu <xiaohaix@student.unimelb.edu.au> * fix wal case Signed-off-by: del-zhenwu <zw@zilliz.com> * modify test_search_vectors Signed-off-by: shengjh <jianghong.sheng@zilliz.com> * update ci Signed-off-by: del-zhenwu <zw@zilliz.com> * update util Signed-off-by: Xiaohai Xu <xiaohaix@student.unimelb.edu.au> * modify test_search_vectoes Signed-off-by: shengjh <jianghong.sheng@zilliz.com> * add hnsw in http module & modify index apis Signed-off-by: Yhz <yinghao.zou@zilliz.com> * modify search in http module Signed-off-by: Yhz <yinghao.zou@zilliz.com> * fix build error Signed-off-by: groot <yihua.mo@zilliz.com> * fix typo in test_index and test_search Signed-off-by: shengjh <jianghong.sheng@zilliz.com> * update... Signed-off-by: Nicky <nicky.xj.lin@gmail.com> * index apis in http module done Signed-off-by: Yhz <yinghao.zou@zilliz.com> * fix build index bug Signed-off-by: groot <yihua.mo@zilliz.com> * search apis unittest pass Signed-off-by: Yhz <yinghao.zou@zilliz.com> * web test pass Signed-off-by: Yhz <yinghao.zou@zilliz.com> * update confadapter Signed-off-by: Nicky <nicky.xj.lin@gmail.com> * update util Signed-off-by: Xiaohai Xu <xiaohaix@student.unimelb.edu.au> * code format Signed-off-by: groot <yihua.mo@zilliz.com> * code format Signed-off-by: groot <yihua.mo@zilliz.com> * fix vectors results bug (fix #1476) Signed-off-by: Yhz <yinghao.zou@zilliz.com> * clang format Signed-off-by: Yhz <yinghao.zou@zilliz.com> * update test Signed-off-by: shengjh <jianghong.sheng@zilliz.com> * fix unittest Signed-off-by: groot <yihua.mo@zilliz.com> * add test_config Signed-off-by: Xiaohai Xu <xiaohaix@student.unimelb.edu.au> * add log Signed-off-by: groot <yihua.mo@zilliz.com> * fix a build error Signed-off-by: groot <yihua.mo@zilliz.com> * add invalid param search test Signed-off-by: shengjh <jianghong.sheng@zilliz.com> * fix range check Signed-off-by: Nicky <nicky.xj.lin@gmail.com> * cpmpact/flush case passed Signed-off-by: del-zhenwu <zhenxiang.li@zilliz.com> * fix unittest failures Signed-off-by: groot <yihua.mo@zilliz.com> * fix unittest failures Signed-off-by: groot <yihua.mo@zilliz.com> * fix unittest failures Signed-off-by: groot <yihua.mo@zilliz.com> * validate json parameters in request Signed-off-by: groot <yihua.mo@zilliz.com> * add unittest cases Signed-off-by: groot <yihua.mo@zilliz.com> * update test index/search Signed-off-by: shengjh <jianghong.sheng@zilliz.com> * update test_config Signed-off-by: sahuang <xiaohaix@student.unimelb.edu.au> * fix Signed-off-by: shengjh <jianghong.sheng@zilliz.com> * support nsg and ivf-nlist Signed-off-by: Nicky <nicky.xj.lin@gmail.com> * update Signed-off-by: xiaojun.lin <xiaojun.lin@zilliz.com> * fix validation bug Signed-off-by: groot <yihua.mo@zilliz.com> * fix python test bug Signed-off-by: groot <yihua.mo@zilliz.com> * fix python test bug Signed-off-by: groot <yihua.mo@zilliz.com> * fix python test bug Signed-off-by: groot <yihua.mo@zilliz.com> * fix python test bug Signed-off-by: groot <yihua.mo@zilliz.com> * code format Signed-off-by: groot <yihua.mo@zilliz.com> * fix python test failure Signed-off-by: groot <yihua.mo@zilliz.com> * remove rnsg cases Signed-off-by: zhenwu <zw@zilliz.com> * fix python test failure Signed-off-by: groot <yihua.mo@zilliz.com> * Update changelog Signed-off-by: JinHai-CN <hai.jin@zilliz.com> * Fix typo Signed-off-by: JinHai-CN <hai.jin@zilliz.com> * add pq to test_index && multithread test Signed-off-by: shengjh <jianghong.sheng@zilliz.com> * add pq to test_search Signed-off-by: shengjh <jianghong.sheng@zilliz.com> * Fix format Signed-off-by: JinHai-CN <hai.jin@zilliz.com> * Update CHANGELOG Signed-off-by: JinHai-CN <hai.jin@zilliz.com> * Fix compiling error Signed-off-by: JinHai-CN <hai.jin@zilliz.com> * Fix compiling error Signed-off-by: JinHai-CN <hai.jin@zilliz.com> * fix config bug Signed-off-by: groot <yihua.mo@zilliz.com> * code format Signed-off-by: groot <yihua.mo@zilliz.com> * fix config test Signed-off-by: xiaojun.lin <xiaojun.lin@zilliz.com> * Update CHANGELOG.md Signed-off-by: JinHai-CN <hai.jin@zilliz.com> * Update CHANGELOG.md Signed-off-by: JinHai-CN <hai.jin@zilliz.com> * disable config test case Signed-off-by: zhenwu <zw@zilliz.com> Co-authored-by: Nicky <nicky.xj.lin@gmail.com> Co-authored-by: zhenwu <zw@zilliz.com> Co-authored-by: Xiaohai Xu <xiaohaix@student.unimelb.edu.au> Co-authored-by: shengjh <jianghong.sheng@zilliz.com> Co-authored-by: xiaojun.lin <xiaojun.lin@zilliz.com> Co-authored-by: Yhz <yinghao.zou@zilliz.com> Co-authored-by: del-zhenwu <zhenxiang.li@zilliz.com> Co-authored-by: JinHai-CN <hai.jin@zilliz.com>
209 lines
7.5 KiB
C++
209 lines
7.5 KiB
C++
// Copyright (C) 2019-2020 Zilliz. All rights reserved.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
|
|
// with the License. You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software distributed under the License
|
|
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
|
// or implied. See the License for the specific language governing permissions and limitations under the License.
|
|
|
|
#include "knowhere/index/vector_index/helpers/FaissGpuResourceMgr.h"
|
|
#include "knowhere/index/vector_index/helpers/IndexParameter.h"
|
|
#include "wrapper/VecIndex.h"
|
|
#include "wrapper/utils.h"
|
|
|
|
#include <gtest/gtest.h>
|
|
#include <fiu-local.h>
|
|
#include <fiu-control.h>
|
|
#include "knowhere/index/vector_index/IndexIVFSQHybrid.h"
|
|
|
|
using ::testing::Combine;
|
|
using ::testing::TestWithParam;
|
|
using ::testing::Values;
|
|
|
|
class KnowhereHybrid : public DataGenBase, public ::testing::Test {
|
|
protected:
|
|
void
|
|
SetUp() override {
|
|
knowhere::FaissGpuResourceMgr::GetInstance().InitDevice(DEVICEID, PINMEM, TEMPMEM, RESNUM);
|
|
|
|
dim = 128;
|
|
nb = 10000;
|
|
nq = 100;
|
|
k = 100;
|
|
GenData(dim, nb, nq, xb, xq, ids, k, gt_ids, gt_dis);
|
|
}
|
|
|
|
void
|
|
TearDown() override {
|
|
knowhere::FaissGpuResourceMgr::GetInstance().Free();
|
|
}
|
|
|
|
protected:
|
|
milvus::engine::IndexType index_type;
|
|
milvus::engine::VecIndexPtr index_ = nullptr;
|
|
knowhere::Config conf;
|
|
};
|
|
|
|
#ifdef CUSTOMIZATION
|
|
TEST_F(KnowhereHybrid, test_interface) {
|
|
assert(!xb.empty());
|
|
|
|
knowhere::Config tempconf{
|
|
{knowhere::Metric::TYPE, knowhere::Metric::L2},
|
|
{knowhere::meta::ROWS, nb},
|
|
{knowhere::meta::DIM, dim},
|
|
{knowhere::meta::TOPK, k},
|
|
{knowhere::meta::DEVICEID, DEVICEID}
|
|
};
|
|
|
|
index_type = milvus::engine::IndexType::FAISS_IVFSQ8_HYBRID;
|
|
index_ = GetVecIndexFactory(index_type);
|
|
conf = ParamGenerator::GetInstance().GenBuild(index_type, tempconf);
|
|
auto search_cfg = ParamGenerator::GetInstance().GenSearchConf(index_type, tempconf);
|
|
|
|
auto elems = nq * k;
|
|
std::vector<int64_t> res_ids(elems);
|
|
std::vector<float> res_dis(elems);
|
|
|
|
index_->BuildAll(nb, xb.data(), ids.data(), conf);
|
|
index_->Search(nq, xq.data(), res_dis.data(), res_ids.data(), search_cfg);
|
|
AssertResult(res_ids, res_dis);
|
|
EXPECT_EQ(index_->Count(), nb);
|
|
EXPECT_EQ(index_->Dimension(), dim);
|
|
|
|
auto binaryset = index_->Serialize();
|
|
{
|
|
// cpu -> gpu
|
|
auto cpu_idx = GetVecIndexFactory(index_type);
|
|
cpu_idx->Load(binaryset);
|
|
{
|
|
for (int i = 0; i < 2; ++i) {
|
|
auto gpu_idx = cpu_idx->CopyToGpu(DEVICEID, conf);
|
|
gpu_idx->Search(nq, xq.data(), res_dis.data(), res_ids.data(), search_cfg);
|
|
AssertResult(res_ids, res_dis);
|
|
}
|
|
}
|
|
}
|
|
|
|
{
|
|
// quantization already in gpu, only copy data
|
|
auto cpu_idx = GetVecIndexFactory(index_type);
|
|
cpu_idx->Load(binaryset);
|
|
|
|
auto pair = cpu_idx->CopyToGpuWithQuantizer(DEVICEID, conf);
|
|
auto gpu_idx = pair.first;
|
|
auto quantization = pair.second;
|
|
|
|
gpu_idx->Search(nq, xq.data(), res_dis.data(), res_ids.data(), search_cfg);
|
|
AssertResult(res_ids, res_dis);
|
|
|
|
milvus::json quantizer_conf {
|
|
{"mode", 2},
|
|
{knowhere::meta::DEVICEID, DEVICEID}
|
|
};
|
|
for (int i = 0; i < 2; ++i) {
|
|
auto hybrid_idx = GetVecIndexFactory(index_type);
|
|
hybrid_idx->Load(binaryset);
|
|
|
|
hybrid_idx->LoadData(quantization, quantizer_conf);
|
|
hybrid_idx->Search(nq, xq.data(), res_dis.data(), res_ids.data(), search_cfg);
|
|
AssertResult(res_ids, res_dis);
|
|
}
|
|
}
|
|
|
|
{
|
|
// quantization already in gpu, only set quantization
|
|
auto cpu_idx = GetVecIndexFactory(index_type);
|
|
cpu_idx->Load(binaryset);
|
|
|
|
auto pair = cpu_idx->CopyToGpuWithQuantizer(DEVICEID, conf);
|
|
auto quantization = pair.second;
|
|
|
|
for (int i = 0; i < 2; ++i) {
|
|
auto hybrid_idx = GetVecIndexFactory(index_type);
|
|
hybrid_idx->Load(binaryset);
|
|
|
|
hybrid_idx->SetQuantizer(quantization);
|
|
hybrid_idx->Search(nq, xq.data(), res_dis.data(), res_ids.data(), search_cfg);
|
|
AssertResult(res_ids, res_dis);
|
|
hybrid_idx->UnsetQuantizer();
|
|
}
|
|
}
|
|
}
|
|
|
|
// TEST_F(KnowhereHybrid, test_invalid_index) {
|
|
// assert(!xb.empty());
|
|
// fiu_init(0);
|
|
|
|
// index_type = milvus::engine::IndexType::FAISS_IVFSQ8_HYBRID;
|
|
// fiu_enable("GetVecIndexFactory.IVFSQHybrid.mock", 1, nullptr, 0);
|
|
// index_ = GetVecIndexFactory(index_type);
|
|
// fiu_disable("GetVecIndexFactory.IVFSQHybrid.mock");
|
|
// conf = ParamGenerator::GetInstance().Gen(index_type);
|
|
|
|
// auto elems = nq * k;
|
|
// std::vector<int64_t> res_ids(elems);
|
|
// std::vector<float> res_dis(elems);
|
|
|
|
// conf->gpu_id = DEVICEID;
|
|
// conf->d = dim;
|
|
// conf->k = k;
|
|
|
|
// auto status = index_->BuildAll(nb, xb.data(), ids.data(), conf);
|
|
// ASSERT_FALSE(status.ok());
|
|
|
|
// auto quantizer = std::make_shared<knowhere::Quantizer>();
|
|
// auto quantizer_cfg = std::make_shared<knowhere::QuantizerCfg>();
|
|
// index_->LoadQuantizer(quantizer_cfg);
|
|
// status = index_->SetQuantizer(quantizer);
|
|
// ASSERT_FALSE(status.ok());
|
|
|
|
// fiu_enable("IVFHybridIndex.SetQuantizer.throw_knowhere_exception", 1, nullptr, 0);
|
|
// status = index_->SetQuantizer(quantizer);
|
|
// ASSERT_FALSE(status.ok());
|
|
// fiu_disable("IVFHybridIndex.SetQuantizer.throw_knowhere_exception");
|
|
|
|
// fiu_enable("IVFHybridIndex.SetQuantizer.throw_std_exception", 1, nullptr, 0);
|
|
// status = index_->SetQuantizer(quantizer);
|
|
// ASSERT_FALSE(status.ok());
|
|
// fiu_disable("IVFHybridIndex.SetQuantizer.throw_std_exception");
|
|
|
|
// status = index_->UnsetQuantizer();
|
|
// ASSERT_FALSE(status.ok());
|
|
// fiu_enable("IVFHybridIndex.UnsetQuantizer.throw_knowhere_exception", 1, nullptr, 0);
|
|
// status = index_->UnsetQuantizer();
|
|
// ASSERT_FALSE(status.ok());
|
|
// fiu_disable("IVFHybridIndex.UnsetQuantizer.throw_knowhere_exception");
|
|
|
|
// fiu_enable("IVFHybridIndex.UnsetQuantizer.throw_std_exception", 1, nullptr, 0);
|
|
// status = index_->UnsetQuantizer();
|
|
// ASSERT_FALSE(status.ok());
|
|
// fiu_disable("IVFHybridIndex.UnsetQuantizer.throw_std_exception");
|
|
|
|
// auto vecindex = index_->LoadData(quantizer, quantizer_cfg);
|
|
// ASSERT_EQ(vecindex, nullptr);
|
|
|
|
// fiu_enable("IVFHybridIndex.LoadData.throw_std_exception", 1, nullptr, 0);
|
|
// vecindex = index_->LoadData(quantizer, quantizer_cfg);
|
|
// ASSERT_EQ(vecindex, nullptr);
|
|
// fiu_disable("IVFHybridIndex.LoadData.throw_std_exception");
|
|
|
|
// fiu_enable("IVFHybridIndex.LoadData.throw_knowhere_exception", 1, nullptr, 0);
|
|
// vecindex = index_->LoadData(quantizer, quantizer_cfg);
|
|
// ASSERT_EQ(vecindex, nullptr);
|
|
// fiu_disable("IVFHybridIndex.LoadData.throw_knowhere_exception");
|
|
|
|
// index_->CopyToGpuWithQuantizer(DEVICEID, conf);
|
|
// fiu_enable("IVFHybridIndex.LoadData.throw_knowhere_exception", 1, nullptr, 0);
|
|
// index_->CopyToGpuWithQuantizer(DEVICEID, conf);
|
|
// fiu_disable("IVFHybridIndex.LoadData.throw_knowhere_exception");
|
|
// fiu_enable("IVFHybridIndex.LoadData.throw_std_exception", 1, nullptr, 0);
|
|
// index_->CopyToGpuWithQuantizer(DEVICEID, conf);
|
|
// fiu_disable("IVFHybridIndex.LoadData.throw_std_exception");
|
|
// }
|
|
|
|
#endif
|