Open Source alternative to Algolia + Pinecone and an Easier-to-Use alternative to ElasticSearch ⚡ 🔍 ✨ Fast, typo tolerant, in-memory fuzzy Search Engine for building delightful search experiences
C++ algoliadatastoreelasticsearchenterprise-searchfacetingfull-text-searchfuzzy-searchgeosearchin-memoryinstantsearchmerchandisingpineconesearchsearch-enginesemantic-searchsimilarity-searchsite-searchsynonymstypo-tolerancevector-search
Fix `k` value for id based vector search.
Kishore Nallan679a6cc62fa2
diff --git a/src/index.cpp b/src/index.cppindex 78fa2a16..126e579f 100644--- a/src/index.cpp+++ b/src/index.cpp@@ -2517,6 +2517,10 @@ void Index::search(std::vector<query_tokens_t>& field_query_tokens, const std::vif (!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);diff --git a/test/collection_vector_search_test.cpp b/test/collection_vector_search_test.cppindex 9ae9a9fb..2e207bbd 100644--- a/test/collection_vector_search_test.cpp+++ b/test/collection_vector_search_test.cpp@@ -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 errorres_op = coll1->search("*", {}, "", {}, {}, {0}, 10, 1, FREQUENCY, {true}, Index::DROP_TOKENS_THRESHOLD,spp::sparse_hash_set<std::string>(),