mirror of
https://github.com/typesense/typesense.git
synced 2025-05-22 14:55:26 +08:00
Fix vector distance comparison bug
# Conflicts: # test/collection_vector_search_test.cpp
This commit is contained in:
parent
dfe3cdadb6
commit
a0cdaaa676
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user