Fix k value for id based vector search.

This commit is contained in:
Kishore Nallan 2023-01-05 14:08:46 +05:30
parent bc31be874a
commit 679a6cc62f
2 changed files with 15 additions and 0 deletions

View File

@ -2517,6 +2517,10 @@ void Index::search(std::vector<query_tokens_t>& field_query_tokens, const std::v
if (!vector_query.field_name.empty()) {
auto k = std::max<size_t>(vector_query.k, per_page * page);
if(vector_query.query_doc_given) {
// since we will omit the query doc from results
k++;
}
VectorFilterFunctor filterFunctor(filter_ids, filter_ids_length);
auto& field_vector_index = vector_index.at(vector_query.field_name);

View File

@ -159,6 +159,17 @@ TEST_F(CollectionVectorTest, BasicVectorQuerying) {
ASSERT_STREQ("0", results["hits"][0]["document"]["id"].get<std::string>().c_str());
ASSERT_STREQ("2", results["hits"][1]["document"]["id"].get<std::string>().c_str());
// `k` value should work correctly
results = coll1->search("*", {}, "", {}, {}, {0}, 1, 1, FREQUENCY, {true}, Index::DROP_TOKENS_THRESHOLD,
spp::sparse_hash_set<std::string>(),
spp::sparse_hash_set<std::string>(), 10, "", 30, 5,
"", 10, {}, {}, {}, 0,
"<mark>", "</mark>", {}, 1000, true, false, true, "", false, 6000 * 1000, 4, 7, fallback,
4, {off}, 32767, 32767, 2,
false, true, "vec:([], id: 1, k: 1)").get();
ASSERT_EQ(1, results["hits"].size());
// when `id` does not exist, return appropriate error
res_op = coll1->search("*", {}, "", {}, {}, {0}, 10, 1, FREQUENCY, {true}, Index::DROP_TOKENS_THRESHOLD,
spp::sparse_hash_set<std::string>(),