Fix vector distance comparison bug

# Conflicts:
#	test/collection_vector_search_test.cpp
This commit is contained in:
ozanarmagan 2023-12-17 16:01:02 +03:00 committed by Kishore Nallan
parent dfe3cdadb6
commit a0cdaaa676
2 changed files with 35 additions and 2 deletions

View File

@ -2089,7 +2089,7 @@ Option<nlohmann::json> Collection::search(std::string raw_query,
wrapper_doc["geo_distance_meters"] = geo_distances;
}
if(!vector_query.field_name.empty() && field_order_kv->vector_distance > 0) {
if(!vector_query.field_name.empty() && field_order_kv->vector_distance >= 0) {
wrapper_doc["vector_distance"] = field_order_kv->vector_distance;
}

View File

@ -2900,4 +2900,37 @@ TEST_F(CollectionVectorTest, TestHybridSearchHiddenHits) {
ASSERT_EQ(3, hybrid_results["hits"].size());
ASSERT_FALSE(hybrid_results["hits"][0]["document"]["id"] == 0);
}
}
TEST_F(CollectionVectorTest, Test0VectorDistance) {
auto schema_json =
R"({
"name": "colors",
"fields": [
{"name": "rgb", "type":"float[]", "num_dim": 3}
]
})"_json;
auto collection_create_op = collectionManager.create_collection(schema_json);
ASSERT_TRUE(collection_create_op.ok());
auto coll = collection_create_op.get();
auto add_op = coll->add(R"({
"rgb": [0.9, 0.9, 0.9]
})"_json.dump());
ASSERT_TRUE(add_op.ok());
auto results = coll->search("*", {}, "", {}, {}, {0}, 10, 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, "rgb:([0.5, 0.5, 0.5])").get();
ASSERT_EQ(results["hits"].size(), 1);
ASSERT_EQ(results["hits"][0].count("vector_distance"), 1);
ASSERT_EQ(results["hits"][0]["vector_distance"], 0);
}