我使用存储在elasticsearch中的文本嵌入来获取与查询相似的文档。但我注意到,在某些情况下,我得到的文档中没有来自查询的单词,得分更高。所以我想提高具有来自查询的单词的文档的得分。我如何在elasticsearch中做到这一点?
这是我的索引
{
"mappings": {
"properties": {
"question_text": {
"type": "text"
},
"question_vector": {
"type": "dense_vector",
"dims": 768
}
}
}
}
我试过这么做
{
"query":{
"script_score": {
"query": {
"bool": {
"must": [
{
"more_like_this": {
"fields": [
"question_text"
],
"like": query_text,
"min_term_freq": 1,
"max_query_terms": 12,
"minimum_should_match": "3<60%"
}
}
]
}
},
"script": {
"source": "cosineSimilarity(params.query_vector, 'question_vector') + 1.0",
"params": {"query_vector": query_vector}
}
}
},
"fields": [
"question_text"
],
"_source": false
}
但是现在我只能得到包含单词的文档。有没有一种方法可以做到这一点,但仍然得到不包含单词的匹配,但得分较低?
2条答案
按热度按时间dy2hfwbg1#
使用功能分数查询。
说明:
boost -〉对整个查询进行boost
weight -〉boost for cosine function
final boost = query boost + function boost。
gpnt7bae2#
该查询选择所有文档并计算余弦相似度,然后减少没有匹配项的文档的得分。