Skip to content
This repository has been archived by the owner on Aug 16, 2023. It is now read-only.

Commit

Permalink
Modify the search list size if this value not set in struct or too sm…
Browse files Browse the repository at this point in the history
…all (#911)

Signed-off-by: cqy123456 <[email protected]>
  • Loading branch information
cqy123456 authored May 29, 2023
1 parent d4c04d4 commit 1dc984d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
6 changes: 4 additions & 2 deletions knowhere/index/vector_index/IndexDiskANNConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,15 @@ to_json(Config& config, const DiskANNQueryConfig& query_conf) {
void
from_json(const Config& config, DiskANNQueryConfig& query_conf) {
CheckNumericParamAndSet<uint64_t>(config, kK, kKMinValue, kKMaxValue, query_conf.k);
if (config.contains(kSearchListSize)) {
auto search_list_threshold = query_conf.k < kKThreshold ? kKThreshold : query_conf.k;
if (config.contains(kSearchListSize) && config[kSearchListSize].get<uint32_t>() >= search_list_threshold) {
// The search_list_size should be no less than the k.
CheckNumericParamAndSet<uint32_t>(config, kSearchListSize, query_conf.k,
std::max(kSearchListSizeMaxValue, static_cast<uint32_t>(10 * query_conf.k)),
query_conf.search_list_size);
} else {
query_conf.search_list_size = query_conf.k < kKThreshold ? kKThreshold : query_conf.k;
// if search_list_size not set (==0), not in json string or smaller than k, modify the value.
query_conf.search_list_size = search_list_threshold;
}
CheckNumericParamAndSet<uint32_t>(config, kBeamwidth, kBeamwidthMinValue, kBeamwidthMaxValue, query_conf.beamwidth);
if (config.contains(kFilterThreshold)) {
Expand Down
2 changes: 1 addition & 1 deletion knowhere/index/vector_index/IndexDiskANNConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ struct DiskANNQueryConfig {
uint64_t k;
// A list of search_list sizes to perform searches with. Larger parameters will result in slower latencies, but
// higher accuracies. Must be at least the value of k.
uint32_t search_list_size;
uint32_t search_list_size = 0;
// The beamwidth to be used for search. This is the maximum number of IO requests each query will issue per
// iteration of search code. Larger beamwidth will result in fewer IO round-trips per query but might result in
// slightly higher total number of IO requests to SSD per query. For the highest query throughput with a fixed SSD
Expand Down
10 changes: 7 additions & 3 deletions unittest/test_diskann.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,13 @@ TEST_P(DiskANNTest, search_without_search_list_size) {
query_cfg["k"] = 32;
search_list_size = knowhere::DiskANNQueryConfig::Get(cfg).search_list_size;
EXPECT_EQ(search_list_size, 32);

knowhere::DiskANNQueryConfig tmp_config;
tmp_config.k = 10;
cfg.clear();
knowhere::DiskANNQueryConfig::Set(cfg, tmp_config);
search_list_size = knowhere::DiskANNQueryConfig::Get(cfg).search_list_size;
EXPECT_EQ(search_list_size, 16);
}

TEST_P(DiskANNTest, knn_search_test) {
Expand Down Expand Up @@ -719,9 +726,6 @@ TEST_P(DiskANNTest, config_test) {

// query config
knowhere::DiskANNQueryConfig query_conf_to_test = query_conf;
query_conf_to_test.k = 10;
query_conf_to_test.search_list_size = 9;
CheckConfigError<knowhere::DiskANNQueryConfig>(query_conf_to_test);

query_conf_to_test = query_conf;
query_conf_to_test.beamwidth = 0;
Expand Down

0 comments on commit 1dc984d

Please sign in to comment.