Browse Source

Split retrievers docs and redirect anchors (#131385) (#131475)

Liam Thompson 2 months ago
parent
commit
06d4baa4e5

+ 24 - 2
docs/redirects.yml

@@ -1,3 +1,25 @@
 redirects:
-# Related to https://github.com/elastic/elasticsearch/pull/130716/
-  'reference/query-languages/eql/eql-ex-threat-detection.md': 'docs-content://explore-analyze/query-filter/languages/example-detect-threats-with-eql.md'
+  # Related to https://github.com/elastic/elasticsearch/pull/130716/
+  'reference/query-languages/eql/eql-ex-threat-detection.md': 'docs-content://explore-analyze/query-filter/languages/example-detect-threats-with-eql.md'
+  
+  # https://github.com/elastic/elasticsearch/pull/131385
+  'reference/elasticsearch/rest-apis/retrievers.md':
+    to: 'reference/elasticsearch/rest-apis/retrievers.md'
+    anchors: {} # pass-through unlisted anchors in the `many` ruleset
+    many:
+      - to: 'reference/elasticsearch/rest-apis/retrievers/standard-retriever.md'
+        anchors: {'standard-retriever'}
+      - to: 'reference/elasticsearch/rest-apis/retrievers/knn-retriever.md'
+        anchors: {'knn-retriever'}
+      - to: 'reference/elasticsearch/rest-apis/retrievers/linear-retriever.md'
+        anchors: {'linear-retriever'}
+      - to: 'reference/elasticsearch/rest-apis/retrievers/rrf-retriever.md'
+        anchors: {'rrf-retriever'}
+      - to: 'reference/elasticsearch/rest-apis/retrievers/rescorer-retriever.md'
+        anchors: {'rescorer-retriever'}
+      - to: 'reference/elasticsearch/rest-apis/retrievers/text-similarity-reranker-retriever.md'
+        anchors: {'text-similarity-reranker-retriever'}
+      - to: 'reference/elasticsearch/rest-apis/retrievers/rule-retriever.md'
+        anchors: {'rule-retriever'}
+      - to: 'reference/elasticsearch/rest-apis/retrievers/pinned-retriever.md'
+        anchors: {'pinned-retriever'}

+ 1 - 1
docs/reference/elasticsearch/rest-apis/reciprocal-rank-fusion.md

@@ -34,7 +34,7 @@ For the most up-to-date API details, refer to [Search APIs](https://www.elastic.
 ::::
 
 
-You can use RRF as part of a [search](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-search) to combine and rank documents using separate sets of top documents (result sets) from a combination of [child retrievers](/reference/elasticsearch/rest-apis/retrievers.md) using an [RRF retriever](/reference/elasticsearch/rest-apis/retrievers.md#rrf-retriever). A minimum of **two** child retrievers is required for ranking.
+You can use RRF as part of a [search](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-search) to combine and rank documents using separate sets of top documents (result sets) from a combination of [child retrievers](/reference/elasticsearch/rest-apis/retrievers.md) using an [RRF retriever](/reference/elasticsearch/rest-apis/retrievers/rrf-retriever.md). A minimum of **two** child retrievers is required for ranking.
 
 An RRF retriever is an optional object defined as part of a search request’s [retriever parameter](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-search#request-body-retriever). The RRF retriever object contains the following parameters:
 

File diff suppressed because it is too large
+ 27 - 989
docs/reference/elasticsearch/rest-apis/retrievers.md


+ 109 - 0
docs/reference/elasticsearch/rest-apis/retrievers/knn-retriever.md

@@ -0,0 +1,109 @@
+---
+applies_to:
+ stack: all
+ serverless: ga
+---
+
+# kNN retriever [knn-retriever]
+
+A kNN retriever returns top documents from a [k-nearest neighbor search (kNN)](docs-content://solutions/search/vector/knn.md).
+
+
+## Parameters [knn-retriever-parameters]
+
+`field`
+:   (Required, string)
+
+    The name of the vector field to search against. Must be a [`dense_vector` field with indexing enabled](/reference/elasticsearch/mapping-reference/dense-vector.md#index-vectors-knn-search).
+
+
+`query_vector`
+:   (Required if `query_vector_builder` is not defined, array of `float`)
+
+    Query vector. Must have the same number of dimensions as the vector field you are searching against. Must be either an array of floats or a hex-encoded byte vector.
+
+
+`query_vector_builder`
+:   (Required if `query_vector` is not defined, query vector builder object)
+
+    Defines a [model](docs-content://solutions/search/vector/knn.md#knn-semantic-search) to build a query vector.
+
+
+`k`
+:   (Required, integer)
+
+    Number of nearest neighbors to return as top hits. This value must be fewer than or equal to `num_candidates`.
+
+
+`num_candidates`
+:   (Required, integer)
+
+    The number of nearest neighbor candidates to consider per shard. Needs to be greater than `k`, or `size` if `k` is omitted, and cannot exceed 10,000. {{es}} collects `num_candidates` results from each shard, then merges them to find the top `k` results. Increasing `num_candidates` tends to improve the accuracy of the final `k` results. Defaults to `Math.min(1.5 * k, 10_000)`.
+
+
+`filter`
+:   (Optional, [query object or list of query objects](/reference/query-languages/querydsl.md))
+
+    Query to filter the documents that can match. The kNN search will return the top `k` documents that also match this filter. The value can be a single query or a list of queries. If `filter` is not provided, all documents are allowed to match.
+
+
+`similarity`
+:   (Optional, float)
+
+    The minimum similarity required for a document to be considered a match. The similarity value calculated relates to the raw [`similarity`](/reference/elasticsearch/mapping-reference/dense-vector.md#dense-vector-similarity) used. Not the document score. The matched documents are then scored according to [`similarity`](/reference/elasticsearch/mapping-reference/dense-vector.md#dense-vector-similarity) and the provided `boost` is applied.
+
+    The `similarity` parameter is the direct vector similarity calculation.
+
+    * `l2_norm`: also known as Euclidean, will include documents where the vector is within the `dims` dimensional hypersphere with radius `similarity` with origin at `query_vector`.
+    * `cosine`, `dot_product`, and `max_inner_product`: Only return vectors where the cosine similarity or dot-product are at least the provided `similarity`.
+
+    Read more here: [knn similarity search](docs-content://solutions/search/vector/knn.md#knn-similarity-search)
+
+
+`rescore_vector`
+:   (Optional, object) Apply oversampling and rescoring to quantized vectors.
+
+::::{note}
+Rescoring only makes sense for quantized vectors; when [quantization](/reference/elasticsearch/mapping-reference/dense-vector.md#dense-vector-quantization) is not used, the original vectors are used for scoring. Rescore option will be ignored for non-quantized `dense_vector` fields.
+::::
+
+
+`oversample`
+:   (Required, float)
+
+    Applies the specified oversample factor to `k` on the approximate kNN search. The approximate kNN search will:
+
+    * Retrieve `num_candidates` candidates per shard.
+    * From these candidates, the top `k * oversample` candidates per shard will be rescored using the original vectors.
+    * The top `k` rescored candidates will be returned.
+
+
+See [oversampling and rescoring quantized vectors](docs-content://solutions/search/vector/knn.md#dense-vector-knn-search-rescoring) for details.
+
+
+## Restrictions [_restrictions_2]
+
+The parameters `query_vector` and `query_vector_builder` cannot be used together.
+
+
+## Example [knn-retriever-example]
+
+```console
+GET /restaurants/_search
+{
+  "retriever": {
+    "knn": { <1>
+      "field": "vector", <2>
+      "query_vector": [10, 22, 77], <3>
+      "k": 10, <4>
+      "num_candidates": 10 <5>
+    }
+  }
+}
+```
+
+1. Configuration for k-nearest neighbor (knn) search, which is based on vector similarity.
+2. Specifies the field name that contains the vectors.
+3. The query vector against which document vectors are compared in the `knn` search.
+4. The number of nearest neighbors to return as top hits. This value must be fewer than or equal to `num_candidates`.
+5. The size of the initial candidate set from which the final `k` nearest neighbors are selected.

+ 93 - 0
docs/reference/elasticsearch/rest-apis/retrievers/linear-retriever.md

@@ -0,0 +1,93 @@
+---
+applies_to:
+ stack: all
+ serverless: ga
+---
+
+# Linear retriever [linear-retriever]
+
+A retriever that normalizes and linearly combines the scores of other retrievers.
+
+
+## Parameters [linear-retriever-parameters]
+
+::::{note}
+Either `query` or `retrievers` must be specified.
+Combining `query` and `retrievers` is not supported.
+::::
+
+`query` {applies_to}`stack: ga 9.1`
+:   (Optional, String)
+
+    The query to use when using the [multi-field query format](../retrievers.md#multi-field-query-format).
+
+`fields` {applies_to}`stack: ga 9.1`
+:   (Optional, array of strings)
+
+    The fields to query when using the [multi-field query format](../retrievers.md#multi-field-query-format).
+    Fields can include boost values using the `^` notation (e.g., `"field^2"`).
+    If not specified, uses the index's default fields from the `index.query.default_field` index setting, which is `*` by default.
+
+`normalizer` {applies_to}`stack: ga 9.1`
+:   (Optional, String)
+
+    The normalizer to use when using the [multi-field query format](../retrievers.md#multi-field-query-format).
+    See [normalizers](#linear-retriever-normalizers) for supported values.
+    Required when `query` is specified.
+
+    ::::{warning}
+    Avoid using `none` as that will disable normalization and may bias the result set towards lexical matches.
+    See [field grouping](../retrievers.md#multi-field-field-grouping) for more information.
+    ::::
+
+`retrievers`
+:   (Optional, array of objects)
+
+    A list of the sub-retrievers' configuration, that we will take into account and whose result sets we will merge through a weighted sum.
+    Each configuration can have a different weight and normalization depending on the specified retriever.
+
+`rank_window_size`
+:   (Optional, integer)
+
+    This value determines the size of the individual result sets per query. A higher value will improve result relevance at the cost of performance.
+    The final ranked result set is pruned down to the search request’s [size](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-search#search-size-param).
+    `rank_window_size` must be greater than or equal to `size` and greater than or equal to `1`.
+    Defaults to 10.
+
+`filter`
+:   (Optional, [query object or list of query objects](/reference/query-languages/querydsl.md))
+
+    Applies the specified [boolean query filter](/reference/query-languages/query-dsl/query-dsl-bool-query.md) to all of the specified sub-retrievers, according to each retriever’s specifications.
+
+Each entry in the `retrievers` array specifies the following parameters:
+
+`retriever`
+:   (Required, a `retriever` object)
+
+    Specifies the retriever for which we will compute the top documents for. The retriever will produce `rank_window_size` results, which will later be merged based on the specified `weight` and `normalizer`.
+
+`weight`
+:   (Optional, float)
+
+    The weight that each score of this retriever’s top docs will be multiplied with. Must be greater or equal to 0. Defaults to 1.0.
+
+`normalizer`
+:   (Optional, String)
+
+    Specifies how the retriever’s score will be normalized before applying the specified `weight`.
+    See [normalizers](#linear-retriever-normalizers) for supported values.
+    Defaults to `none`.
+
+See also [this hybrid search example](docs-content://solutions/search/retrievers-examples.md#retrievers-examples-linear-retriever) using a linear retriever on how to independently configure and apply normalizers to retrievers.
+
+## Normalizers [linear-retriever-normalizers]
+
+The `linear` retriever supports the following normalizers:
+
+* `none`: No normalization
+* `minmax`: Normalizes scores based on the following formula:
+
+    ```
+    score = (score - min) / (max - min)
+    ```
+* `l2_norm`: Normalizes scores using the L2 norm of the score values

+ 55 - 0
docs/reference/elasticsearch/rest-apis/retrievers/pinned-retriever.md

@@ -0,0 +1,55 @@
+---
+applies_to:
+ stack: ga 9.1
+ serverless: ga
+---
+
+# Pinned retriever [pinned-retriever]
+
+A `pinned` retriever returns top documents by always placing specific documents at the top of the results, with the remaining hits provided by a secondary retriever.
+
+This retriever offers similar functionality to the [pinned query](/reference/query-languages/query-dsl/query-dsl-pinned-query.md), but works seamlessly with other retrievers. This is useful for promoting certain documents for particular queries, regardless of their relevance score.
+
+## Parameters [pinned-retriever-parameters]
+
+`ids`
+:   (Optional, array of strings)
+
+    A list of document IDs to pin at the top of the results, in the order provided.
+
+`docs`
+:   (Optional, array of objects)
+
+    A list of objects specifying documents to pin. Each object must contain at least an `_id` field, and may also specify `_index` if pinning documents across multiple indices.
+
+`retriever`
+:   (Optional, retriever object)
+
+    A retriever (for example a `standard` retriever or a specialized retriever such as `rrf` retriever) used to retrieve the remaining documents after the pinned ones.
+
+Either `ids` or `docs` must be specified.
+
+## Example using `docs` [pinned-retriever-example-documents]
+
+```console
+GET /restaurants/_search
+{
+  "retriever": {
+    "pinned": {
+      "docs": [
+        { "_id": "doc1", "_index": "my-index" },
+        { "_id": "doc2" }
+      ],
+      "retriever": {
+        "standard": {
+          "query": {
+            "match": {
+              "title": "elasticsearch"
+            }
+          }
+        }
+      }
+    }
+  }
+}
+```

+ 123 - 0
docs/reference/elasticsearch/rest-apis/retrievers/rescorer-retriever.md

@@ -0,0 +1,123 @@
+---
+applies_to:
+ stack: all
+ serverless: ga
+---
+
+# Rescorer retriever [rescorer-retriever]
+
+The `rescorer` retriever re-scores only the results produced by its child retriever. For the `standard` and `knn` retrievers, the `window_size` parameter specifies the number of documents examined per shard.
+
+For compound retrievers like `rrf`, the `window_size` parameter defines the total number of documents examined globally.
+
+When using the `rescorer`, an error is returned if the following conditions are not met:
+
+* The minimum configured rescore’s `window_size` is:
+
+    * Greater than or equal to the `size` of the parent retriever for nested `rescorer` setups.
+    * Greater than or equal to the `size` of the search request when used as the primary retriever in the tree.
+
+* And the maximum rescore’s `window_size` is:
+
+    * Smaller than or equal to the `size` or `rank_window_size` of the child retriever.
+
+## Parameters [rescorer-retriever-parameters]
+
+`rescore`
+:   (Required. [A rescorer definition or an array of rescorer definitions](/reference/elasticsearch/rest-apis/filter-search-results.md#rescore))
+
+    Defines the [rescorers](/reference/elasticsearch/rest-apis/filter-search-results.md#rescore) applied sequentially to the top documents returned by the child retriever.
+
+
+`retriever`
+:   (Required. `retriever`)
+
+    Specifies the child retriever responsible for generating the initial set of top documents to be re-ranked.
+
+
+`filter`
+:   (Optional. [query object or list of query objects](/reference/query-languages/querydsl.md))
+
+    Applies a [boolean query filter](/reference/query-languages/query-dsl/query-dsl-bool-query.md) to the retriever, ensuring that all documents match the filter criteria without affecting their scores.
+
+
+
+## Example [rescorer-retriever-example]
+
+The `rescorer` retriever can be placed at any level within the retriever tree. The following example demonstrates a `rescorer` applied to the results produced by an `rrf` retriever:
+
+```console
+GET movies/_search
+{
+  "size": 10, <1>
+  "retriever": {
+    "rescorer": { <2>
+      "rescore": {
+        "window_size": 50, <3>
+        "query": { <4>
+          "rescore_query": {
+            "script_score": {
+              "query": {
+                "match_all": {}
+              },
+              "script": {
+                "source": "cosineSimilarity(params.queryVector, 'product-vector_final_stage') + 1.0",
+                "params": {
+                  "queryVector": [-0.5, 90.0, -10, 14.8, -156.0]
+                }
+              }
+            }
+          }
+        }
+      },
+      "retriever": { <5>
+        "rrf": {
+          "rank_window_size": 100, <6>
+          "retrievers": [
+            {
+              "standard": {
+                "query": {
+                  "sparse_vector": {
+                    "field": "plot_embedding",
+                    "inference_id": "my-elser-model",
+                    "query": "films that explore psychological depths"
+                  }
+                }
+              }
+            },
+            {
+              "standard": {
+                "query": {
+                  "multi_match": {
+                    "query": "crime",
+                    "fields": [
+                      "plot",
+                      "title"
+                    ]
+                  }
+                }
+              }
+            },
+            {
+              "knn": {
+                "field": "vector",
+                "query_vector": [10, 22, 77],
+                "k": 10,
+                "num_candidates": 10
+              }
+            }
+          ]
+        }
+      }
+    }
+  }
+}
+```
+
+1. Specifies the number of top documents to return in the final response.
+2. A `rescorer` retriever applied as the final step.
+3. Defines the number of documents to rescore from the child retriever.
+4. The definition of the `query` rescorer.
+5. Specifies the child retriever definition.
+6. Defines the number of documents returned by the `rrf` retriever, which limits the available documents to
+

+ 149 - 0
docs/reference/elasticsearch/rest-apis/retrievers/rrf-retriever.md

@@ -0,0 +1,149 @@
+---
+applies_to:
+ stack: all
+ serverless: ga
+---
+
+# RRF retriever [rrf-retriever]
+
+An [RRF](/reference/elasticsearch/rest-apis/reciprocal-rank-fusion.md) retriever returns top documents based on the RRF formula, equally weighting two or more child retrievers.
+Reciprocal rank fusion (RRF) is a method for combining multiple result sets with different relevance indicators into a single result set.
+
+
+## Parameters [rrf-retriever-parameters]
+
+::::{note}
+Either `query` or `retrievers` must be specified.
+Combining `query` and `retrievers` is not supported.
+::::
+
+`query` {applies_to}`stack: ga 9.1`
+:   (Optional, String)
+
+    The query to use when using the [multi-field query format](../retrievers.md#multi-field-query-format).
+
+`fields` {applies_to}`stack: ga 9.1`
+:   (Optional, array of strings)
+
+    The fields to query when using the [multi-field query format](../retrievers.md#multi-field-query-format).
+    If not specified, uses the index's default fields from the `index.query.default_field` index setting, which is `*` by default.
+
+`retrievers`
+:   (Optional, array of retriever objects)
+
+    A list of child retrievers to specify which sets of returned top documents will have the RRF formula applied to them.
+    Each child retriever carries an equal weight as part of the RRF formula. Two or more child retrievers are required.
+
+`rank_constant`
+:   (Optional, integer)
+
+    This value determines how much influence documents in individual result sets per query have over the final ranked result set. A higher value indicates that lower ranked documents have more influence. This value must be greater than or equal to `1`. Defaults to `60`.
+
+`rank_window_size`
+:   (Optional, integer)
+
+    This value determines the size of the individual result sets per query.
+    A higher value will improve result relevance at the cost of performance.
+    The final ranked result set is pruned down to the search request’s [size](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-search#search-size-param).
+    `rank_window_size` must be greater than or equal to `size` and greater than or equal to `1`.
+    Defaults to 10.
+
+`filter`
+:   (Optional, [query object or list of query objects](/reference/query-languages/querydsl.md))
+
+    Applies the specified [boolean query filter](/reference/query-languages/query-dsl/query-dsl-bool-query.md) to all of the specified sub-retrievers, according to each retriever’s specifications.
+
+## Example: Hybrid search [rrf-retriever-example-hybrid]
+
+A simple hybrid search example (lexical search + dense vector search) combining a `standard` retriever with a `knn` retriever using RRF:
+
+```console
+GET /restaurants/_search
+{
+  "retriever": {
+    "rrf": { <1>
+      "retrievers": [ <2>
+        {
+          "standard": { <3>
+            "query": {
+              "multi_match": {
+                "query": "Austria",
+                "fields": [
+                  "city",
+                  "region"
+                ]
+              }
+            }
+          }
+        },
+        {
+          "knn": { <4>
+            "field": "vector",
+            "query_vector": [10, 22, 77],
+            "k": 10,
+            "num_candidates": 10
+          }
+        }
+      ],
+      "rank_constant": 1, <5>
+      "rank_window_size": 50  <6>
+    }
+  }
+}
+```
+
+1. Defines a retriever tree with an RRF retriever.
+2. The sub-retriever array.
+3. The first sub-retriever is a `standard` retriever.
+4. The second sub-retriever is a `knn` retriever.
+5. The rank constant for the RRF retriever.
+6. The rank window size for the RRF retriever.
+
+## Example: Hybrid search with sparse vectors [rrf-retriever-example-hybrid-sparse]
+
+A more complex hybrid search example (lexical search + ELSER sparse vector search + dense vector search) using RRF:
+
+```console
+GET movies/_search
+{
+  "retriever": {
+    "rrf": {
+      "retrievers": [
+        {
+          "standard": {
+            "query": {
+              "sparse_vector": {
+                "field": "plot_embedding",
+                "inference_id": "my-elser-model",
+                "query": "films that explore psychological depths"
+              }
+            }
+          }
+        },
+        {
+          "standard": {
+            "query": {
+              "multi_match": {
+                "query": "crime",
+                "fields": [
+                  "plot",
+                  "title"
+                ]
+              }
+            }
+          }
+        },
+        {
+          "knn": {
+            "field": "vector",
+            "query_vector": [10, 22, 77],
+            "k": 10,
+            "num_candidates": 10
+          }
+        }
+      ]
+    }
+  }
+}
+```
+

+ 121 - 0
docs/reference/elasticsearch/rest-apis/retrievers/rule-retriever.md

@@ -0,0 +1,121 @@
+---
+applies_to:
+ stack: all
+ serverless: ga
+---
+
+# Query rules retriever [rule-retriever]
+
+The `rule` retriever enables fine-grained control over search results by applying contextual [query rules](/reference/elasticsearch/rest-apis/searching-with-query-rules.md#query-rules) to pin or exclude documents for specific queries. This retriever has similar functionality to the [rule query](/reference/query-languages/query-dsl/query-dsl-rule-query.md), but works out of the box with other retrievers.
+
+## Prerequisites [_prerequisites_16]
+
+To use the `rule` retriever you must first create one or more query rulesets using the [query rules management APIs](https://www.elastic.co/docs/api/doc/elasticsearch/group/endpoint-query_rules).
+
+## Parameters [rule-retriever-parameters]
+
+`retriever`
+:   (Required, `retriever`)
+
+    The child retriever that returns the results to apply query rules on top of. This can be a standalone retriever such as the [standard](standard-retriever.md) or [knn](knn-retriever.md) retriever, or it can be a compound retriever.
+
+
+`ruleset_ids`
+:   (Required, `array`)
+
+    An array of one or more unique [query ruleset](https://www.elastic.co/docs/api/doc/elasticsearch/group/endpoint-query_rules) IDs with query-based rules to match and apply as applicable. Rulesets and their associated rules are evaluated in the order in which they are specified in the query and ruleset. The maximum number of rulesets to specify is 10.
+
+
+`match_criteria`
+:   (Required, `object`)
+
+    Defines the match criteria to apply to rules in the given query ruleset(s). Match criteria should match the keys defined in the `criteria.metadata` field of the rule.
+
+
+`rank_window_size`
+:   (Optional, `int`)
+
+    The number of top documents to return from the `rule` retriever. Defaults to `10`.
+
+## Example: Rule retriever [rule-retriever-example]
+
+This example shows the rule retriever executed without any additional retrievers. It runs the query defined by the `retriever` and applies the rules from `my-ruleset` on top of the returned results.
+
+```console
+GET movies/_search
+{
+  "retriever": {
+    "rule": {
+      "match_criteria": {
+        "query_string": "harry potter"
+      },
+      "ruleset_ids": [
+        "my-ruleset"
+      ],
+      "retriever": {
+        "standard": {
+          "query": {
+            "query_string": {
+              "query": "harry potter"
+            }
+          }
+        }
+      }
+    }
+  }
+}
+```
+
+## Example: Rule retriever combined with RRF [rule-retriever-example-rrf]
+
+This example shows how to combine the `rule` retriever with other rerank retrievers such as [rrf](rrf-retriever.md) or [text_similarity_reranker](text-similarity-reranker-retriever.md).
+
+::::{warning}
+The `rule` retriever will apply rules to any documents returned from its defined `retriever` or any of its sub-retrievers. This means that for the best results, the `rule` retriever should be the outermost defined retriever. Nesting a `rule` retriever as a sub-retriever under a reranker such as `rrf` or `text_similarity_reranker` may not produce the expected results.
+
+::::
+
+
+```console
+GET movies/_search
+{
+  "retriever": {
+    "rule": { <1>
+      "match_criteria": {
+        "query_string": "harry potter"
+      },
+      "ruleset_ids": [
+        "my-ruleset"
+      ],
+      "retriever": {
+        "rrf": { <2>
+          "retrievers": [
+            {
+              "standard": {
+                "query": {
+                  "query_string": {
+                    "query": "sorcerer's stone"
+                  }
+                }
+              }
+            },
+            {
+              "standard": {
+                "query": {
+                  "query_string": {
+                    "query": "chamber of secrets"
+                  }
+                }
+              }
+            }
+          ]
+        }
+      }
+    }
+  }
+}
+```
+
+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.
+

+ 98 - 0
docs/reference/elasticsearch/rest-apis/retrievers/standard-retriever.md

@@ -0,0 +1,98 @@
+---
+applies_to:
+ stack: all
+ serverless: ga
+---
+# Standard retriever [standard-retriever]
+
+A standard retriever returns top documents from a traditional [query](/reference/query-languages/querydsl.md).
+
+
+### Parameters: [standard-retriever-parameters]
+
+`query`
+:   (Optional, [query object](/reference/query-languages/querydsl.md))
+
+    Defines a query to retrieve a set of top documents.
+
+
+`filter`
+:   (Optional, [query object or list of query objects](/reference/query-languages/querydsl.md))
+
+    Applies a [boolean query filter](/reference/query-languages/query-dsl/query-dsl-bool-query.md) to this retriever, where all documents must match this query but do not contribute to the score.
+
+
+`search_after`
+:   (Optional, [search after object](/reference/elasticsearch/rest-apis/paginate-search-results.md#search-after))
+
+    Defines a search after object parameter used for pagination.
+
+
+`terminate_after`
+:   (Optional, integer) Maximum number of documents to collect for each shard. If a query reaches this limit, {{es}} terminates the query early. {{es}} collects documents before sorting.
+
+    ::::{important}
+    Use with caution. {{es}} applies this parameter to each shard handling the request. When possible, let {{es}} perform early termination automatically. Avoid specifying this parameter for requests that target data streams with backing indices across multiple data tiers.
+    ::::
+
+
+`sort`
+:   (Optional, [sort object](/reference/elasticsearch/rest-apis/sort-search-results.md)) A sort object that specifies the order of matching documents.
+
+
+`min_score`
+:   (Optional, `float`)
+
+    Minimum [`_score`](/reference/query-languages/query-dsl/query-filter-context.md#relevance-scores) for matching documents. Documents with a lower `_score` are not included in the top documents.
+
+
+`collapse`
+:   (Optional, [collapse object](/reference/elasticsearch/rest-apis/collapse-search-results.md))
+
+    Collapses the top documents by a specified key into a single top document per key.
+
+
+## Restrictions [_restrictions]
+
+When a retriever tree contains a compound retriever (a retriever with two or more child retrievers) the [search after](/reference/elasticsearch/rest-apis/paginate-search-results.md#search-after) parameter is not supported.
+
+
+## Example [standard-retriever-example]
+
+```console
+GET /restaurants/_search
+{
+  "retriever": { <1>
+    "standard": { <2>
+      "query": { <3>
+        "bool": { <4>
+          "should": [ <5>
+            {
+              "match": { <6>
+                "region": "Austria"
+              }
+            }
+          ],
+          "filter": [ <7>
+            {
+              "term": { <8>
+                "year": "2019" <9>
+              }
+            }
+          ]
+        }
+      }
+    }
+  }
+}
+```
+
+1. Opens the `retriever` object.
+2. The `standard` retriever is used for defining traditional {{es}} queries.
+3. The entry point for defining the search query.
+4. The `bool` object allows for combining multiple query clauses logically.
+5. The `should` array indicates conditions under which a document will match. Documents matching these conditions will have increased relevancy scores.
+6. The `match` object finds documents where the `region` field contains the word "Austria."
+7. The `filter` array provides filtering conditions that must be met but do not contribute to the relevancy score.
+8. The `term` object is used for exact matches, in this case, filtering documents by the `year` field.
+9. The exact value to match in the `year` field.

+ 248 - 0
docs/reference/elasticsearch/rest-apis/retrievers/text-similarity-reranker-retriever.md

@@ -0,0 +1,248 @@
+---
+applies_to:
+ stack: all
+ serverless: ga
+---
+
+# Text similarity re-ranker retriever [text-similarity-reranker-retriever]
+
+The `text_similarity_reranker` retriever uses an NLP model to improve search results by reordering the top-k documents based on their semantic similarity to the query.
+
+::::{tip}
+Refer to [*Semantic re-ranking*](docs-content://solutions/search/ranking/semantic-reranking.md) for a high level overview of semantic re-ranking.
+::::
+
+## Prerequisites [_prerequisites_15]
+
+To use `text_similarity_reranker`, you can rely on the preconfigured `.rerank-v1-elasticsearch` inference endpoint, which uses the [Elastic Rerank model](docs-content://explore-analyze/machine-learning/nlp/ml-nlp-rerank.md) and serves as the default if no `inference_id` is provided. This model is optimized for reranking based on text similarity. If you'd like to use a different model, you can set up a custom inference endpoint for the `rerank` task using the [Create {{infer}} API](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-inference-put). The endpoint should be configured with a machine learning model capable of computing text similarity. Refer to [the Elastic NLP model reference](docs-content://explore-analyze/machine-learning/nlp/ml-nlp-model-ref.md#ml-nlp-model-ref-text-similarity) for a list of third-party text similarity models supported by {{es}}.
+
+You have the following options:
+
+* Use the built-in [Elastic Rerank](docs-content://explore-analyze/machine-learning/nlp/ml-nlp-rerank.md) cross-encoder model via the inference API’s {{es}} service. See [this example](https://www.elastic.co/guide/en/elasticsearch/reference/current/infer-service-elasticsearch.html#inference-example-elastic-reranker) for creating an endpoint using the Elastic Rerank model.
+* Use the [Cohere Rerank inference endpoint](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-inference-put) with the `rerank` task type.
+* Use the [Google Vertex AI inference endpoint](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-inference-put) with the `rerank` task type.
+* Upload a model to {{es}} with [Eland](eland://reference/machine-learning.md#ml-nlp-pytorch) using the `text_similarity` NLP task type.
+
+    * Then set up an [{{es}} service inference endpoint](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-inference-put) with the `rerank` task type.
+    * Refer to the [example](#text-similarity-reranker-retriever-example-eland) on this page for a step-by-step guide.
+
+
+::::{important}
+Scores from the re-ranking process are normalized using the following formula before returned to the user, to avoid having negative scores.
+
+```text
+score = max(score, 0) + min(exp(score), 1)
+```
+
+Using the above, any initially negative scores are projected to (0, 1) and positive scores to [1, infinity). To revert back if needed, one can use:
+
+```text
+score = score - 1, if score >= 0
+score = ln(score), if score < 0
+```
+
+::::
+
+## Parameters [text-similarity-reranker-retriever-parameters]
+
+`retriever`
+:   (Required, `retriever`)
+
+    The child retriever that generates the initial set of top documents to be re-ranked.
+
+
+`field`
+:   (Required, `string`)
+
+    The document field to be used for text similarity comparisons. This field should contain the text that will be evaluated against the `inferenceText`.
+
+
+`inference_id`
+:   (Optional, `string`)
+
+    Unique identifier of the inference endpoint created using the {{infer}} API. If you don’t specify an inference endpoint, the `inference_id` field defaults to `.rerank-v1-elasticsearch`, a preconfigured endpoint for the elasticsearch `.rerank-v1` model.
+
+
+`inference_text`
+:   (Required, `string`)
+
+    The text snippet used as the basis for similarity comparison.
+
+
+`rank_window_size`
+:   (Optional, `int`)
+
+    The number of top documents to consider in the re-ranking process. Defaults to `10`.
+
+
+`min_score`
+:   (Optional, `float`)
+
+    Sets a minimum threshold score for including documents in the re-ranked results. Documents with similarity scores below this threshold will be excluded. Note that score calculations vary depending on the model used.
+
+
+`filter`
+:   (Optional, [query object or list of query objects](/reference/query-languages/querydsl.md))
+
+    Applies the specified [boolean query filter](/reference/query-languages/query-dsl/query-dsl-bool-query.md) to the child  `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.
+
+
+
+## Example: Elastic Rerank [text-similarity-reranker-retriever-example-elastic-rerank]
+
+::::{tip}
+Refer to this [Python notebook](https://github.com/elastic/elasticsearch-labs/blob/main/notebooks/search/12-semantic-reranking-elastic-rerank.ipynb) for an end-to-end example using Elastic Rerank.
+
+::::
+
+
+This example demonstrates how to deploy the [Elastic Rerank](docs-content://explore-analyze/machine-learning/nlp/ml-nlp-rerank.md) model and use it to re-rank search results using the `text_similarity_reranker` retriever.
+
+Follow these steps:
+
+1. Create an inference endpoint for the `rerank` task using the [Create {{infer}} API](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-inference-put).
+
+    ```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
+        }
+      }
+    }
+    ```
+
+    1. [Adaptive allocations](docs-content://deploy-manage/autoscaling/trained-model-autoscaling.md#enabling-autoscaling-through-apis-adaptive-allocations) will be enabled with the minimum of 1 and the maximum of 10 allocations.
+
+2. Define a `text_similarity_rerank` retriever:
+
+    ```console
+    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
+        }
+      }
+    }
+    ```
+
+
+
+## Example: Cohere Rerank [text-similarity-reranker-retriever-example-cohere]
+
+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 [Cohere Rerank inference endpoint](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-inference-put) that is set up for the `rerank` task type.
+
+```console
+GET /index/_search
+{
+   "retriever": {
+      "text_similarity_reranker": {
+         "retriever": {
+            "standard": {
+               "query": {
+                  "match_phrase": {
+                     "text": "landmark in Paris"
+                  }
+               }
+            }
+         },
+         "field": "text",
+         "inference_id": "my-cohere-rerank-model",
+         "inference_text": "Most famous landmark in Paris",
+         "rank_window_size": 100,
+         "min_score": 0.5
+      }
+   }
+}
+```
+
+
+## Example: Semantic re-ranking with a Hugging Face model [text-similarity-reranker-retriever-example-eland]
+
+The following example uses the `cross-encoder/ms-marco-MiniLM-L-6-v2` model from Hugging Face to rerank search results based on semantic similarity. The model must be uploaded to {{es}} using [Eland](eland://reference/machine-learning.md#ml-nlp-pytorch).
+
+::::{tip}
+Refer to [the Elastic NLP model reference](docs-content://explore-analyze/machine-learning/nlp/ml-nlp-model-ref.md#ml-nlp-model-ref-text-similarity) for a list of third party text similarity models supported by {{es}}.
+
+::::
+
+
+Follow these steps to load the model and create a semantic re-ranker.
+
+1. Install Eland using `pip`
+
+    ```sh
+    python -m pip install eland[pytorch]
+    ```
+
+2. Upload the model to {{es}} using Eland. This example assumes you have an Elastic Cloud deployment and an API key. Refer to the [Eland documentation](eland://reference/machine-learning.md#ml-nlp-pytorch-auth) for more authentication options.
+
+    ```sh
+    eland_import_hub_model \
+      --cloud-id $CLOUD_ID \
+      --es-api-key $ES_API_KEY \
+      --hub-model-id cross-encoder/ms-marco-MiniLM-L-6-v2 \
+      --task-type text_similarity \
+      --clear-previous \
+      --start
+    ```
+
+3. Create an inference endpoint for the `rerank` task
+
+    ```console
+    PUT _inference/rerank/my-msmarco-minilm-model
+    {
+      "service": "elasticsearch",
+      "service_settings": {
+        "num_allocations": 1,
+        "num_threads": 1,
+        "model_id": "cross-encoder__ms-marco-minilm-l-6-v2"
+      }
+    }
+    ```
+
+4. Define a `text_similarity_rerank` retriever.
+
+    ```console
+    POST movies/_search
+    {
+      "retriever": {
+        "text_similarity_reranker": {
+          "retriever": {
+            "standard": {
+              "query": {
+                "match": {
+                  "genre": "drama"
+                }
+              }
+            }
+          },
+          "field": "plot",
+          "inference_id": "my-msmarco-minilm-model",
+          "inference_text": "films that explore psychological depths"
+        }
+      }
+    }
+    ```
+
+    This retriever uses a standard `match` query to search the `movie` index for films tagged with the genre "drama". It then re-ranks the results based on semantic similarity to the text in the `inference_text` parameter, using the model we uploaded to {{es}}.

+ 4 - 4
docs/reference/elasticsearch/rest-apis/searching-with-query-rules.md

@@ -18,13 +18,13 @@ $$$query-rules$$$
 * A referring site
 * etc.
 
-Query rules define a metadata key that will be used to match the metadata provided in the [rule retriever](/reference/elasticsearch/rest-apis/retrievers.md#rule-retriever) with the criteria specified in the rule.
+Query rules define a metadata key that will be used to match the metadata provided in the [rule retriever](/reference/elasticsearch/rest-apis/retrievers/rule-retriever.md) with the criteria specified in the rule.
 
 When a query rule matches the rule metadata according to its defined criteria, the query rule action is applied to the underlying `organic` query.
 
 For example, a query rule could be defined to match a user-entered query string of `pugs` and a country `us` and promote adoptable shelter dogs if the rule query met both criteria.
 
-Rules are defined using the [query rules API](https://www.elastic.co/docs/api/doc/elasticsearch/group/endpoint-query_rules) and searched using the [rule retriever](/reference/elasticsearch/rest-apis/retrievers.md#rule-retriever) or the [rule query](/reference/query-languages/query-dsl/query-dsl-rule-query.md).
+Rules are defined using the [query rules API](https://www.elastic.co/docs/api/doc/elasticsearch/group/endpoint-query_rules) and searched using the [rule retriever](/reference/elasticsearch/rest-apis/retrievers/rule-retriever.md) or the [rule query](/reference/query-languages/query-dsl/query-dsl-rule-query.md).
 
 
 ## Rule definition [query-rule-definition]
@@ -148,7 +148,7 @@ You can use the [Get query ruleset](https://www.elastic.co/docs/api/doc/elastics
 
 ## Search using query rules [rule-query-search]
 
-Once you have defined one or more query rulesets, you can search using these rulesets using the [rule retriever](/reference/elasticsearch/rest-apis/retrievers.md#rule-retriever) or the [rule query](/reference/query-languages/query-dsl/query-dsl-rule-query.md). Retrievers are the recommended way to use rule queries, as they will work out of the box with other reranking retrievers such as [Reciprocal rank fusion](/reference/elasticsearch/rest-apis/reciprocal-rank-fusion.md).
+Once you have defined one or more query rulesets, you can search using these rulesets using the [rule retriever](/reference/elasticsearch/rest-apis/retrievers/rule-retriever.md) or the [rule query](/reference/query-languages/query-dsl/query-dsl-rule-query.md). Retrievers are the recommended way to use rule queries, as they will work out of the box with other reranking retrievers such as [Reciprocal rank fusion](/reference/elasticsearch/rest-apis/reciprocal-rank-fusion.md).
 
 Rulesets are evaluated in order, so rules in the first ruleset you specify will be applied before any subsequent rulesets.
 
@@ -186,7 +186,7 @@ It’s possible to have multiple rules in a ruleset match a single [rule query](
 * If multiple documents are specified in a single rule, in the order they are specified
 * If a document is matched by both a `pinned` rule and an `exclude` rule, the `exclude` rule will take precedence
 
-You can specify reranking retrievers such as [rrf](/reference/elasticsearch/rest-apis/retrievers.md#rrf-retriever) or [text_similarity_reranker](/reference/elasticsearch/rest-apis/retrievers.md#text-similarity-reranker-retriever) in the rule query to apply query rules on already-reranked results. Here is an example:
+You can specify reranking retrievers such as [rrf](/reference/elasticsearch/rest-apis/retrievers/rrf-retriever.md) or [text_similarity_reranker](/reference/elasticsearch/rest-apis/retrievers/text-similarity-reranker-retriever.md) in the rule query to apply query rules on already-reranked results. Here is an example:
 
 ```console
 GET my-index-000001/_search

+ 9 - 0
docs/reference/elasticsearch/toc.yml

@@ -96,6 +96,15 @@ toc:
             - file: rest-apis/retrieve-selected-fields.md
             - file: rest-apis/retrieve-stored-fields.md
             - file: rest-apis/retrievers.md
+              children:
+                - file: rest-apis/retrievers/knn-retriever.md
+                - file: rest-apis/retrievers/linear-retriever.md
+                - file: rest-apis/retrievers/pinned-retriever.md
+                - file: rest-apis/retrievers/rescorer-retriever.md
+                - file: rest-apis/retrievers/rrf-retriever.md
+                - file: rest-apis/retrievers/rule-retriever.md
+                - file: rest-apis/retrievers/standard-retriever.md
+                - file: rest-apis/retrievers/text-similarity-reranker-retriever.md
             - file: rest-apis/search-multiple-data-streams-indices.md
             - file: rest-apis/search-profile.md
             - file: rest-apis/search-rank-eval.md

+ 1 - 1
docs/reference/query-languages/query-dsl/query-dsl-rule-query.md

@@ -14,7 +14,7 @@ mapped_pages:
 
 
 ::::{tip}
-The rule query is not supported for use alongside reranking. If you want to use query rules in conjunction with reranking, use the [rule retriever](/reference/elasticsearch/rest-apis/retrievers.md#rule-retriever) instead.
+The rule query is not supported for use alongside reranking. If you want to use query rules in conjunction with reranking, use the [rule retriever](/reference/elasticsearch/rest-apis/retrievers/rule-retriever.md) instead.
 
 ::::
 

+ 1 - 1
docs/reference/query-languages/query-dsl/query-dsl-sparse-vector-query.md

@@ -150,7 +150,7 @@ GET my-index/_search
 }
 ```
 
-This can also be achieved using [reciprocal rank fusion (RRF)](/reference/elasticsearch/rest-apis/reciprocal-rank-fusion.md), through an [`rrf` retriever](/reference/elasticsearch/rest-apis/retrievers.md#rrf-retriever) with multiple [`standard` retrievers](/reference/elasticsearch/rest-apis/retrievers.md#standard-retriever).
+This can also be achieved using [reciprocal rank fusion (RRF)](/reference/elasticsearch/rest-apis/reciprocal-rank-fusion.md), through an [`rrf` retriever](/reference/elasticsearch/rest-apis/retrievers/rrf-retriever.md) with multiple [`standard` retrievers](/reference/elasticsearch/rest-apis/retrievers/standard-retriever.md).
 
 ```console
 GET my-index/_search

+ 1 - 1
docs/reference/query-languages/query-dsl/query-dsl-text-expansion-query.md

@@ -134,7 +134,7 @@ GET my-index/_search
 }
 ```
 
-This can also be achieved using [reciprocal rank fusion (RRF)](/reference/elasticsearch/rest-apis/reciprocal-rank-fusion.md), through an [`rrf` retriever](/reference/elasticsearch/rest-apis/retrievers.md#rrf-retriever) with multiple [`standard` retrievers](/reference/elasticsearch/rest-apis/retrievers.md#standard-retriever).
+This can also be achieved using [reciprocal rank fusion (RRF)](/reference/elasticsearch/rest-apis/reciprocal-rank-fusion.md), through an [`rrf` retriever](/reference/elasticsearch/rest-apis/retrievers/rrf-retriever.md) with multiple [`standard` retrievers](/reference/elasticsearch/rest-apis/retrievers/standard-retriever.md).
 
 ```console
 GET my-index/_search

Some files were not shown because too many files changed in this diff