Elasticsearch使用默认余玄来计算如何让计算结果分数按照 consine 余弦大小来排序?

Elasticsearch使用默认的consine 余玄来计算,如何让计算结果分数按照 consine 余弦大小来排序?

展开
收起
鸡蛋灌饼儿 2023-01-27 14:22:30 354 分享 版权
2 条回答
写回答
取消 提交回答
  • 在使用阿里云 Elasticsearch 查询时,可以使用 "function_score" 查询来对结果进行排序。具体来说,可以使用 "script_score" 函数并在该函数中指定使用 consine 余弦相似度来计算分数。 比如: "text_vector" 是在 Elasticsearch 中存储的文本向量,"query_vector" 是查询词向量

    {
      "query": {
        "function_score": {
          "query": {
            "match": {
              "text": "your search term"
            }
          },
          "script_score": {
            "script": {
              "source": "cosineSimilarity(params.query_vector, 'text_vector') + 1.0",
              "params": {
                "query_vector": [1.0, 2.0, 3.0]
              }
            }
          }
        }
      }
    }
    
    
    2023-01-28 12:51:14
    赞同 展开评论
  • 可以使用Spring Shell在Kotlin中构建了一个包装器。它接受一个单词作为输入,从索引中检索相应的向量,然后执行script_score查询根据大小来进行降序排列。

    2023-01-28 07:58:54
    赞同 展开评论

阿里云检索分析服务Elasticsearch版兼容开源ELK功能,免运维全托管,提升企业数据检索与运维分析能力。

收录在圈子:

热门讨论

热门文章

还有其他疑问?
咨询AI助理