mirror of
https://github.com/typesense/typesense.git
synced 2025-05-21 22:33:27 +08:00
Fix k
value for id based vector search.
This commit is contained in:
parent
bc31be874a
commit
679a6cc62f
@ -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);
|
||||
|
@ -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>(),
|
||||
|
Loading…
x
Reference in New Issue
Block a user