-
Notifications
You must be signed in to change notification settings - Fork 25.6k
[DOCS] Add Elastic Rerank usage docs #117625
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
Changes from all commits
3735481
93c6891
af2a7f9
87f4485
b17535b
5be7eac
e32a350
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ This allows for complex behavior to be depicted in a tree-like structure, called | |
[TIP] | ||
==== | ||
Refer to <<retrievers-overview>> for a high level overview of the retrievers abstraction. | ||
Refer to <<retrievers-examples, Retrievers examples>> for additional examples. | ||
==== | ||
|
||
The following retrievers are available: | ||
|
@@ -382,16 +383,17 @@ Refer to <<semantic-reranking>> for a high level overview of semantic re-ranking | |
|
||
===== Prerequisites | ||
|
||
To use `text_similarity_reranker` you must first set up a `rerank` task using the <<put-inference-api, Create {infer} API>>. | ||
The `rerank` task should be set up with a machine learning model that can compute text similarity. | ||
To use `text_similarity_reranker` you must first set up an inference endpoint for the `rerank` task using the <<put-inference-api, Create {infer} API>>. | ||
The endpoint should be set up with a machine learning model that can compute text similarity. | ||
Refer to {ml-docs}/ml-nlp-model-ref.html#ml-nlp-model-ref-text-similarity[the Elastic NLP model reference] for a list of third-party text similarity models supported by {es}. | ||
|
||
Currently you can: | ||
You have the following options: | ||
|
||
* Integrate directly with the <<infer-service-cohere,Cohere Rerank inference endpoint>> using the `rerank` task type | ||
* Integrate directly with the <<infer-service-google-vertex-ai,Google Vertex AI inference endpoint>> using the `rerank` task type | ||
* Use the the built-in <<inference-example-elastic-reranker,Elastic Rerank>> cross-encoder model via the inference API's {es} service. | ||
* Use the <<infer-service-cohere,Cohere Rerank inference endpoint>> with the `rerank` task type. | ||
* Use the <<infer-service-google-vertex-ai,Google Vertex AI inference endpoint>> with the `rerank` task type. | ||
* Upload a model to {es} with {eland-docs}/machine-learning.html#ml-nlp-pytorch[Eland] using the `text_similarity` NLP task type. | ||
** Then set up an <<inference-example-eland,{es} service inference endpoint>> with the `rerank` task type | ||
** Then set up an <<inference-example-eland,{es} service inference endpoint>> with the `rerank` task type. | ||
** Refer to the <<text-similarity-reranker-retriever-example-eland,example>> on this page for a step-by-step guide. | ||
|
||
===== Parameters | ||
|
@@ -436,13 +438,70 @@ Note that score calculations vary depending on the model used. | |
Applies the specified <<query-dsl-bool-query, boolean query filter>> to the child <<retriever, retriever>>. | ||
If the child retriever already specifies any filters, then this top-level filter is applied in conjuction with the filter defined in the child retriever. | ||
|
||
[discrete] | ||
[[text-similarity-reranker-retriever-example-elastic-rerank]] | ||
==== Example: Elastic Rerank | ||
|
||
This examples demonstrates how to deploy the Elastic Rerank model and use it to re-rank search results using the `text_similarity_reranker` retriever. | ||
|
||
Follow these steps: | ||
|
||
. Create an inference endpoint for the `rerank` task using the <<put-inference-api, Create {infer} API>>. | ||
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. in this case the " |
||
+ | ||
[source,console] | ||
---- | ||
PUT _inference/rerank/my-elastic-rerank | ||
{ | ||
"service": "elasticsearch", | ||
"service_settings": { | ||
"model_id": ".rerank-v1", | ||
"num_threads": 1, | ||
"adaptive_allocations": { <1> | ||
"enabled": true, | ||
"min_number_of_allocations": 1, | ||
"max_number_of_allocations": 10 | ||
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. once again, we may want to decrease the max allocations in this example |
||
} | ||
} | ||
} | ||
---- | ||
// TEST[skip:uses ML] | ||
<1> {ml-docs}/ml-nlp-auto-scale.html#nlp-model-adaptive-allocations[Adaptive allocations] will be enabled with the minimum of 1 and the maximum of 10 allocations. | ||
+ | ||
. Define a `text_similarity_rerank` retriever: | ||
+ | ||
[source,console] | ||
leemthompo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
---- | ||
POST _search | ||
{ | ||
"retriever": { | ||
"text_similarity_reranker": { | ||
"retriever": { | ||
"standard": { | ||
"query": { | ||
"match": { | ||
"text": "How often does the moon hide the sun?" | ||
} | ||
} | ||
} | ||
}, | ||
"field": "text", | ||
"inference_id": "my-elastic-rerank", | ||
"inference_text": "How often does the moon hide the sun?", | ||
"rank_window_size": 100, | ||
"min_score": 0.5 | ||
} | ||
} | ||
} | ||
---- | ||
// TEST[skip:uses ML] | ||
|
||
[discrete] | ||
[[text-similarity-reranker-retriever-example-cohere]] | ||
==== Example: Cohere Rerank | ||
|
||
This example enables out-of-the-box semantic search by re-ranking top documents using the Cohere Rerank API. | ||
This approach eliminates the need to generate and store embeddings for all indexed documents. | ||
This requires a <<infer-service-cohere,Cohere Rerank inference endpoint>> using the `rerank` task type. | ||
This requires a <<infer-service-cohere,Cohere Rerank inference endpoint>> that is set up for the `rerank` task type. | ||
|
||
[source,console] | ||
---- | ||
|
@@ -680,6 +739,12 @@ GET movies/_search | |
<1> The `rule` retriever is the outermost retriever, applying rules to the search results that were previously reranked using the `rrf` retriever. | ||
<2> The `rrf` retriever returns results from all of its sub-retrievers, and the output of the `rrf` retriever is used as input to the `rule` retriever. | ||
|
||
[discrete] | ||
[[retriever-common-parameters]] | ||
=== Common usage guidelines | ||
|
||
[discrete] | ||
[[retriever-size-pagination]] | ||
==== Using `from` and `size` with a retriever tree | ||
|
||
The <<search-from-param, `from`>> and <<search-size-param, `size`>> | ||
|
@@ -688,12 +753,16 @@ parameters are provided globally as part of the general | |
They are applied to all retrievers in a retriever tree, unless a specific retriever overrides the `size` parameter using a different parameter such as `rank_window_size`. | ||
Though, the final search hits are always limited to `size`. | ||
|
||
[discrete] | ||
[[retriever-aggregations]] | ||
==== Using aggregations with a retriever tree | ||
|
||
<<search-aggregations, Aggregations>> are globally specified as part of a search request. | ||
The query used for an aggregation is the combination of all leaf retrievers as `should` | ||
clauses in a <<query-dsl-bool-query, boolean query>>. | ||
|
||
[discrete] | ||
[[retriever-restrictions]] | ||
==== Restrictions on search parameters when specifying a retriever | ||
|
||
When a retriever is specified as part of a search, the following elements are not allowed at the top-level. | ||
|
Uh oh!
There was an error while loading. Please reload this page.