Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add create index check for ScaNN and fix UTs #816

Merged
merged 1 commit into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/index/index_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "knowhere/index/index_factory.h"

#include "knowhere/index/index_table.h"
#include "simd/hook.h"

#ifdef KNOWHERE_WITH_RAFT
#include <cuda_runtime_api.h>
Expand Down Expand Up @@ -59,6 +60,11 @@ IndexFactory::Create(const std::string& name, const int32_t& version, const Obje
return expected<Index<IndexNode>>::Err(Status::cuda_runtime_error, "gpu not available");
}
#endif
if (name == knowhere::IndexEnum::INDEX_FAISS_SCANN && !faiss::support_pq_fast_scan) {
LOG_KNOWHERE_ERROR_ << "SCANN index is not supported on the current CPU model";
return expected<Index<IndexNode>>::Err(Status::invalid_index_error,
"SCANN index is not supported on the current CPU model");
}

return fun_map_v->fun_value(version, object);
}
Expand Down
12 changes: 11 additions & 1 deletion tests/ut/test_get_vector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "knowhere/comp/knowhere_check.h"
#include "knowhere/comp/knowhere_config.h"
#include "knowhere/index/index_factory.h"
#include "simd/hook.h"
#include "utils.h"
TEST_CASE("Test Binary Get Vector By Ids", "[Binary GetVectorByIds]") {
using Catch::Approx;
Expand Down Expand Up @@ -177,7 +178,16 @@ TEST_CASE("Test Float Get Vector By Ids", "[Float GetVectorByIds]") {
make_tuple(knowhere::IndexEnum::INDEX_FAISS_SCANN, scann_gen2),
make_tuple(knowhere::IndexEnum::INDEX_HNSW, hnsw_gen),
}));
auto idx = knowhere::IndexFactory::Instance().Create<knowhere::fp32>(name, version).value();

auto idx_expected = knowhere::IndexFactory::Instance().Create<knowhere::fp32>(name, version);
if (name == knowhere::IndexEnum::INDEX_FAISS_SCANN) {
// need to check cpu model for scann
if (!faiss::support_pq_fast_scan) {
REQUIRE(idx_expected.error() == knowhere::Status::invalid_index_error);
return;
}
}
auto idx = idx_expected.value();
auto cfg_json = gen().dump();
CAPTURE(name, cfg_json);
knowhere::Json json = knowhere::Json::parse(cfg_json);
Expand Down
31 changes: 28 additions & 3 deletions tests/ut/test_search.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "knowhere/comp/knowhere_config.h"
#include "knowhere/index/index_factory.h"
#include "knowhere/log.h"
#include "simd/hook.h"
#include "utils.h"

namespace {
Expand Down Expand Up @@ -166,7 +167,15 @@ TEST_CASE("Test Mem Index With Float Vector", "[float metrics]") {
make_tuple(knowhere::IndexEnum::INDEX_HNSW_SQ8, hnsw_gen),
make_tuple(knowhere::IndexEnum::INDEX_HNSW_SQ8_REFINE, hnsw_gen),
}));
auto idx = knowhere::IndexFactory::Instance().Create<knowhere::fp32>(name, version).value();
auto idx_expected = knowhere::IndexFactory::Instance().Create<knowhere::fp32>(name, version);
if (name == knowhere::IndexEnum::INDEX_FAISS_SCANN) {
// need to check cpu model for scann
if (!faiss::support_pq_fast_scan) {
REQUIRE(idx_expected.error() == knowhere::Status::invalid_index_error);
return;
}
}
auto idx = idx_expected.value();
auto cfg_json = gen().dump();
CAPTURE(name, cfg_json);
knowhere::Json json = knowhere::Json::parse(cfg_json);
Expand Down Expand Up @@ -218,7 +227,15 @@ TEST_CASE("Test Mem Index With Float Vector", "[float metrics]") {
make_tuple(knowhere::IndexEnum::INDEX_HNSW_SQ8, hnsw_gen),
make_tuple(knowhere::IndexEnum::INDEX_HNSW_SQ8_REFINE, hnsw_gen),
}));
auto idx = knowhere::IndexFactory::Instance().Create<knowhere::fp32>(name, version).value();
auto idx_expected = knowhere::IndexFactory::Instance().Create<knowhere::fp32>(name, version);
if (name == knowhere::IndexEnum::INDEX_FAISS_SCANN) {
// need to check cpu model for scann
if (!faiss::support_pq_fast_scan) {
REQUIRE(idx_expected.error() == knowhere::Status::invalid_index_error);
return;
}
}
auto idx = idx_expected.value();
auto cfg_json = gen().dump();
CAPTURE(name, cfg_json);
knowhere::Json json = knowhere::Json::parse(cfg_json);
Expand Down Expand Up @@ -426,7 +443,15 @@ TEST_CASE("Test Mem Index With Float Vector", "[float metrics]") {
make_tuple(knowhere::IndexEnum::INDEX_HNSW_SQ8_REFINE, hnsw_gen),
}));

auto idx = knowhere::IndexFactory::Instance().Create<knowhere::fp32>(name, version).value();
auto idx_expected = knowhere::IndexFactory::Instance().Create<knowhere::fp32>(name, version);
if (name == knowhere::IndexEnum::INDEX_FAISS_SCANN) {
// need to check cpu model for scann
if (!faiss::support_pq_fast_scan) {
REQUIRE(idx_expected.error() == knowhere::Status::invalid_index_error);
return;
}
}
auto idx = idx_expected.value();
auto cfg_json = gen().dump();
CAPTURE(name, cfg_json);
knowhere::Json json = knowhere::Json::parse(cfg_json);
Expand Down
Loading