> For the complete documentation index, see [llms.txt](https://docs.hexabot.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.hexabot.ai/retrieval-augmented-generation/rag-action.md).

# RAG action

Reference for the retrieve\_rag\_content workflow action

### `retrieve_rag_content` action

`retrieve_rag_content` retrieves CMS Content through the helper selected in `global_settings.default_rag_helper`. It can run as a normal workflow task or as a tool mounted on an AI Agent.

#### Input

| Field   | Type   | Required | Description                                                              |
| ------- | ------ | -------: | ------------------------------------------------------------------------ |
| `query` | string |      Yes | Non-empty natural-language or keyword query sent to the selected helper. |

#### Settings

| Field              | Type             |          Default | Description                                                                                 |
| ------------------ | ---------------- | ---------------: | ------------------------------------------------------------------------------------------- |
| `limit`            | positive integer | `3` when omitted | Maximum number of content hits to return. The value is passed to the helper.                |
| `content_type_id`  | string           |             None | Restricts retrieval to one Content Type. The action validates that the Content Type exists. |
| `include_inactive` | boolean          |          `false` | Allows inactive content to be returned when the helper has indexed it.                      |

#### Output

| Field     | Type                | Description                                                                                                 |
| --------- | ------------------- | ----------------------------------------------------------------------------------------------------------- |
| `hits`    | `RagHit[]`          | Ranked structured results returned by the helper.                                                           |
| `text`    | string              | The `text` value from each hit, joined with a blank line between hits. Convenient for an LLM prompt.        |
| `warning` | string or undefined | Explains a helper configuration or availability problem. In this case, `hits` is empty and `text` is empty. |

#### `RagHit`

| Field           | Type                | Description                                                                                                             |
| --------------- | ------------------- | ----------------------------------------------------------------------------------------------------------------------- |
| `contentId`     | string              | ID of the matching Content entry.                                                                                       |
| `title`         | string              | Content title.                                                                                                          |
| `text`          | string              | Matching canonical text or chunk text returned by the helper.                                                           |
| `score`         | number or undefined | Optional helper-specific rank or similarity score.                                                                      |
| `contentTypeId` | string or undefined | ID of the entry's Content Type.                                                                                         |
| `source`        | string              | Registered runtime name of the helper that produced the hit, such as `fulltext-search`, `sqlite-vector`, or `pgvector`. |

{% hint style="warning" %}
The action converts helper configuration and availability errors into `warning`, but unexpected application errors can still fail the workflow task. Always configure normal workflow error handling as well.
{% endhint %}

### Common integration patterns

#### Retrieve with a Content Type filter

Use a stable Content Type ID in the action settings or API request. Do not use the displayed label where an ID is required.

#### Retrieve first, generate second

Use `text` as model context and retain `hits` for traceability.

#### Let an agent retrieve

Define the action with `kind: tools` and mount the definition in the AI Agent's tools binding.

#### Build an external application

Call the search endpoint from a trusted backend, then supply the returned texts to the model under a separate, clearly delimited context section. Do not expose administrative reindexing endpoints to untrusted clients.


---

# 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.hexabot.ai/retrieval-augmented-generation/rag-action.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.
