> ## Documentation Index
> Fetch the complete documentation index at: https://rasa.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Integrate RAG in Rasa

> Learn more about how to design your assistant

Many AI assistants need to handle both structured workflows and open-ended knowledge queries.
Rasa's approach to Enterprise Search and Retrieval-Augmented Generation (RAG) enables you to build assistants that can blend these capabilities,
ensuring users get the information and support they need.

## Types of AI Assistant Conversations

Conversations with AI assistants typically fall into two categories: **Transactional** and **Informational**.

**Transactional**:\
These conversations are structured, goal-oriented, and designed to complete specific tasks. They guide users through predefined processes—such as booking a flight, checking an account balance, or filing a support ticket—where every input and response is precisely managed to ensure a successful transaction.

**Informational**:\
These conversations are designed to answer questions and provide insights. Whether users are inquiring about product features, technical details, or pricing, these dialogues rely on current data and strong contextual understanding to deliver clear, relevant answers.

Real conversations often mix both types - a user might start booking a flight (transactional) but then ask about baggage policies (informational) before completing their booking.

## Understanding RAG

To enable building assistants that can handle different conversational usecases, Rasa enables you to integrate Retrieval-Augmented Generation (RAG) into your assistants.
RAG is a method that leverages LLMs to produce more accurate and up-to-date responses by providing them access to external knowledge sources.

RAG involves three steps:

1. **Retrieval**: When a user asks a question, we search through a knowledge base (documents, databases, or other structured information) to find relevant information.
2. **Augmentation**: The retrieved information is combined with the user's query and conversation context to create a comprehensive prompt.
3. **Generation**: This enriched prompt is sent to an LLM which generates a response that incorporates the retrieved information.

## How RAG Works in Rasa

Rasa enables assistants to handle informational dialogue at any point in the conversation.

When a user asks an informational question, Rasa's **Dialogue Understanding** component will produce a `SearchAndReply` command.
This command triggers the search pattern, which processes the knowledge query and then returns back to the ongoing conversation.

User:

Yes the 17:30 flight to San Fransisco works fine.

action\_flight\_booking triggered

Bot:

Great! It's confirmed. You're going to SF at 17:30 tomorrow, anything else I can help you with?

User:

Actually - how big a bag can I bring again?

pattern\_search triggered

Bot:

One moment, let me check the latest baggage policy information for the flight.

Bot:

I found that your flight includes one carry-on bag and one checked bag up to 50 lbs. Extra checked bags are available for an additional fee.

User:

Thanks! Please add an extra checked bag to my booking.

action\_flight\_booking\_update triggered

Bot:

Got it. I’ve updated your reservation to include an extra checked bag. Let’s proceed with your booking details.

Example illustrating Rasa's RAG and Enterprise Search in a Flight Booking Scenario

**📌 Pro tip:** You can also trigger enterprise search at specific points in a conversation by adding it as a step in your flow.

## Getting Started with Enterprise Search

### Step One: Prep your Knowledge Base

Rasa offers flexible options for configuring your knowledge base when setting up Retrieval-Augmented Generation (RAG). You can choose from two primary storage methods:

#### Folder-Based Storage

For a quick and simple setup, you can store text documents in your project’s `/docs` folder. This approach is ideal for rapid development and prototyping, as it provides an easy-to-use source of information for the LLM to generate responses.

#### Vector Database

For a production-ready solution, consider connecting to a vector database like [Qdrant](https://qdrant.tech/) or [Milvus](https://github.com/milvus-io/milvus/). This method supports dynamic updates and enables sharing your knowledge base among multiple assistants.

<Tabs>
  <Tab title="Pro">
    > **Note:** In this example, we use the simple folder-based storage approach to demonstrate how to prepare your knowledge base, configure Enterprise Search, and override the search flow. This is a quickstart approach using Pro.

    ```yaml-rasa title="docs/sampleDocument.txt" theme={null}
    We have five type of cards:  debit card, credit card, and loyalty card.

    The price of a debit card is between 5 euros and 10, depending on the options you want to have.
    Debit cards are directly linked to the user's bank account.

    If the borrowed amount is not paid in full, credit card users may incur interest charges.

    Loyalty cards are designed to reward customers for their repeat business.
    Customers typically earn points or receive discounts based on their purchases.
    Loyalty cards are often part of broader membership programs that may include additional benefits.
    ```
  </Tab>

  <Tab title="Studio">
    > **Note:** In Studio it's more straightforward to integrate enterprise search when you have set up your vector database already.

    <img src="https://mintcdn.com/rasa-43f32701/eLeGQhEoUGCT-ckv/images/legacy/studio/building/config-es-vector-store.png?fit=max&auto=format&n=eLeGQhEoUGCT-ckv&q=85&s=b3c97f6bbe0871e8fa434c16052b0e07" alt="Configure your Vector Store for Enterprise Search" width="2538" height="1612" data-path="images/legacy/studio/building/config-es-vector-store.png" />
  </Tab>
</Tabs>

### Step Two: Configure the Command Generator and Enterprise Search

Include the correct command generator (`SearchReadyLLMCommandGenerator`) in your assistant's configuration -

<Tabs>
  <Tab title="Pro">
    ```yaml title="config.yml" theme={null}
    pipeline:
      - name: SearchReadyLLMCommandGenerator
        llm:  # The model for command generation
          model_group: command_generator_llm
    policies:
      - name: EnterpriseSearchPolicy
        llm:  # The model for response generation
          model_group: enterprise_search_generation
        embeddings: # The model for your embeddings
          model_group: enterprise_search_embeddings
        vector_store:
          type: "faiss"
          source: "./docs" # The path to the folder where your text files are stored
    ```

    ```yaml title="endpoints.yml" theme={null}
    model_groups:
      - id: command_generator_llm
        models:
          - provider: "openai"
            model: "gpt-4o-2024-11-20"
      - id: enterprise_search_generation
        models:
          - provider: "openai"
            model: "gpt-4.1-mini-2025-04-14"
      - id: enterprise_search_embeddings
        models:
          - provider: "openai"
            model: "text-embedding-3-large"
    ```
  </Tab>

  <Tab title="Studio">
    <img src="https://mintcdn.com/rasa-43f32701/eLeGQhEoUGCT-ckv/images/legacy/studio/building/config-es-policy.png?fit=max&auto=format&n=eLeGQhEoUGCT-ckv&q=85&s=49240dcda345ce6804231d4a08e8f5da" alt="Edit config.yml for enterprise search" width="2868" height="1010" data-path="images/legacy/studio/building/config-es-policy.png" />

    <img src="https://mintcdn.com/rasa-43f32701/eLeGQhEoUGCT-ckv/images/legacy/studio/building/endpoints-es.png?fit=max&auto=format&n=eLeGQhEoUGCT-ckv&q=85&s=bf2a1042b4de8ca903c1877d5fbc3c63" alt="Edit endpoints.yml for enterprise search" width="2866" height="1126" data-path="images/legacy/studio/building/endpoints-es.png" />
  </Tab>
</Tabs>

### Step Three: Override pattern\_search

<Tabs>
  <Tab title="Pro">
    Modify `flows.yml` by adding a new system flow called `pattern_search` to trigger document search for knowledge-based questions:

    ```yaml title="flows.yml" theme={null}
    flows:
      pattern_search:
        description: Handle knowledge-based questions.
        steps:
          - action: action_trigger_search
    ```
  </Tab>

  <Tab title="Studio">
    Go to the "System flows" tab and open `pattern_search` to modify it.

    <img src="https://mintcdn.com/rasa-43f32701/MQtQODV4k9Yeq80-/images/legacy/studio/building/system-flows-search.png?fit=max&auto=format&n=MQtQODV4k9Yeq80-&q=85&s=ad9fabe2b7c4e34612dd5b21f068ee16" alt="Search for System Flows" width="2646" height="1664" data-path="images/legacy/studio/building/system-flows-search.png" />

    Delete the message and add the custom action step instead. In the right panel, select the action named `action_trigger_search`.

    <img src="https://mintcdn.com/rasa-43f32701/eLeGQhEoUGCT-ckv/images/legacy/studio/building/pattern-search-action.png?fit=max&auto=format&n=eLeGQhEoUGCT-ckv&q=85&s=58bf552993d85eefcf81f4af9f01ecd1" alt="Add Custom Action Step in System Flows" width="2742" height="1656" data-path="images/legacy/studio/building/pattern-search-action.png" />
  </Tab>
</Tabs>

This will send relevant queries to the default action `action_trigger_search`.

### Step Four: Try out your assistant

Once you have indexed your documents and trained your assistant, you should be ready to try out your new informational conversation!

<img src="https://mintcdn.com/rasa-43f32701/eDjBolAWgmzj0Tj5/images/legacy/rag_chat.gif?s=82e25b162cf1d84cb564e6b5f4f76b6c" alt="conversation example" width="400" height="649" data-path="images/legacy/rag_chat.gif" />

Example conversation with a Rasa assistant using Enterprise Search

## Customization Options

### LLM and Prompt Customization (Optional)

Rasa ships with default prompts for RAG interactions, but you can customize these to better match your use case. This ensures that generated responses align with your specific needs.

You can also choose the LLM that best fits your needs. Rasa supports various LLM providers and can also work with your hosted LLMs, allowing you to balance factors like response quality, speed, and cost.
For more details on customizing your model configuration [see this reference](/docs/reference/config/policies/enterprise-search-policy#embeddings).

### Extractive Search (Optional)

For scenarios where you want to deliver pre-approved answers from your knowledge base directly to your user, Rasa supports **Extractive Search**.
This method bypasses the LLM generation step, reducing both cost and latency and ensuring complete control and consistency over responses.
You can read more about this feature in the [technical reference](/docs/reference/config/policies/extractive-search).


## Related topics

- [Configuring Enterprise Search (RAG)](/docs/pro/build/configuring-enterprise-search.md)
- [How to Use the Platform](/docs/learn/platform-workflow.md)
- [Enterprise Search](/docs/pro/customize/enterprise-search.md)
- [Designing Natural and Engaging Conversations](/docs/learn/best-practices/conversation-design.md)
- [Compatibility Matrix for the Rasa Platform](/docs/reference/changelogs/compatibility-matrix.md)
