# Retrieval Actions

Warning

This feature is experimental.  We introduce experimental features to get feedback from our community, so we encourage you to try it out! However, the functionality might be changed or removed in the future. If you have feedback (positive or negative) please share it with us on the [forum](https://forum.rasa.com/). Also, currently we do not support adding new annotations in Rasa X if your training data contains retrieval actions.

## [About](https://legacy-docs-v1.rasa.com/1.7.1/core/retrieval-actions/#about)

Retrieval actions are designed to make it simpler to work with [Small Talk](https://legacy-docs-v1.rasa.com/1.7.1/dialogue-elements/small-talk/#small-talk) and [Simple Questions](https://legacy-docs-v1.rasa.com/1.7.1/dialogue-elements/completing-tasks/#simple-questions). For example, if your assistant can handle 100 FAQs and 50 different small talk intents, you can use a single retrieval action to cover all of these.

Instead of having a lot of stories like:

```
## weather
* ask_weather
   - utter_ask_weather

## introduction
* ask_name
   - utter_introduce_myself

```

You can cover all of these with a single story where the above intents are grouped under a common `chitchat` intent:

```
## chitchat
* chitchat
   - respond_chitchat
```

A retrieval action uses the output of a [Response Selector](https://legacy-docs-v1.rasa.com/1.7.1/nlu/components/#response-selector) component from NLU which learns a retrieval model to predict the correct response from a list of candidate responses given a user message text.

## [Training Data](https://legacy-docs-v1.rasa.com/1.7.1/core/retrieval-actions/#training-data)

Like the name suggests, retrieval actions learn to select the correct response from a list of candidates. As with other NLU data, you need to include examples of what your users will say in your NLU file:

```
## intent: chitchat/ask_name
- what's your name
- who are you?
- what are you called?

## intent: chitchat/ask_weather
- how's weather?
- is it sunny where you are?
```

First, all of these examples will be combined into a single `chitchat` retrieval intent that NLU will predict. All retrieval intents have a suffix added to them which identifies a particular response text for your assistant, in the above example - `ask_name` and `ask_weather`. The suffix is separated from the intent name by a `/` delimiter.

## [Config File](https://legacy-docs-v1.rasa.com/1.7.1/core/retrieval-actions/#config-file)

You need to include the [Response Selector](https://legacy-docs-v1.rasa.com/1.7.1/nlu/components/#response-selector) component in your config. The component needs a tokenizer, a featurizer and an intent classifier to operate on the user message before it can predict a response and hence these components should be placed before `ResponseSelector` in the NLU configuration. An example:

```
language: "en"

pipeline:
- name: "WhitespaceTokenizer"
  intent_split_symbol: "_"
- name: "CountVectorsFeaturizer"
- name: "EmbeddingIntentClassifier"
- name: "ResponseSelector"
```

## [Domain](https://legacy-docs-v1.rasa.com/1.7.1/core/retrieval-actions/#domain)

Rasa uses a naming convention to match the intent names like `chitchat/ask_name` to the retrieval action. The correct action name in this case is `respond_chitchat`. The prefix `respond_` is mandatory to identify it as a retrieval action. Another example - correct action name for `faq/ask_policy` would be `respond_faq`.  To include this in your domain, add it to the list of actions:

```
actions:
  ...
  - respond_chitchat
  - respond_faq
```

## [Multiple Retrieval Actions](https://legacy-docs-v1.rasa.com/1.7.1/core/retrieval-actions/#multiple-retrieval-actions)

If your assistant includes both FAQs **and** chitchat, it is possible to separate these into separate retrieval actions, for example having intents like `chitchat/ask_weather` and `faq/returns_policy`. Rasa supports adding multiple `RetrievalActions` like `respond_chitchat` and `respond_returns_policy`.

```json
{
    "text": "What is the recommend python version to install?",
    "entities": [],
    "intent": {"confidence": 0.6485910906220309, "name": "faq"},
    "intent_ranking": [
        {"confidence": 0.6485910906220309, "name": "faq"},
        {"confidence": 0.1416153159565678, "name": "greet"}
    ],
    "response_selector": {
      "faq": {
        "response": {"confidence": 0.7356462617, "name": "Supports 3.5, 3.6 and 3.7, recommended version is 3.6"},
        "ranking": [
            {"confidence": 0.7356462617, "name": "Supports 3.5, 3.6 and 3.7, recommended version is 3.6"},
            {"confidence": 0.2134543431, "name": "You can ask me about how to get started"}
        ]
      }
    }
}
```
