gpt4 book ai didi

elasticsearch - 在Elasticsearch中如何计算嵌套文档的相关性分数(TF/IDF)?

转载 作者:行者123 更新时间:2023-12-02 22:37:20 29 4
gpt4 key购买 nike

在嵌套字段上运行匹配查询时,是基于所有根文档中的所有嵌套文档还是仅基于单个根文档下的嵌套文档来计算每个嵌套文档的相关性得分?基本上,在计算TF / IDF时,用于IDF的集合的范围是什么?

这是一个嵌套的文档:

PUT /channels_index
{
"mappings": {
"channel": {
"properties": {
"username": { "type": "string" },
"posts": {
"type": "nested",
"properties": {
"link": { "type": "string" },
"caption": { "type": "string" },
}
}
}
}
}
}

这是查询:
GET channels/_search
{
"query": {
"nested": {
"path": "posts",
"query": {
"match": {
"posts.caption": "adidas"
}
},
"inner_hits": {}
}
}
}

但是,在我的结果中,即使第二份文档的内部匹配最高得分更高,但第一份文档的根得分却有所提高。
{
"hits": {
"total": 2,
"max_score": 4.3327584,
"hits": [
{
"_index": "channels",
"_type": "channel",
"_id": "1",
"_score": 4.3327584,
"_source": {
"username": "user1",
"posts": [...]
},
"inner_hits": {
"posts": {
"hits": {
"total": 2,
"max_score": 5.5447335,
"hits": [...]
}
}
}
},
{
"_index": "channels",
"_type": "channel",
"_id": "2",
"_score": 4.2954993,
"_source": {
"username": "user2",
"posts": [...]
},
"inner_hits": {
"posts": {
"hits": {
"total": 13,
"max_score": 11.446381,
"hits": [...]
}
}
}
}
]
}
}

最佳答案

在对查询运行解释之后,我可以看到内部匹配的TF / IDF分数确实是使用从所有根文档中的嵌套文档计算得出的IDF。

对于根文档评分,嵌套文档的默认评分模式是平均评分。如果我想使用嵌套文档的最大分数,可以通过定义一个score_mode来设置它。下面的查询显示了如何在文档上运行说明以及设置不同的评分模式。

GET channels/channel/1/_explain
{
"query": {
"nested": {
"path": "posts",
"score_mode": "max",
"query": {
"match": {
"posts.caption": "adidas"
}
},
"inner_hits": {}
}
}
}

关于elasticsearch - 在Elasticsearch中如何计算嵌套文档的相关性分数(TF/IDF)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46697441/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com