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

Commit 1dc984d

Browse files
authored
Modify the search list size if this value not set in struct or too small (#911)
Signed-off-by: cqy123456 <[email protected]>
1 parent d4c04d4 commit 1dc984d

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

knowhere/index/vector_index/IndexDiskANNConfig.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,13 +219,15 @@ to_json(Config& config, const DiskANNQueryConfig& query_conf) {
219219
void
220220
from_json(const Config& config, DiskANNQueryConfig& query_conf) {
221221
CheckNumericParamAndSet<uint64_t>(config, kK, kKMinValue, kKMaxValue, query_conf.k);
222-
if (config.contains(kSearchListSize)) {
222+
auto search_list_threshold = query_conf.k < kKThreshold ? kKThreshold : query_conf.k;
223+
if (config.contains(kSearchListSize) && config[kSearchListSize].get<uint32_t>() >= search_list_threshold) {
223224
// The search_list_size should be no less than the k.
224225
CheckNumericParamAndSet<uint32_t>(config, kSearchListSize, query_conf.k,
225226
std::max(kSearchListSizeMaxValue, static_cast<uint32_t>(10 * query_conf.k)),
226227
query_conf.search_list_size);
227228
} else {
228-
query_conf.search_list_size = query_conf.k < kKThreshold ? kKThreshold : query_conf.k;
229+
// if search_list_size not set (==0), not in json string or smaller than k, modify the value.
230+
query_conf.search_list_size = search_list_threshold;
229231
}
230232
CheckNumericParamAndSet<uint32_t>(config, kBeamwidth, kBeamwidthMinValue, kBeamwidthMaxValue, query_conf.beamwidth);
231233
if (config.contains(kFilterThreshold)) {

knowhere/index/vector_index/IndexDiskANNConfig.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ struct DiskANNQueryConfig {
8686
uint64_t k;
8787
// A list of search_list sizes to perform searches with. Larger parameters will result in slower latencies, but
8888
// higher accuracies. Must be at least the value of k.
89-
uint32_t search_list_size;
89+
uint32_t search_list_size = 0;
9090
// The beamwidth to be used for search. This is the maximum number of IO requests each query will issue per
9191
// iteration of search code. Larger beamwidth will result in fewer IO round-trips per query but might result in
9292
// slightly higher total number of IO requests to SSD per query. For the highest query throughput with a fixed SSD

unittest/test_diskann.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,13 @@ TEST_P(DiskANNTest, search_without_search_list_size) {
471471
query_cfg["k"] = 32;
472472
search_list_size = knowhere::DiskANNQueryConfig::Get(cfg).search_list_size;
473473
EXPECT_EQ(search_list_size, 32);
474+
475+
knowhere::DiskANNQueryConfig tmp_config;
476+
tmp_config.k = 10;
477+
cfg.clear();
478+
knowhere::DiskANNQueryConfig::Set(cfg, tmp_config);
479+
search_list_size = knowhere::DiskANNQueryConfig::Get(cfg).search_list_size;
480+
EXPECT_EQ(search_list_size, 16);
474481
}
475482

476483
TEST_P(DiskANNTest, knn_search_test) {
@@ -719,9 +726,6 @@ TEST_P(DiskANNTest, config_test) {
719726

720727
// query config
721728
knowhere::DiskANNQueryConfig query_conf_to_test = query_conf;
722-
query_conf_to_test.k = 10;
723-
query_conf_to_test.search_list_size = 9;
724-
CheckConfigError<knowhere::DiskANNQueryConfig>(query_conf_to_test);
725729

726730
query_conf_to_test = query_conf;
727731
query_conf_to_test.beamwidth = 0;

0 commit comments

Comments
 (0)