ES搜索排序,文档相关度评分介绍——Vector Space Model

简介:

Vector Space Model

The vector space model provides a way of comparing a multiterm query against a document. The output is a single score that represents how well the document matches the query. In order to do this, the model represents both the document and the query as vectors.

A vector is really just a one-dimensional array containing numbers, for example:

[1,2,5,22,3,8]

In the vector space model, each number in the vector is the weight of a term, as calculated with term frequency/inverse document frequency.

Tip

While TF/IDF is the default way of calculating term weights for the vector space model, it is not the only way. Other models like Okapi-BM25 exist and are available in Elasticsearch. TF/IDF is the default because it is a simple, efficient algorithm that produces high-quality search results and has stood the test of time.

Imagine that we have a query for “happy hippopotamus.” A common word like happy will have a low weight, while an uncommon term like hippopotamus will have a high weight. Let’s assume that happyhas a weight of 2 and hippopotamus has a weight of 5. We can plot this simple two-dimensional vector—[2,5]—as a line on a graph starting at point (0,0) and ending at point (2,5), as shown inFigure 27, “A two-dimensional query vector for “happy hippopotamus” represented”.

Figure 27. A two-dimensional query vector for “happy hippopotamus” represented

The query vector plotted on a graph

 

Now, imagine we have three documents:

  1. I am happy in summer.
  2. After Christmas I’m a hippopotamus.
  3. The happy hippopotamus helped Harry.

We can create a similar vector for each document, consisting of the weight of each query term—happy and hippopotamus—that appears in the document, and plot these vectors on the same graph, as shown in Figure 28, “Query and document vectors for “happy hippopotamus””:

  • Document 1: (happy,____________)—[2,0]
  • Document 2: ( ___ ,hippopotamus)—[0,5]
  • Document 3: (happy,hippopotamus)—[2,5]

Figure 28. Query and document vectors for “happy hippopotamus”

The query and document vectors plotted on a graph

 

The nice thing about vectors is that they can be compared. By measuring the angle between the query vector and the document vector, it is possible to assign a relevance score to each document. The angle between document 1 and the query is large, so it is of low relevance. Document 2 is closer to the query, meaning that it is reasonably relevant, and document 3 is a perfect match.

Tip

In practice, only two-dimensional vectors (queries with two terms) can be plotted easily on a graph. Fortunately, linear algebra—the branch of mathematics that deals with vectors—provides tools to compare the angle between multidimensional vectors, which means that we can apply the same principles explained above to queries that consist of many terms.

You can read more about how to compare two vectors by using cosine similarity.

Now that we have talked about the theoretical basis of scoring, we can move on to see how scoring is implemented in Lucene.












本文转自张昺华-sky博客园博客,原文链接:http://www.cnblogs.com/bonelee/p/6474138.html,如需转载请自行联系原作者


相关文章
|
XML C# 数据格式
掌握了在Windows平台上查看DLL依赖的方法
掌握了在Windows平台上查看DLL依赖的方法
4731 4
|
关系型数据库 MySQL Java
mysql连接池和redis连接池
mysql连接池和redis连接池
579 0
|
人工智能 自然语言处理 IDE
CodeFuse IDE 0.7 版本发布,支持 Lint Error 智能改写
CodeFuse IDE 0.7 版本发布,支持 Lint Error 智能改写和 zsh 终端自然语言生成命令。它基于蚂蚁自研大模型和 OpenSumi 框架开发,提供代码编写建议、解释、单测生成等功能,提升开发效率。内置插件升级至 VS Code 1.88.1,未来将支持更多模型服务。下载地址:[GitHub](https://github.com/codefuse-ai/codefuse-ide/releases)。
1712 4
|
关系型数据库 MySQL Apache
实时计算 Flink版操作报错之mysql整库同步到doris连接器报错,如何解决
在使用实时计算Flink版过程中,可能会遇到各种错误,了解这些错误的原因及解决方法对于高效排错至关重要。针对具体问题,查看Flink的日志是关键,它们通常会提供更详细的错误信息和堆栈跟踪,有助于定位问题。此外,Flink社区文档和官方论坛也是寻求帮助的好去处。以下是一些常见的操作报错及其可能的原因与解决策略。
|
监控 中间件 测试技术
『软件测试5』测开岗只要求会黑白盒测试?NO!还要学会性能测试!
该文章指出软件测试工程师不仅需要掌握黑盒和白盒测试,还应该了解性能测试的重要性及其实现方法,包括负载测试、压力测试等多种性能测试类型及其在保证软件质量中的作用。
『软件测试5』测开岗只要求会黑白盒测试?NO!还要学会性能测试!
|
前端开发 API 数据库
告别繁琐,拥抱简洁!Python RESTful API 设计实战,让 API 调用如丝般顺滑!
【7月更文挑战第23天】在Python的Flask框架下构建RESTful API,为在线商店管理商品、订单及用户信息。以商品管理为例,设计简洁API端点,如GET `/products`获取商品列表,POST `/products`添加商品,PUT和DELETE则分别用于更新和删除商品。使用SQLAlchemy ORM与SQLite数据库交互,确保数据一致性。实战中还应加入数据验证、错误处理和权限控制,使API既高效又安全,便于前端或其他服务无缝对接。
476 9
|
Java
SpringBoot启动报错:Unable to start LiveReload server【已解决】
SpringBoot启动报错:Unable to start LiveReload server【已解决】
1212 1
|
JavaScript 前端开发 编译器
纯前端如何实现批量dom转图片,并下载成压缩包
【8月更文挑战第22天】纯前端如何实现批量dom转图片,并下载成压缩包
877 0
|
缓存 前端开发 算法
浅谈【JavaScript】的浏览器指纹?
浅谈【JavaScript】的浏览器指纹?
512 0
1个非常实用的找影视片段的工具神器,赶紧来白嫖!
只需要输入对应的关键词,就能快速找到大量的相关素材,从而大大缩短了我们的搜集时间。
4096 0
1个非常实用的找影视片段的工具神器,赶紧来白嫖!