> For the complete documentation index, see [llms.txt](https://docs.rierino.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.rierino.com/devops/api-event-and-process-flows/configuring-saga-steps/event-step/ml-and-ai-actions/rerank-documents.md).

# Rerank Documents

These actions reorder candidate documents by their relevance to a query, to improve search and RAG retrieval quality.

## Rerank Documents Actions

### **Rerank**

Scores candidate documents against a query and returns them ordered by relevance. Event metadata fields applicable for this action are as follows:

{% tabs %}
{% tab title="Fields (table)" %}

| Field          | Definition                                         | Example | Default |
| -------------- | -------------------------------------------------- | ------- | ------- |
| Input Element  | Json path for the input in request event payload   | input   | -       |
| Output Element | Json path for the output in response event payload | output  | -       |
| {% endtab %}   |                                                    |         |         |

{% tab title="Fields (JSON Schema)" %}

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "eventMeta": {
      "type": "object",
      "properties": {
        "inputElement": {
          "type": "string",
          "description": "Json path for the input in request event payload",
          "examples": ["input"],
          "default": null
        },
        "outputElement": {
          "type": "string",
          "description": "Json path for the output in response event payload",
          "examples": ["output"],
          "default": null
        }
      }
    }
  }
}
```

{% endtab %}
{% endtabs %}

With event metadata parameters as:

{% tabs %}
{% tab title="Parameters (table)" %}

| Parameter     | Definition                                                                 | Example                     | Default |
| ------------- | -------------------------------------------------------------------------- | --------------------------- | ------- |
| Input Pattern | JMESpath pattern to apply on input element for getting query and documents | {query: q, documents: hits} | -       |
| Max Results   | Maximum number of reranked documents to return                             | 5                           | -       |
| Min Score     | Minimum relevance score required for a document to be returned             | 0.3                         | -       |
| {% endtab %}  |                                                                            |                             |         |

{% tab title="Parameters (JSON Schema)" %}

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "eventMeta": {
      "type": "object",
      "properties": {
        "parameters": {
          "type": "object",
          "properties": {
            "inputPattern": {
              "type": "string",
              "description": "JMESpath pattern to apply on input element for getting query and documents",
              "examples": ["{query: q, documents: hits}"],
              "default": null
            },
            "maxResults": {
              "type": "integer",
              "description": "Maximum number of reranked documents to return",
              "examples": [5],
              "default": null
            },
            "minScore": {
              "type": "number",
              "description": "Minimum relevance score required for a document to be returned",
              "examples": [0.3],
              "default": null
            }
          }
        }
      }
    }
  }
}
```

{% endtab %}
{% endtabs %}

The input element (after the input pattern is applied) must be in `{query, documents}` format. `query` is the search text. `documents` is a non-empty array whose items are plain strings or objects in `{text, metadata}` format:

```json
{
  "query": "how do I get a refund?",
  "documents": [
    "Shipping usually takes 3-5 business days.",
    {"text": "Refunds are issued within 14 days of return.", "metadata": {"id": "faq-12"}}
  ]
}
```

Reranked documents are written to `results` in the output element, highest relevance first. Each entry is in `{score, index, text, metadata}` format:

* `index` is the document's position in the input array.
* `metadata` is passed through unchanged from object documents.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.rierino.com/devops/api-event-and-process-flows/configuring-saga-steps/event-step/ml-and-ai-actions/rerank-documents.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
