When I sort by `_text_match:desc` , i found that r...
# community-help
a
When I sort by
_text_match:desc
, i found that results are not truely sorted by
_text_match
score. I have printed the normalised score.
Copy code
1.0
1.0
1.0
1.0
1.0
0.8569848525430065
1.0
1.0
0.9999999909374664
0.8569848434804729
0.9999999909374664
0.9999999909374664
0.9999999909374664
This is my sort by query:
"sort_by": f"_eval(variants.{city_code}_in_stock:true):desc,_text_match:desc"
After testing more, i figured it out that even the item present at 0 index do not have highest score.
Few items also have 0 zero score. How can some item have 0 score because it has some vector score?
f
Your
sort_by
clause doesn't rank text match score highest, but tie-breaks on in-stock city code items first. You're boosting those results up, regardless of text match, and then use text match on top to sort the new list.
a
But this is not the case, all the items with in_stock true are not sorted by text match score. and how can a item has 0 text match score, Item has "vector_distance":
0.7403973340988159
"rank_fusion_score":
0.17045454680919647
But "text_match":
0
j
Hi Ayush. In hybrid search,
text_match
and
_text_match
are not the same. Hybrid search combines the
text_match
score with
vector_distance
to create
rank_fusion_score
, and then sets
_text_match = rank_fusion_score
. All the items with
in_stock: true
might not be sorted by
text_match
, but they should be sorted by`rank_fusion_score`. That is also why some documents might have
text_match: 0
, because they have a
vector_distance
that makes their
rank_fusion_score
high enough to put them in the results.
a
Ok. I got confused. I thought
_text_match
and
text_match
are same.
Can I also get to know how
rank_fusion_score
is calculated? Because, when i set
alpha: 0
,
rank_fusion_score
is not same for items with same
text_score
.
Also, I want to know can I sort by
text_match
and use
vector_distance
score as a tie breaker.
Copy code
"query_by": "variants.item_name,animal_type,flavor_name,item_form,age_range_description,variants.category_name,variants.sub_category_name,embedding",
        "query_by_weights": "3,2,1,1,2,2,1,1",
One more issue, Im facing is for my this query, I have given different weightage to each field but still
text_score
is same for all if it finds matching tokens in any one of the field ignoring weightage at all.
f
The rank fusion score is based on rank position, not the raw text score itself. So when alpha is 0, Typesense is using only the keyword rank. That means two items can have the same text score but still end up with different rank fusion scores if their final keyword rank position is different after tie handling.
Copy code
rank_fusion_score = (1 / keyword_rank)  (1 - alpha) + (1 / semantic_rank) * alpha
but if alpha’s 0 then
Copy code
rank_fusion_score = 1 / keyword_rank
You can sort by text match first and use vector distance as a tie-breaker:
Copy code
sort_by=_text_match:desc,_vector_distance:asc
​