Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 50 additions & 8 deletions solutions/search/ranking/learning-to-rank-search-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@ products:
This feature was introduced in version 8.12.0 and is only available to certain subscription levels. For more information, see {{subscriptions}}.
::::

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:

1. **As a [rescorer](#learning-to-rank-rescorer)**
2. **As a [retriever](#learning-to-rank-retriever)**


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

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):
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:

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

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

```{applies_to}
stack: ga 9.1
serverless: ga
```

### Known limitations [learning-to-rank-rescorer-limitations]
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:

```console
GET my-index/_search
{
"retriever": {
"rescorer": {
"rescore": {
"window_size": 100, <4>
"learning_to_rank": {
"model_id": "ltr-model", <2>
"params": { <3>
"query_text": "the quick brown fox"
}
}
},
"retrievers": [ <1>
{
"standard": {
"query": {
"multi_match": {
"fields": ["title", "content"],
"query": "the quick brown fox"
}
}
}
}
]
}
}
}
```

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

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`.
## Known limitations [learning-to-rank-rescorer-limitations]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this just wording changes, or have the limitations changed from 9.0 to 9.1?

  • If it's just wording then that's fine
  • But if the limitations have changed, users need to be able to see both versions, so could use a tabbed widget to distinguish them, or inline applies_to annotations if there are minor differences.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just rewording



#### Pagination [learning-to-rank-rescorer-limitations-pagination]
### Rescore window size [learning-to-rank-rescorer-limitations-window-size]

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.
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`.


#### Negative scores [learning-to-rank-rescorer-limitations-negative-scores]
### Pagination [learning-to-rank-rescorer-limitations-pagination]

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.
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.

Loading