Fix text match score being overwritten.

This commit is contained in:
Kishore Nallan 2024-11-07 18:22:38 +05:30
parent 32598540c6
commit fd100f73d0
2 changed files with 4 additions and 14 deletions

View File

@ -3632,7 +3632,6 @@ Option<bool> Index::search(std::vector<query_tokens_t>& field_query_tokens, cons
// old_score + (1 / rank_of_document) * WEIGHT)
found_kv->vector_distance = vec_result.second;
found_kv->text_match_score = found_kv->scores[found_kv->match_score_index];
int64_t match_score = float_to_int64_t(
(int64_t_to_float(found_kv->scores[found_kv->match_score_index])) +
((1.0 / (seq_id_to_rank[seq_id] + 1)) * VECTOR_SEARCH_WEIGHT));
@ -7889,15 +7888,6 @@ void Index::compute_aux_scores(Topster *topster, const std::vector<search_field_
std::sort(result_ids.begin(), result_ids.end(), [&](const auto& kv1, const auto& kv2) {
return kv1->text_match_score > kv2->text_match_score;
});
//start after already found ids
for(int i = 0; i < result_ids.size(); ++i) {
auto& kv = result_ids[i];
if(kv->text_match_score) { //skip the ids which have 0 text match score
kv->text_match_score = float_to_int64_t(
(1.0 / (found_ids_offset + i)) * (1.0 - vector_query.alpha));
}
}
}
for(posting_list_t* plist: expanded_plists) {

View File

@ -5154,7 +5154,7 @@ TEST_F(CollectionVectorTest, HybridSearchAuxScoreTest) {
ASSERT_FLOAT_EQ(0.15472877025604248, res["hits"][2]["vector_distance"].get<float>());
ASSERT_FLOAT_EQ(0.2496563196182251, res["hits"][3]["vector_distance"].get<float>());
ASSERT_EQ(1060320051, res["hits"][0]["text_match"].get<std::size_t>());
ASSERT_EQ(1736172819517014137, res["hits"][0]["text_match"].get<std::size_t>());
ASSERT_EQ(0, res["hits"][1]["text_match"].get<std::size_t>());
ASSERT_EQ(0, res["hits"][2]["text_match"].get<std::size_t>());
ASSERT_EQ(0, res["hits"][3]["text_match"].get<std::size_t>());
@ -5186,9 +5186,9 @@ TEST_F(CollectionVectorTest, HybridSearchAuxScoreTest) {
ASSERT_FLOAT_EQ(0.15472877025604248, res["hits"][2]["vector_distance"].get<float>());
ASSERT_FLOAT_EQ(0.2496563196182251, res["hits"][3]["vector_distance"].get<float>());
ASSERT_EQ(1060320051, res["hits"][0]["text_match"].get<std::size_t>());
ASSERT_EQ(1051931443, res["hits"][1]["text_match"].get<std::size_t>());
ASSERT_EQ(1047457519, res["hits"][2]["text_match"].get<std::size_t>());
ASSERT_EQ(1736172819517014137, res["hits"][0]["text_match"].get<std::size_t>());
ASSERT_EQ(2211897868288, res["hits"][1]["text_match"].get<std::size_t>());
ASSERT_EQ(1108091338752, res["hits"][2]["text_match"].get<std::size_t>());
ASSERT_EQ(0, res["hits"][3]["text_match"].get<std::size_t>()); //document with id:3 won't have any text_match
}