Skip to content

Commit

Permalink
Update all APIs' input parameter to 'const DataSetPtr' (zilliztech#667)
Browse files Browse the repository at this point in the history
Signed-off-by: Cai Yudong <yudong.cai@zilliz.com>
  • Loading branch information
cydrain authored and zihengsjtu@gmail.com committed Jul 23, 2024
1 parent 06ba9f1 commit 84d830c
Show file tree
Hide file tree
Showing 38 changed files with 352 additions and 364 deletions.
6 changes: 3 additions & 3 deletions benchmark/hdf5/benchmark_binary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Benchmark_binary : public Benchmark_knowhere, public ::testing::Test {
knowhere::DataSetPtr ds_ptr = knowhere::GenDataSet(nq, dim_, xq_);
for (auto k : TOPKs_) {
conf[knowhere::meta::TOPK] = k;
CALC_TIME_SPAN(auto result = index_.value().Search(*ds_ptr, conf, nullptr));
CALC_TIME_SPAN(auto result = index_.value().Search(ds_ptr, conf, nullptr));
auto ids = result.value()->GetIds();
float recall = CalcRecall(ids, nq, k);
printf(" nq = %4d, k = %4d, elapse = %6.3fs, R@ = %.4f\n", nq, k, t_diff, recall);
Expand All @@ -55,7 +55,7 @@ class Benchmark_binary : public Benchmark_knowhere, public ::testing::Test {
knowhere::DataSetPtr ds_ptr = knowhere::GenDataSet(nq, dim_, xq_);
for (auto k : TOPKs_) {
conf[knowhere::meta::TOPK] = k;
CALC_TIME_SPAN(auto result = index_.value().Search(*ds_ptr, conf, nullptr));
CALC_TIME_SPAN(auto result = index_.value().Search(ds_ptr, conf, nullptr));
auto ids = result.value()->GetIds();
float recall = CalcRecall(ids, nq, k);
printf(" nprobe = %4d, nq = %4d, k = %4d, elapse = %6.3fs, R@ = %.4f\n", nprobe, nq, k, t_diff,
Expand Down Expand Up @@ -83,7 +83,7 @@ class Benchmark_binary : public Benchmark_knowhere, public ::testing::Test {
auto ds_ptr = knowhere::GenDataSet(nq, dim_, xq_);
for (auto k : TOPKs_) {
conf[knowhere::meta::TOPK] = k;
CALC_TIME_SPAN(auto result = index_.value().Search(*ds_ptr, conf, nullptr));
CALC_TIME_SPAN(auto result = index_.value().Search(ds_ptr, conf, nullptr));
auto ids = result.value()->GetIds();
float recall = CalcRecall(ids, nq, k);
printf(" ef = %4d, nq = %4d, k = %4d, elapse = %6.3fs, R@ = %.4f\n", ef, nq, k, t_diff, recall);
Expand Down
6 changes: 3 additions & 3 deletions benchmark/hdf5/benchmark_binary_range.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Benchmark_binary_range : public Benchmark_knowhere, public ::testing::Test
printf("================================================================================\n");
for (auto nq : NQs_) {
knowhere::DataSetPtr ds_ptr = knowhere::GenDataSet(nq, dim_, xq_);
CALC_TIME_SPAN(auto result = index_.value().RangeSearch(*ds_ptr, conf, nullptr));
CALC_TIME_SPAN(auto result = index_.value().RangeSearch(ds_ptr, conf, nullptr));
auto ids = result.value()->GetIds();
auto distances = result.value()->GetDistance();
auto lims = result.value()->GetLims();
Expand All @@ -56,7 +56,7 @@ class Benchmark_binary_range : public Benchmark_knowhere, public ::testing::Test
conf[knowhere::indexparam::NPROBE] = nprobe;
for (auto nq : NQs_) {
knowhere::DataSetPtr ds_ptr = knowhere::GenDataSet(nq, dim_, xq_);
CALC_TIME_SPAN(auto result = index_.value().RangeSearch(*ds_ptr, conf, nullptr));
CALC_TIME_SPAN(auto result = index_.value().RangeSearch(ds_ptr, conf, nullptr));
auto ids = result.value()->GetIds();
auto lims = result.value()->GetLims();
float recall = CalcRecall(ids, lims, nq);
Expand Down Expand Up @@ -84,7 +84,7 @@ class Benchmark_binary_range : public Benchmark_knowhere, public ::testing::Test
conf[knowhere::indexparam::EF] = ef;
for (auto nq : NQs_) {
knowhere::DataSetPtr ds_ptr = knowhere::GenDataSet(nq, dim_, xq_);
CALC_TIME_SPAN(auto result = index_.value().RangeSearch(*ds_ptr, conf, nullptr));
CALC_TIME_SPAN(auto result = index_.value().RangeSearch(ds_ptr, conf, nullptr));
auto ids = result.value()->GetIds();
auto lims = result.value()->GetLims();
float recall = CalcRecall(ids, lims, nq);
Expand Down
10 changes: 5 additions & 5 deletions benchmark/hdf5/benchmark_float.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Benchmark_float : public Benchmark_knowhere, public ::testing::Test {
auto ds_ptr = knowhere::GenDataSet(nq, dim_, xq_);
for (auto k : TOPKs_) {
conf[knowhere::meta::TOPK] = k;
CALC_TIME_SPAN(auto result = index_.value().Search(*ds_ptr, conf, nullptr));
CALC_TIME_SPAN(auto result = index_.value().Search(ds_ptr, conf, nullptr));
auto ids = result.value()->GetIds();
float recall = CalcRecall(ids, nq, k);
printf(" nq = %4d, k = %4d, elapse = %6.3fs, R@ = %.4f\n", nq, k, t_diff, recall);
Expand All @@ -56,7 +56,7 @@ class Benchmark_float : public Benchmark_knowhere, public ::testing::Test {
auto ds_ptr = knowhere::GenDataSet(nq, dim_, xq_);
for (auto k : TOPKs_) {
conf[knowhere::meta::TOPK] = k;
CALC_TIME_SPAN(auto result = index_.value().Search(*ds_ptr, conf, nullptr));
CALC_TIME_SPAN(auto result = index_.value().Search(ds_ptr, conf, nullptr));
auto ids = result.value()->GetIds();
float recall = CalcRecall(ids, nq, k);
printf(" nprobe = %4d, nq = %4d, k = %4d, elapse = %6.3fs, R@ = %.4f\n", nprobe, nq, k, t_diff,
Expand Down Expand Up @@ -84,7 +84,7 @@ class Benchmark_float : public Benchmark_knowhere, public ::testing::Test {
auto ds_ptr = knowhere::GenDataSet(nq, dim_, xq_);
for (auto k : TOPKs_) {
conf[knowhere::meta::TOPK] = k;
CALC_TIME_SPAN(auto result = index_.value().Search(*ds_ptr, conf, nullptr));
CALC_TIME_SPAN(auto result = index_.value().Search(ds_ptr, conf, nullptr));
auto ids = result.value()->GetIds();
float recall = CalcRecall(ids, nq, k);
printf(" ef = %4d, nq = %4d, k = %4d, elapse = %6.3fs, R@ = %.4f\n", ef, nq, k, t_diff, recall);
Expand All @@ -109,7 +109,7 @@ class Benchmark_float : public Benchmark_knowhere, public ::testing::Test {
auto ds_ptr = knowhere::GenDataSet(nq, dim_, xq_);
for (auto k : TOPKs_) {
conf[knowhere::meta::TOPK] = k;
CALC_TIME_SPAN(auto result = index_.value().Search(*ds_ptr, conf, nullptr));
CALC_TIME_SPAN(auto result = index_.value().Search(ds_ptr, conf, nullptr));
auto ids = result.value()->GetIds();
float recall = CalcRecall(ids, nq, k);
printf(" search_list_size = %4d, nq = %4d, k = %4d, elapse = %6.3fs, R@ = %.4f\n",
Expand Down Expand Up @@ -261,7 +261,7 @@ TEST_F(Benchmark_float, TEST_DISKANN) {
index_type_, knowhere::Version::GetCurrentVersion().VersionNumber(), diskann_index_pack);
printf("[%.3f s] Building all on %d vectors\n", get_time_diff(), nb_);
knowhere::DataSetPtr ds_ptr = nullptr;
index_.value().Build(*ds_ptr, conf);
index_.value().Build(ds_ptr, conf);

knowhere::BinarySet binset;
index_.value().Serialize(binset);
Expand Down
14 changes: 7 additions & 7 deletions benchmark/hdf5/benchmark_float_bitset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ class Benchmark_float_bitset : public Benchmark_knowhere, public ::testing::Test
auto ds_ptr = knowhere::GenDataSet(nq, dim_, xq_);
for (auto k : TOPKs_) {
conf[knowhere::meta::TOPK] = k;
auto g_result = golden_index_.value().Search(*ds_ptr, conf, bitset);
auto g_result = golden_index_.value().Search(ds_ptr, conf, bitset);
auto g_ids = g_result.value()->GetIds();
CALC_TIME_SPAN(auto result = index_.value().Search(*ds_ptr, conf, bitset));
CALC_TIME_SPAN(auto result = index_.value().Search(ds_ptr, conf, bitset));
auto ids = result.value()->GetIds();
float recall = CalcRecall(g_ids, ids, nq, k);
printf(" bitset_per = %3d%%, nq = %4d, k = %4d, elapse = %6.3fs, R@ = %.4f\n", per, nq, k, t_diff,
Expand All @@ -72,9 +72,9 @@ class Benchmark_float_bitset : public Benchmark_knowhere, public ::testing::Test
auto ds_ptr = knowhere::GenDataSet(nq, dim_, xq_);
for (auto k : TOPKs_) {
conf[knowhere::meta::TOPK] = k;
auto g_result = golden_index_.value().Search(*ds_ptr, conf, bitset);
auto g_result = golden_index_.value().Search(ds_ptr, conf, bitset);
auto g_ids = g_result.value()->GetIds();
CALC_TIME_SPAN(auto result = index_.value().Search(*ds_ptr, conf, bitset));
CALC_TIME_SPAN(auto result = index_.value().Search(ds_ptr, conf, bitset));
auto ids = result.value()->GetIds();
float recall = CalcRecall(g_ids, ids, nq, k);
printf(" bitset_per = %3d%%, nq = %4d, k = %4d, elapse = %6.3fs, R@ = %.4f\n", per, nq, k, t_diff,
Expand All @@ -101,9 +101,9 @@ class Benchmark_float_bitset : public Benchmark_knowhere, public ::testing::Test
auto ds_ptr = knowhere::GenDataSet(nq, dim_, xq_);
for (auto k : TOPKs_) {
conf[knowhere::meta::TOPK] = k;
auto g_result = golden_index_.value().Search(*ds_ptr, conf, bitset);
auto g_result = golden_index_.value().Search(ds_ptr, conf, bitset);
auto g_ids = g_result.value()->GetIds();
CALC_TIME_SPAN(auto result = index_.value().Search(*ds_ptr, conf, bitset));
CALC_TIME_SPAN(auto result = index_.value().Search(ds_ptr, conf, bitset));
auto ids = result.value()->GetIds();
float recall = CalcRecall(g_ids, ids, nq, k);
printf(" bitset_per = %3d%%, nq = %4d, k = %4d, elapse = %6.3fs, R@ = %.4f\n", per, nq, k, t_diff,
Expand Down Expand Up @@ -224,7 +224,7 @@ TEST_F(Benchmark_float_bitset, TEST_DISKANN) {
index_ = knowhere::IndexFactory::Instance().Create<knowhere::fp32>(index_type_, version, diskann_index_pack);
printf("[%.3f s] Building all on %d vectors\n", get_time_diff(), nb_);
knowhere::DataSetPtr ds_ptr = nullptr;
index_.value().Build(*ds_ptr, conf);
index_.value().Build(ds_ptr, conf);

knowhere::BinarySet binset;
index_.value().Serialize(binset);
Expand Down
10 changes: 5 additions & 5 deletions benchmark/hdf5/benchmark_float_qps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Benchmark_float_qps : public Benchmark_knowhere, public ::testing::Test {
nprobe = left + (right - left) / 2;
conf[knowhere::indexparam::NPROBE] = nprobe;

auto result = index_.value().Search(*ds_ptr, conf, nullptr);
auto result = index_.value().Search(ds_ptr, conf, nullptr);
recall = CalcRecall(result.value()->GetIds(), nq_, topk_);
printf("[%0.3f s] iterate IVF param for recall %.4f: nlist=%d, nprobe=%4d, k=%d, R@=%.4f\n",
get_time_diff(), expected_recall, nlist, nprobe, topk_, recall);
Expand Down Expand Up @@ -88,7 +88,7 @@ class Benchmark_float_qps : public Benchmark_knowhere, public ::testing::Test {
max_iterations = left + (right - left) / 2;
conf[knowhere::indexparam::MAX_ITERATIONS] = max_iterations;

auto result = index_.value().Search(*ds_ptr, conf, nullptr);
auto result = index_.value().Search(ds_ptr, conf, nullptr);
recall = CalcRecall(result.value()->GetIds(), nq_, topk_);
printf(
"[%0.3f s] iterate CAGRA param for recall %.4f: max_iterations=%d, k=%d, "
Expand Down Expand Up @@ -143,7 +143,7 @@ class Benchmark_float_qps : public Benchmark_knowhere, public ::testing::Test {
ef = left + (right - left) / 2;
conf[knowhere::indexparam::EF] = ef;

auto result = index_.value().Search(*ds_ptr, conf, nullptr);
auto result = index_.value().Search(ds_ptr, conf, nullptr);
recall = CalcRecall(result.value()->GetIds(), nq_, topk_);
printf("[%0.3f s] iterate HNSW param for expected recall %.4f: M=%d, efc=%d, ef=%4d, k=%d, R@=%.4f\n",
get_time_diff(), expected_recall, M, efConstruction, ef, topk_, recall);
Expand Down Expand Up @@ -196,7 +196,7 @@ class Benchmark_float_qps : public Benchmark_knowhere, public ::testing::Test {
nprobe = left + (right - left) / 2;
conf[knowhere::indexparam::NPROBE] = nprobe;

auto result = index_.value().Search(*ds_ptr, conf, nullptr);
auto result = index_.value().Search(ds_ptr, conf, nullptr);
recall = CalcRecall(result.value()->GetIds(), nq_, topk_);
printf(
"[%0.3f s] iterate scann param for recall %.4f: nlist=%d, nprobe=%4d, reorder_k=%d, "
Expand Down Expand Up @@ -241,7 +241,7 @@ class Benchmark_float_qps : public Benchmark_knowhere, public ::testing::Test {
num = std::min(num, nq_total - idx_start);
for (int32_t i = 0; i < num; i++) {
knowhere::DataSetPtr ds_ptr = knowhere::GenDataSet(1, dim_, (const float*)xq_ + (idx_start + i) * dim_);
index_.value().Search(*ds_ptr, conf, nullptr);
index_.value().Search(ds_ptr, conf, nullptr);
}
};

Expand Down
10 changes: 5 additions & 5 deletions benchmark/hdf5/benchmark_float_range.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Benchmark_float_range : public Benchmark_knowhere, public ::testing::Test
printf("================================================================================\n");
for (auto nq : NQs_) {
knowhere::DataSetPtr ds_ptr = knowhere::GenDataSet(nq, dim_, xq_);
CALC_TIME_SPAN(auto result = index_.value().RangeSearch(*ds_ptr, conf, nullptr));
CALC_TIME_SPAN(auto result = index_.value().RangeSearch(ds_ptr, conf, nullptr));
auto ids = result.value()->GetIds();
auto distances = result.value()->GetDistance();
auto lims = result.value()->GetLims();
Expand Down Expand Up @@ -58,7 +58,7 @@ class Benchmark_float_range : public Benchmark_knowhere, public ::testing::Test
conf[knowhere::indexparam::NPROBE] = nprobe;
for (auto nq : NQs_) {
knowhere::DataSetPtr ds_ptr = knowhere::GenDataSet(nq, dim_, xq_);
CALC_TIME_SPAN(auto result = index_.value().RangeSearch(*ds_ptr, conf, nullptr));
CALC_TIME_SPAN(auto result = index_.value().RangeSearch(ds_ptr, conf, nullptr));
auto ids = result.value()->GetIds();
auto lims = result.value()->GetLims();
float recall = CalcRecall(ids, lims, nq);
Expand Down Expand Up @@ -86,7 +86,7 @@ class Benchmark_float_range : public Benchmark_knowhere, public ::testing::Test
conf[knowhere::indexparam::EF] = ef;
for (auto nq : NQs_) {
knowhere::DataSetPtr ds_ptr = knowhere::GenDataSet(nq, dim_, xq_);
CALC_TIME_SPAN(auto result = index_.value().RangeSearch(*ds_ptr, conf, nullptr));
CALC_TIME_SPAN(auto result = index_.value().RangeSearch(ds_ptr, conf, nullptr));
auto ids = result.value()->GetIds();
auto lims = result.value()->GetLims();
float recall = CalcRecall(ids, lims, nq);
Expand All @@ -113,7 +113,7 @@ class Benchmark_float_range : public Benchmark_knowhere, public ::testing::Test
conf["search_list_size"] = search_list_size;
for (auto nq : NQs_) {
auto ds_ptr = knowhere::GenDataSet(nq, dim_, xq_);
CALC_TIME_SPAN(auto result = index_.value().RangeSearch(*ds_ptr, conf, nullptr));
CALC_TIME_SPAN(auto result = index_.value().RangeSearch(ds_ptr, conf, nullptr));
auto ids = result.value()->GetIds();
auto lims = result.value()->GetLims();
float recall = CalcRecall(ids, lims, nq);
Expand Down Expand Up @@ -304,7 +304,7 @@ TEST_F(Benchmark_float_range, TEST_DISKANN) {
index_type_, knowhere::Version::GetCurrentVersion().VersionNumber(), diskann_index_pack);
printf("[%.3f s] Building all on %d vectors\n", get_time_diff(), nb_);
knowhere::DataSetPtr ds_ptr = nullptr;
index_.value().Build(*ds_ptr, conf);
index_.value().Build(ds_ptr, conf);

knowhere::BinarySet binset;
index_.value().Serialize(binset);
Expand Down
14 changes: 7 additions & 7 deletions benchmark/hdf5/benchmark_float_range_bitset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ class Benchmark_float_range_bitset : public Benchmark_knowhere, public ::testing

for (auto nq : NQs_) {
auto ds_ptr = knowhere::GenDataSet(nq, dim_, xq_);
auto g_result = golden_index_.value().RangeSearch(*ds_ptr, conf, bitset);
auto g_result = golden_index_.value().RangeSearch(ds_ptr, conf, bitset);
auto g_ids = g_result.value()->GetIds();
auto g_lims = g_result.value()->GetLims();
CALC_TIME_SPAN(auto result = index_.value().RangeSearch(*ds_ptr, conf, bitset));
CALC_TIME_SPAN(auto result = index_.value().RangeSearch(ds_ptr, conf, bitset));
auto ids = result.value()->GetIds();
auto lims = result.value()->GetLims();
float recall = CalcRecall(g_ids, g_lims, ids, lims, nq);
Expand Down Expand Up @@ -74,10 +74,10 @@ class Benchmark_float_range_bitset : public Benchmark_knowhere, public ::testing

for (auto nq : NQs_) {
auto ds_ptr = knowhere::GenDataSet(nq, dim_, xq_);
auto g_result = golden_index_.value().RangeSearch(*ds_ptr, conf, bitset);
auto g_result = golden_index_.value().RangeSearch(ds_ptr, conf, bitset);
auto g_ids = g_result.value()->GetIds();
auto g_lims = g_result.value()->GetLims();
CALC_TIME_SPAN(auto result = index_.value().RangeSearch(*ds_ptr, conf, bitset));
CALC_TIME_SPAN(auto result = index_.value().RangeSearch(ds_ptr, conf, bitset));
auto ids = result.value()->GetIds();
auto lims = result.value()->GetLims();
float recall = CalcRecall(g_ids, g_lims, ids, lims, nq);
Expand Down Expand Up @@ -105,10 +105,10 @@ class Benchmark_float_range_bitset : public Benchmark_knowhere, public ::testing
knowhere::BitsetView bitset(bitset_data.data(), nb_);
for (auto nq : NQs_) {
auto ds_ptr = knowhere::GenDataSet(nq, dim_, xq_);
auto g_result = golden_index_.value().RangeSearch(*ds_ptr, conf, bitset);
auto g_result = golden_index_.value().RangeSearch(ds_ptr, conf, bitset);
auto g_ids = g_result.value()->GetIds();
auto g_lims = g_result.value()->GetLims();
CALC_TIME_SPAN(auto result = index_.value().RangeSearch(*ds_ptr, conf, bitset));
CALC_TIME_SPAN(auto result = index_.value().RangeSearch(ds_ptr, conf, bitset));
auto ids = result.value()->GetIds();
auto lims = result.value()->GetLims();
float recall = CalcRecall(g_ids, g_lims, ids, lims, nq);
Expand Down Expand Up @@ -223,7 +223,7 @@ TEST_F(Benchmark_float_range_bitset, TEST_DISKANN) {
index_ = knowhere::IndexFactory::Instance().Create<knowhere::fp32>(index_type_, version, diskann_index_pack);
printf("[%.3f s] Building all on %d vectors\n", get_time_diff(), nb_);
knowhere::DataSetPtr ds_ptr = nullptr;
index_.value().Build(*ds_ptr, conf);
index_.value().Build(ds_ptr, conf);

knowhere::BinarySet binset;
index_.value().Serialize(binset);
Expand Down
Loading

0 comments on commit 84d830c

Please sign in to comment.