你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
在查询作中,任何给定结果的相关性由排名算法确定,该算法根据查询与索引文档的接近程度来评估匹配的强度。 找到匹配项时,算法会分配一个分数,结果按该分数进行排名,并在响应中返回最上面的结果。
每当查询请求包含全文或矢量查询时,就会进行排名。 如果查询调用严格的模式匹配,例如仅筛选查询或专用查询表单(如自动完成、建议、地理空间搜索、模糊搜索或正则表达式搜索),则不会发生这种情况。 统一搜索分数为 1.0 表示缺少排名算法。
排名级别
Azure AI 搜索中的查询引擎支持多级方法来对搜索结果进行排名,其中每个查询类型都有内置的排名形式,以及用于扩展相关性优化的额外排名功能。
本部分介绍评分操作的等级。 有关它们如何协同工作的说明,请参阅本文中的 关系图 。 本文还提供了 所有搜索分数类型和范围的比较 。
| Level | 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 结果集。
搜索分数的类型
为查询响应中的每个匹配项指示评分结果。 下表列出了具有关联范围的所有搜索分数。 范围因算法而异。
| Score | Range | Algorithm |
|---|---|---|
@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) |
排名算法示意图
下图说明了排名算法如何协同工作。
Note
此工作流关系图当前省略了 @search.rerankerBoostedScore 和包含计分概要文件提升功能的语义排序步骤。 如果将语义排序与计分概要文件一起使用,则计分概要文件在 L2 排名后应用,最终分数基于 @search.rerankerBoostedScore。
包含所有排名算法的示例查询
生成上一个工作流的查询可能如以下示例所示。 此混合语义查询使用 RRF(基于文本和矢量的 L1 分数)和语义排名进行评分。
POST https://{{search-service-name}}.search.windows.net/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",
}
]