Skip to content

Commit 22c80a0

Browse files
authored
Merge pull request #107684 from LuisCabrer/luiscabranch
Submitting changes related to ranking algo
2 parents 3b3779f + 4d20f2d commit 22c80a0

File tree

2 files changed

+106
-1
lines changed

2 files changed

+106
-1
lines changed

articles/search/TOC.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,10 @@
261261
items:
262262
- name: Page-related features
263263
href: search-pagination-page-layout.md
264-
- name: Relevance tuning (scoring profiles)
264+
- name: Relevance tuning (scoring profiles)
265265
href: index-add-scoring-profiles.md
266+
- name: Relevance tuning (similarity algorithm)
267+
href: index-ranking-similarity.md
266268
- name: Plan
267269
items:
268270
- name: Choose a tier
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
---
2+
title: Ranking Similarity Algorithm
3+
titleSuffix: Azure Cognitive Search
4+
description: How to set the similarity algorithm to try new similarity algorithm for ranking
5+
6+
manager: nitinme
7+
author: luiscabrer
8+
ms.author: luisca
9+
ms.service: cognitive-search
10+
ms.topic: conceptual
11+
ms.date: 03/13/2020
12+
---
13+
14+
# Ranking algorithm in Azure Cognitive Search
15+
16+
> [!IMPORTANT]
17+
> Starting July 15, 2020, newly created search services will use the BM25 ranking function, which has proven in most cases to provide search rankings that align better with user expectations than the current default ranking. Beyond superior ranking, BM25 also enables configuration options for tuning results based on factors such as document size.
18+
>
19+
> With this change, you will most likely see slight changes in the ordering of your search results. For those that want to test the impact of this change, we have made available in the 2019-05-06-Preview API an ability to enable BM25 scoring on new indexes.
20+
21+
This article describes how you can update a service created before July 15, 2020 to to use the new BM25 ranking algorithm.
22+
23+
Azure Cognitive Search will be using the official Lucene implementation of the Okapi BM25 algorithm, *BM25Similarity*, which will replace the previously used *ClassicSimilarity* implementation. Like the older ClassicSimilarity algorithm, BM25Similarity is a TF-IDF-like retrieval function which uses the term frequency (TF) and the inverse document frequency (IDF) as variables to calculate relevance scores for each document-query pair, which is then used for ranking. While conceptually similar to the older Classic Similarity algorithm, BM25 takes its root in probabilistic information retrieval to improve upon it. BM25 also offers advanced customization options, such as allowing the user to decide how the relevance score scales with the term frequency of matched terms.
24+
25+
## How to test BM25 today
26+
27+
When you create a new index, you can set a "similarity" property. You will need to use the *2019-05-06-Preview* version, as shown below.
28+
29+
```
30+
PUT https://[search service name].search.windows.net/indexes/[index name]?api-version=2019-05-06-Preview
31+
```
32+
33+
```json
34+
{
35+
"name": "indexName",
36+
"fields": [
37+
{
38+
"name": "id",
39+
"type": "Edm.String",
40+
"key": true
41+
},
42+
{
43+
"name": "name",
44+
"type": "Edm.String",
45+
"searchable": true,
46+
"analyzer": "en.lucene"
47+
},
48+
...
49+
],
50+
"similarity": {
51+
"@odata.type": "#Microsoft.Azure.Search.BM25Similarity"
52+
}
53+
}
54+
```
55+
56+
For services created before July 15, 2020: If the similarity is omitted or set to null, the index will use the old classic similarity algorithm.
57+
58+
For services created after July 15, 2020: If the similarity is omitted or set to null, the index will use the new BM25 similarity algorithm.
59+
60+
You can also explicitly set the similarity value to be one of the following two values: *"#Microsoft.Azure.Search.ClassicSimilarity"* or *"#Microsoft.Azure.Search.BM25Similarity"*.
61+
62+
63+
## BM25 similarity parameters
64+
65+
BM25 similarity adds two user customizable parameters to control the calculated relevance score:
66+
67+
### k1
68+
69+
The *k1* parameter controls the scaling function between the term frequency of each matching terms to the final relevance score of a document-query pair.
70+
71+
A value of zero represents a "binary model", where the contribution of a single matching term is the same for all matching documents, regardless of how many times that term appears in the text, while a larger k1 value allows the score to continue to increase as more instances of the same term is found in the document. By default, Azure Cognitive Search uses a value of 1.2 for the k1 parameter. Using a higher k1 value can be important in cases where we expect multiple terms to be part of a search query. In those cases, we might want to favor documents that match many of the different query terms being searched over documents that only match a single one, multiple times. For example, when querying the index for documents containing the terms "Apollo Spaceflight", we might want to lower the score of an article about Greek Mythology which contains the term "Apollo" a few dozen times, without mentions of "Spaceflight", compared to another article which explicitly mentions both "Apollo" and "Spaceflight" a handful of times only.
72+
73+
### b
74+
75+
The *b* parameter controls how the length of a document affects the relevance score.
76+
77+
A value of 0.0 means the length of the document will not influence the score, while a value of 1.0 means the impact of term frequency on relevance score will be normalized by the document's length. The default value used in Azure Cognitive Search for the b parameter is 0.75. Normalizing the term frequency by the document's length is useful in cases where we want to penalize longer documents. In some cases, longer documents (such as a complete novel), are more likely to contain many irrelevant terms, compared to much shorter documents.
78+
79+
### Setting k1 and b parameters
80+
81+
To customize the b or k1 values, simply add them as properties to the similarity object when using BM25:
82+
83+
```json
84+
"similarity": {
85+
"@odata.type": "#Microsoft.Azure.Search.BM25Similarity",
86+
"b" : 0.5,
87+
"k1" : 1.3
88+
}
89+
```
90+
91+
The similarity algorithm can only be set at index creation time. This means the similarity algorithm being used cannot be changed for existing indexes. The *"b"* and *"k1"* parameters can be modified when updating an existing index definition that uses BM25. Changing those values on an existing index will take the index offline for at least a few seconds, causing your indexing and query requests to fail. Because of that, you will need to set the "allowIndexDowntime=true" parameter in the query string of your update request:
92+
93+
```http
94+
PUT https://[search service name].search.windows.net/indexes/[index name]?api-version=[api-version]&allowIndexDowntime=true
95+
```
96+
97+
98+
## See also
99+
100+
[Azure Cognitive Search REST](https://docs.microsoft.com/rest/api/searchservice/)
101+
[Add scoring profiles to your index](index-add-scoring-profiles.md)
102+
[Create Index (Azure Cognitive Search REST API)](https://docs.microsoft.com/rest/api/searchservice/create-index)
103+
[Azure Cognitive Search .NET SDK](https://docs.microsoft.com/dotnet/api/overview/azure/search?view=azure-dotnet)

0 commit comments

Comments
 (0)