Skip to content

Commit f8586c4

Browse files
afoucretleemthompo
andauthored
Add LTR retriever example in the doc. (elastic#2095)
Co-authored-by: Liam Thompson <[email protected]>
1 parent a7f79cb commit f8586c4

File tree

1 file changed

+50
-8
lines changed

1 file changed

+50
-8
lines changed

solutions/search/ranking/learning-to-rank-search-usage.md

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,15 @@ products:
1818
This feature was introduced in version 8.12.0 and is only available to certain subscription levels. For more information, see {{subscriptions}}.
1919
::::
2020

21+
Once your LTR model is trained and deployed in {{es}}, there are two ways to use it with the [search API](../querying-for-search.md) to improve your search results:
22+
23+
1. **As a [rescorer](#learning-to-rank-rescorer)**
24+
2. **As a [retriever](#learning-to-rank-retriever)**
2125

2226

2327
## Learning To Rank as a rescorer [learning-to-rank-rescorer]
2428

25-
Once your LTR model is trained and deployed in {{es}}, it can be used as a [rescorer](elasticsearch://reference/elasticsearch/rest-apis/filter-search-results.md#rescore) in the [search API](../querying-for-search.md):
29+
To use your LTR model as a [rescorer](elasticsearch://reference/elasticsearch/rest-apis/filter-search-results.md#rescore) in the [search API](../querying-for-search.md), follow this example:
2630

2731
```console
2832
GET my-index/_search
@@ -50,22 +54,60 @@ GET my-index/_search
5054
3. Named parameters to be passed to the query templates used for feature.
5155
4. The number of documents that should be examined by the rescorer on each shard.
5256

57+
## Learning To Rank as a retriever [learning-to-rank-retriever]
5358

59+
```{applies_to}
60+
stack: ga 9.1
61+
serverless: ga
62+
```
5463

55-
### Known limitations [learning-to-rank-rescorer-limitations]
64+
LTR models can also be used as a [retriever](../retrievers-overview.md) in the search pipeline. You can implement this with a [rescorer retriever](elasticsearch://reference/elasticsearch/rest-apis/retrievers.md#rescorer-retriever) as shown in the following example:
5665

66+
```console
67+
GET my-index/_search
68+
{
69+
"retriever": {
70+
"rescorer": {
71+
"rescore": {
72+
"window_size": 100, <4>
73+
"learning_to_rank": {
74+
"model_id": "ltr-model", <2>
75+
"params": { <3>
76+
"query_text": "the quick brown fox"
77+
}
78+
}
79+
},
80+
"retrievers": [ <1>
81+
{
82+
"standard": {
83+
"query": {
84+
"multi_match": {
85+
"fields": ["title", "content"],
86+
"query": "the quick brown fox"
87+
}
88+
}
89+
}
90+
}
91+
]
92+
}
93+
}
94+
}
95+
```
5796

58-
#### Rescore window size [learning-to-rank-rescorer-limitations-window-size]
97+
1. First pass retrievers used to retrieve documents to be rescored
98+
2. The unique identifier of the trained model uploaded to {{es}}.
99+
3. Named parameters to be passed to the query templates used for feature extraction.
100+
4. The number of documents that should be examined by the rescorer.
59101

60-
Scores returned by LTR models are usually not comparable with the scores issued by the first pass query and can be lower than the non-rescored score. This can cause the non-rescored result document to be ranked higher than the rescored document. To prevent this, the `window_size` parameter is mandatory for LTR rescorers and should be greater than or equal to `from + size`.
102+
## Known limitations [learning-to-rank-rescorer-limitations]
61103

62104

63-
#### Pagination [learning-to-rank-rescorer-limitations-pagination]
105+
### Rescore window size [learning-to-rank-rescorer-limitations-window-size]
64106

65-
When exposing pagination to users, `window_size` should remain constant as each page is progressed by passing different `from` values. Changing the `window_size` can alter the top hits causing results to confusingly shift as the user steps through pages.
107+
Scores returned by LTR models are usually not comparable with the scores issued by the first pass query and can be lower than the non-rescored score. This can cause the non-rescored result document to be ranked higher than the rescored document. To prevent this, the `window_size` parameter is mandatory for LTR rescorers and should be greater than or equal to `from + size`.
66108

67109

68-
#### Negative scores [learning-to-rank-rescorer-limitations-negative-scores]
110+
### Pagination [learning-to-rank-rescorer-limitations-pagination]
69111

70-
Depending on how your model is trained, it’s possible that the model will return negative scores for documents. While negative scores are not allowed from first-stage retrieval and ranking, it is possible to use them in the LTR rescorer.
112+
When exposing pagination to users, `window_size` should remain constant as each page is progressed by passing different `from` values. Changing the `window_size` can alter the top hits causing results to confusingly shift as the user steps through pages.
71113

0 commit comments

Comments
 (0)