Skip to content

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

Really fix the regression in flat search cutoff.

Kishore Nallan58c81989c553
diff --git a/src/index.cpp b/src/index.cpp
index 8eb8ee69..bdd8dae8 100644
--- a/src/index.cpp
+++ b/src/index.cpp
@@ -3069,6 +3069,10 @@ Option<bool> Index::search(std::vector<query_tokens_t>& field_query_tokens, cons
group_by_field_it_vec = get_group_by_field_iterators(group_by_fields);
}
+ std::sort(dist_results.begin(), dist_results.end(), [](const auto& p1, const auto& p2) {
+ return p1.first < p2.first;
+ });
+
for (auto& dist_result : dist_results) {
auto& seq_id = dist_result.second.seq_id;
auto references = std::move(dist_result.second.reference_filter_results);
@@ -3077,7 +3081,7 @@ Option<bool> Index::search(std::vector<query_tokens_t>& field_query_tokens, cons
continue;
}
- if(vector_query.query_doc_given && nearest_ids.size() >= k-1) {
+ if(vector_query.query_doc_given && nearest_ids.size() == k-1) {
// When id based vector query is made, we ask for K+1 results to account for the query
// record itself being returned. However, when the filter clause does not match the
// query record, we will end up returning 1 extra hit.
diff --git a/test/collection_vector_search_test.cpp b/test/collection_vector_search_test.cpp
index 053637d8..137409c6 100644
--- a/test/collection_vector_search_test.cpp
+++ b/test/collection_vector_search_test.cpp
@@ -768,7 +768,7 @@ TEST_F(CollectionVectorTest, VecSearchWithFiltering) {
ASSERT_EQ(10, results["hits"].size());
// with points:<10, flat-search
- results = coll1->search("*", {}, "points:<10", {}, {}, {0}, 20, 1, FREQUENCY, {true}, Index::DROP_TOKENS_THRESHOLD,
+ results = coll1->search("*", {}, "points:<10", {}, {}, {0}, 3, 1, FREQUENCY, {true}, Index::DROP_TOKENS_THRESHOLD,
spp::sparse_hash_set<std::string>(),
spp::sparse_hash_set<std::string>(), 10, "", 30, 5,
"", 10, {}, {}, {}, 0,
@@ -778,13 +778,33 @@ TEST_F(CollectionVectorTest, VecSearchWithFiltering) {
false, true, "vec:([0.96826, 0.94, 0.39557, 0.306488], flat_search_cutoff: 1000)").get();
ASSERT_EQ(10, results["found"].get<size_t>());
- ASSERT_EQ(10, results["hits"].size());
+ ASSERT_EQ(3, results["hits"].size());
ASSERT_FLOAT_EQ(3.409385e-05, results["hits"][0]["vector_distance"].get<float>());
ASSERT_EQ("1", results["hits"][0]["document"]["id"].get<std::string>());
ASSERT_FLOAT_EQ(0.016780376, results["hits"][1]["vector_distance"].get<float>());
ASSERT_EQ("5", results["hits"][1]["document"]["id"].get<std::string>());
+ results = coll1->search("*", {}, "points:<10", {}, {}, {0}, 3, 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: 3, flat_search_cutoff: 1000)").get();
+
+ ASSERT_EQ(3, results["hits"].size());
+
+ LOG(INFO) << results["hits"][0];
+ LOG(INFO) << results["hits"][1];
+
+ ASSERT_EQ("9", results["hits"][0]["document"]["id"].get<std::string>());
+ ASSERT_FLOAT_EQ(0.050603985, results["hits"][0]["vector_distance"].get<float>());
+
+ ASSERT_EQ("5", results["hits"][1]["document"]["id"].get<std::string>());
+ ASSERT_FLOAT_EQ(0.100155532, results["hits"][1]["vector_distance"].get<float>());
+
// single point
results = coll1->search("*", {}, "points:1", {}, {}, {0}, 20, 1, FREQUENCY, {true}, Index::DROP_TOKENS_THRESHOLD,