-
Notifications
You must be signed in to change notification settings - Fork 164
Add LTR retriever example in the doc. #2095
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.