共用方式為

Azure AI 搜索中的相关性

在查询作中,任何给定结果的相关性由排名算法确定,该算法根据查询与索引文档的接近程度来评估匹配的强度。 找到匹配项时,算法会分配一个分数,结果按该分数进行排名,并在响应中返回最上面的结果。

每当查询请求包含全文或矢量查询时,就会进行排名。 如果查询调用严格的模式匹配,例如仅筛选查询或专用查询表单(如自动完成、建议、地理空间搜索、模糊搜索或正则表达式搜索),则不会发生这种情况。 统一搜索分数为 1.0 表示缺少排名算法。

排名级别

Azure AI 搜索中的查询引擎支持多级方法来对搜索结果进行排名,其中每个查询类型都有内置的排名形式,以及用于扩展相关性优化的额外排名功能。

本部分介绍评分操作的级别。 有关它们如何协同工作的说明,请参阅本文中的 关系图 。 本文还提供了 所有搜索分数类型和范围的比较

级别 Description
级别 1 (L1) 初始搜索分数 (@search.score)。
对于与标记化字符串匹配的文本查询,结果始终使用 BM25 排名算法进行初始排名。
对于向量查询,使用 分层可导航小世界(HNSW)或详尽的 K 近邻(KNN) 对结果进行排序。 图像搜索或多模式搜索基于矢量查询,并使用 L1 矢量排名算法评分。
融合L1 使用倒数排名融合(RRF)算法从多个查询中进行评分。 RRF 用于包含文本和矢量组件的混合查询。 当多个矢量查询并行执行时,也会使用 RRF。 RRF 的@search.score搜索分数反映在不同的范围内
级别 2 (L2) 语义排名分数 (@search.reRankerScore 将计算机读取理解应用于 L1 排名检索的文本内容,并重新记录 L1 结果以更好地匹配查询的语义意向。 L2 重新排序 L1 结果,因为这样可以节省时间和金钱。将语义排序用作 L1 排名系统成本高昂。 语义排名是一项高级功能,会根据使用语义排名模型的情况进行计费。

相关性优化

相关性优化 是一种基于附加条件(如加权字段、新鲜度或邻近度)提升搜索分数的技术。 在 Azure AI 搜索中,相关性优化选项因查询类型而异:

  • 对于关键字或混合搜索中的文本和数字(非函数)内容,可以通过 评分配置文件 或调用 语义排名器来优化相关性。

  • 对于混合查询中的矢量内容,可以 加权向量字段 ,以提高矢量组件相对于混合查询的文本组件的重要性。

  • 对于纯矢量查询,可以在分层导航小世界(HNSW)和全量 K近邻搜索(KNN)之间进行实验,以确定哪种算法在你的场景中表现更好。 在查询时进行详尽 KNN 替换的 HNSW 图形是对比测试中最灵活的方法。 还可以试验各种嵌入模型,以查看哪些模型产生更高质量的结果。 最后,请记住,混合查询或在包含非向量字段的文档上的向量查询均在相关性优化范围内,因此只有向量字段本身无法参与相关性优化。

使用计分配置文件的自定义提升逻辑

计分配置文件 是一项可选功能,用于根据额外的用户定义条件提升评分。 条件可以包括加权字段,其中在特定字段中找到的匹配项的权重高于在不同字段中找到的相同匹配项。 可以通过提升新鲜度、邻近度、数量级或范围的函数来定义条件。 没有与计分配置文件相关的额外费用。 若要使用计分配置文件,请在索引中定义它,然后在查询中指定它。

评分逻辑适用于文本和非向量数值内容。 可以将计分配置文件与...一起使用:

对于独立文本查询,评分配置文件会在 BM25 排序的搜索中识别出前 1,000 个匹配项,并在响应中返回排名前 50 的匹配项。

对于纯粹向量,查询仅涉及向量,但如果 k 匹配的文档 包含具有人类可读内容的非向量字段,则评分模型将应用于文档中的非向量字段 k

对于混合查询的文本组件,评分规则识别 BM25 排名搜索结果中的前 1,000 个匹配项。 但是,一旦识别了这 1,000 个结果,它们就会还原到其原始的 BM25 顺序,以便将其与向量结果一起重新评分以便纳入到最终 倒数排名函数(RRF) 排序中,其中评分配置文件(在图中标识为“最终文档加权调整”)应用于合并结果,以及 向量权重以及 语义排名 作为最后一步。

对于语义排名查询(图中未显示),假设使用最新的预览版 REST API 或预览版 Azure SDK 包,计分配置文件可以应用于 L2 排名结果集,从而生成确定最终排名的新 @search.rerankerBoostedScore 结果集。

搜索分数的类型

为查询响应中的每个匹配项指示评分结果。 下表列出了具有关联范围的所有搜索分数。 范围因算法而异。

得分 范围 算法
@search.score 0 到无限制 文本搜索的 BM25 排名算法
@search.score 0.333 - 1.00 用于矢量搜索的 HNSW 或详尽 KNN 算法
@search.score 0 到查询数确定的上限 RRF 算法
@search.rerankerScore 0.00 - 4.00 L2 排序的语义排序算法
@search.rerankerBoostedScore 0 到无限制 具有评分模型提升的语义排名 (分数可能明显高于 4)

排名算法示意图

下图说明了排名算法如何协同工作。

显示哪些字段具有评分配置文件以及何时进行排名的图表。

注释

此工作流关系图当前省略了@search.rerankerBoostedScore,以及从评分配置文件中提升的语义排名步骤。 如果将语义排名与计分配置文件一起使用,则评分配置文件在 L2 排名后应用,最终分数基于 @search.rerankerBoostedScore

包含所有排名算法的示例查询

生成上一个工作流的查询可能如以下示例所示。 此混合语义查询使用 RRF(基于文本和矢量的 L1 分数)和语义排名进行评分。

POST https://{{search-service-name}}.search.azure.cn/indexes/{{index-name}}/docs/search?api-version=2025-08-01-preview

{
  "search": "cloud formation over water",
  "count": true,
  "vectorQueries": [
    {
      "kind": "text",
      "text": "cloud formation over water",
      "fields": "text_vector,image_vector"
    }
  ],
  "queryType": "semantic",
  "semanticConfiguration": "my-semantic-configuration",
  "select": "title,chunk",
  "top": 5
}

上述查询的响应包含原始 RRF @search.core@search.rerankerScore.

  "value": [
    {
      "@search.score": 0.03177805617451668,
      "@search.rerankerScore": 2.6919238567352295,
      "chunk": "A\nT\n\nM\nO\n\nS\nP\n\nH\nE\n\nR\nE\n\nE\nA\n\nR\nT\n\nH\n\n32\n\nFraming an Iceberg\nSouth Atlantic Ocean\n\nIn June 2016, the Suomi NPP satellite captured this image of various cloud formations in the South Atlantic Ocean. Note how low \n\nstratus clouds framed a hole over iceberg A-56 as it drifted across the sea. \n\nThe exact reason for the hole in the clouds is somewhat of a mystery. It could have formed by chance, although imagery from the \n\ndays before and after this date suggest something else was at work. It could be that the relatively unobstructed path of the clouds \n\nover the ocean surface was interrupted by thermal instability created by the iceberg. In other words, if an obstacle is big enough,  \n\nit can divert the low-level atmospheric flow of air around it, a phenomenon often caused by islands.",
      "title": "page-39.pdf",
    },
    {
      "@search.score": 0.030621785670518875,
      "@search.rerankerScore": 2.557225465774536,
      "chunk": "A\nT\n\nM\nO\n\nS\nP\n\nH\nE\n\nR\nE\n\nE\nA\n\nR\nT\n\nH\n\n24\n\nMaking Tracks\nPacific Ocean\n\nShips steaming across the Pacific Ocean left this cluster of bright cloud trails lingering in the atmosphere in February 2012. The \n\nnarrow clouds, known as ship tracks, form when water vapor condenses around tiny particles of pollution from ship exhaust. The \n\ncrisscrossing clouds off the coast of California stretched for many hundreds of kilometers from end to end. The narrow ends of the \n\nclouds are youngest, while the broader, wavier ends are older.\n\nSome of the pollution particles generated by ships (especially sulfates) are soluble in water and can serve as the seeds around which \n\ncloud droplets form. Clouds infused with ship exhaust have more and smaller droplets than unpolluted clouds. As a result, light \n\nhitting the ship tracks scatters in many directions, often making them appear brighter than other types of marine clouds, which are \n\nusually seeded by larger, naturally occurring particles like sea salt.",
      "title": "page-31.pdf",
    },
    {
      "@search.score": 0.013698630034923553,
      "@search.rerankerScore": 2.515575408935547,
      "chunk": "A\nT\n\nM\nO\n\nS\nP\n\nH\nE\n\nR\nE\n\nE\nA\n\nR\nT\n\nH\n\n16\n\nRiding the Waves\nMauritania\n\nYou cannot see it directly, but air masses from Africa and the Atlantic Ocean are colliding in this Landsat 8 image from August 2016. \n\nThe collision off the coast of Mauritania produces a wave structure in the atmosphere. \n\nCalled an undular bore or solitary wave, this cloud formation was created by the interaction between cool, dry air coming off the \n\ncontinent and running into warm, moist air over the ocean. The winds blowing out from the land push a wave of air ahead like a  \n\nbow wave moving ahead of a boat. \n\nParts of these waves are favorable for cloud formation, while other parts are not. The dust blowing out from Africa appears to be \n\nriding these waves. Dust has been known to affect cloud growth, but it probably has little to do with the cloud pattern observed here.",
      "title": "page-23.pdf",
    },
    {
      "@search.score": 0.028949543833732605,
      "@search.rerankerScore": 2.4990925788879395,
      "chunk": "A\nT\n\nM\nO\n\nS\nP\n\nH\nE\n\nR\nE\n\nE\nA\n\nR\nT\n\nH\n\n14\n\nBering Streets\nArctic Ocean\n\nWinds from the northeast pushed sea ice southward and formed cloud streets—parallel rows of clouds—over the Bering Strait in \n\nJanuary 2010. The easternmost reaches of Russia, blanketed in snow and ice, appear in the upper left. To the east, sea ice spans \n\nthe Bering Strait. Along the southern edge of the ice, wavy tendrils of newly formed, thin sea ice predominate.\n\nThe cloud streets run in the direction of the northerly wind that helps form them. When wind blows out from a cold surface like sea \n\nice over the warmer, moister air near the open ocean, cylinders of spinning air may develop. Clouds form along the upward cycle in \n\nthe cylinders, where air is rising, and skies remain clear along the downward cycle, where air is falling. The cloud streets run toward \n\nthe southwest in this image from the Terra satellite.",
      "title": "page-21.pdf",
    },
    {
      "@search.score": 0.027637723833322525,
      "@search.rerankerScore": 2.4686081409454346,
      "chunk": "A\nT\n\nM\nO\n\nS\nP\n\nH\nE\n\nR\nE\n\nE\nA\n\nR\nT\n\nH\n\n38\n\nLofted Over Land\nMadagascar\n\nAlong the muddy Mania River, midday clouds form over the forested land but not the water. In the tropical rainforests of Madagascar, \n\nthere is ample moisture for cloud formation. Sunlight heats the land all day, warming that moist air and causing it to rise high into the \n\natmosphere until it cools and condenses into water droplets. Clouds generally form where air is ascending (over land in this case), \n\nbut not where it is descending (over the river). Landsat 8 acquired this image in January 2015.",
      "title": "page-45.pdf",
    }
  ]