

# AI Assistant for Amazon OpenSearch Service
<a name="AI-assistant-support"></a>

AI Assistant is a generative AI-powered assistant that helps developers and IT professionals perform a variety of tasks throughout the software development lifecycle. AI Assistant helps AWS customers code, test, deploy, troubleshoot, and optimize their applications running in AWS.

AI Assistant integration with Amazon OpenSearch Service offers the following generative capabilities:
+ [Generate visualizations using natural language](AI-Assistant-generate-visualizations.md)
+ [View alert summaries and insights](AI-assistant-alert-summary.md)
+ [View AI Assistant generated query result summaries on the Discover page](AI-assistant-query-summary.md)
+ [View recommended anomaly detectors](AI-assistant-anomaly-detectors.md)
+ [Access AI Assistant chat for OpenSearch-related questions](AI-assistant-chat-interface.md)

To access AI Assistant features in OpenSearch Service that are relevant to your task, look for the following in-context icon on the **Alerts**, **Discover**, and **Create visualization** pages. Click the icon to prompt for assistance and use the features described in this section.

You can also chat directly with AI Assistant by clicking the icon in the top-right corner of the OpenSearch Service console. AI Assistant chat supports answers to questions about OpenSearch Service features and functionality.

## Supported AWS Regions
<a name="AI-assistant-supported-regions"></a>

AI Assistant support for OpenSearch Service is available in the following AWS Regions:
+ US East (N. Virginia)
+ US West (Oregon)
+ Asia Pacific (Mumbai)
+ Asia Pacific (Sydney)
+ Asia Pacific (Tokyo)
+ Canada (Central)
+ Europe (Frankfurt)
+ Europe (London)
+ Europe (Paris)
+ South America (São Paulo)

# Setting up AI Assistant for OpenSearch Service
<a name="AI-Assistant-setting-up"></a>

Complete the following steps to set up AI Assistant for OpenSearch Service.

1. Verify that you have configured OpenSearch Service fine-grained access control. For more information, see [Fine-grained access control in Amazon OpenSearch Service](fgac.md).

1. Verify that your data source is on OpenSearch version 2.17 or later.

1. Verify that you selected the **Enable natural language query generation** checkbox in the **Artificial Intelligence (AI) and Machine Learning (ML)** section during domain creation or by editing the cluster configuration.

**Note**  
Amazon Q for Developer OpenSearch features are available with the Q free tier. For more information, see [Understanding tiers of service](https://docs.aws.amazon.com/amazonq/latest/qdeveloper-ug/q-tiers.html) in *Amazon Q User Guide*.

# Generate visualizations using natural language
<a name="AI-Assistant-generate-visualizations"></a>

To help you gain further insights into your operational data, AI Assistant for OpenSearch Service supports using natural language prompts to build visualizations. Before you start, verify that you've set up [AI Assistant for OpenSearch Service](https://docs.aws.amazon.com/opensearch-service/latest/developerguide/AI-Assistant-setting-up.html). Once confirmed, launch your OpenSearch Service UI application, navigate to the **Visualizations** page, select the **\$1 Create Visualization** button, and choose **natural language**. You can now specify a data source, and enter a requirement in natural language to generate the visualizations. Here is an example.

![\[A sample Amazon Q visualization in OpenSearch Service.\]](http://docs.aws.amazon.com/opensearch-service/latest/developerguide/images/AmazonQVisualization.gif)


Visualizations can expedite troubleshooting by breaking down error analysis according to different dimensions. Visualizations can also help you identify patterns and trends, speed up decision making, reveal relationships, and simplify complex data. Alternatively, you can also create visualizations in **Discover** page as part of the query results.

# View alert summaries and insights
<a name="AI-assistant-alert-summary"></a>

You can configure OpenSearch Service to create an alert monitor when data from one or more indexes meets certain conditions. To help you quickly understand and troubleshoot an alert, you can view an alert summary by clicking the AI Assistant icon beside an alert. A summary provides details about the underlying issue that triggered the alert and, when available, additional analysis to help you locate the root cause of the problem. The following screenshot shows an example of an alert summary created by AI Assistant.

![\[An example of an AI Assistant alert summary in OpenSearch Service.\]](http://docs.aws.amazon.com/opensearch-service/latest/developerguide/images/AmazonQAlertSummary.gif)


If you connect a knowledge base to provide additional context about your environment, as described later in this topic, AI Assistant creates insights about an alert. Insights provide details and troubleshooting options to help you remedy the root cause of an alert. For the previously shown alert, AI Assistant also produced the following insights.

![\[An example of an AI Assistant alert insight in OpenSearch Service.\]](http://docs.aws.amazon.com/opensearch-service/latest/developerguide/images/AmazonQAlertInsight.gif)


**Note**  
Depending on the nature of the alert and the information available, AI Assistant can give you the option to view the alert data on the **Discover** page in the OpenSearch Dashboards. If you see the **View in Discover** button at the bottom of an AI Assistant alert summary, click the button to open the corresponding data set in **Discover** with an active filter for the alert data. 

**Topics**
+ [Before you begin](#AI-assistant-alert-summary-insight-setup)
+ [Viewing alert summaries and insights](#AI-assistant-viewing-alert-summaries)

## Before you begin
<a name="AI-assistant-alert-summary-insight-setup"></a>

Complete the following steps to configure an Amazon Bedrock knowledge base so that AI Assistant can create insights for OpenSearch Service alerts.

### Step 1: Create the LambdaInvokeOpenSearchMLCommonsRole IAM role
<a name="AI-assistant-alert-summary-insight-setup-step-1"></a>

Create a new role named `LambdaInvokeOpenSearchMLCommonsRole` in AWS Identity and Access Management (IAM). OpenSearch Service uses this role to create an AI connector in OpenSearch that helps produce insights based on configured knowledge base articles. You must map this role to the OpenSearch Service `ml_full_access` role, as described in step 2.

When you create the new role, for **Trusted entity type**, choose **AWS account**. You don't need to specify a permission policy. On the **Add permissions** page, choose **Next**. For more information about creating a new role, see [Creating a role for an AWS service (console)](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_create_for-service.html#roles-creatingrole-service-console).

### Step 2: Map the LambdaInvokeOpenSearchMLCommonsRole role to the OpenSearch Service ml\$1full\$1access role
<a name="AI-assistant-alert-summary-insight-setup-step-2"></a>

Use the following procedure to map the `LambdaInvokeOpenSearchMLCommonsRole` role to the OpenSearch Service `ml_full_access` role. This mapping also helps OpenSearch Service create the AI connector.

**To map the required IAM role to the OpenSearch Service ml\$1full\$1access role**

1. Open the OpenSearch Service Dashboard **Data administration** page.

1. Under **Data access and user**, choose **Roles**.

1. Use the search box to locate the `ml_full_access` role.

1. On the **ml\$1full\$1access** page, choose the **Mapped users** tab.

1. Choose **Map users**.

1. In the **Backend roles** field, paste the Amazon Resource Name (ARN) of the `LambdaInvokeOpenSearchMLCommonsRole` role, and then choose **Map**.

### Step 3: Configure an OpenSearch Service knowledge base using CloudFormation
<a name="AI-assistant-alert-summary-insight-setup-step-3"></a>

Use the following procedure to configure an OpenSearch Service knowledge base using AWS CloudFormation so that AI Assistant can generate insights.

**To configure a knowledge base for insights**

1. Sign in to the Amazon OpenSearch Service console [https://console.aws.amazon.com/aos/home](https://console.aws.amazon.com/aos/home) in a supported AWS Region. For more information, see [Supported AWS Regions](AI-assistant-support.md#AI-assistant-supported-regions).

1. In the navigation pane, choose **Integrations**.

1. In the **Integration templates** section, choose the **Integrate with knowledge base through Amazon Bedrock** template. If you don't see this template, verify you're in a supported Region.

1. In the **Integrate with knowledge base through Amazon Bedrock** tile, choose **Configure domain**, and then choose one of the available options. OpenSearch Service opens the CloudFormation stack template with the required fields pre-populated. The CloudFormation stack supports integration for public and VPC domains.

1. Choose **Create stack**. After CloudFormation creates the resources, the service displays the Amazon Bedrock agent **AgentId**, **ConnectorId**, and **ModelId**.

When applicable, AI Assistant now creates insights for OpenSearch Service alerts.

## Viewing alert summaries and insights
<a name="AI-assistant-viewing-alert-summaries"></a>

Use the following procedure to view alert summaries and insights in OpenSearch Service.

**Viewing alert summaries and insights**

1. Verify that you've [set up AI Assistant for OpenSearch Service](https://docs.aws.amazon.com/opensearch-service/latest/developerguide/AI-Assistant-setting-up.html).

1. Verify that you've [set up alerts for OpenSearch Service](https://docs.aws.amazon.com/opensearch-service/latest/developerguide/alerting.html).

1. In the OpenSearch Dashboards main menu, choose **Alerting**, and then choose **Alerts**.

1. Choose the AI Assistant icon beside an alert. AI Assistant can take up to 10 seconds to generate the summary.

1. If present in the alert summary, choose **View insights** to view more details about the alert based on your configured knowledge base.

1. If present in the alert summary, choose **View in Discover** to view the alert data on the **Discover** page in the OpenSearch Dashboards.

# View AI Assistant generated query result summaries on the Discover page
<a name="AI-assistant-query-summary"></a>

OpenSearch Service enables you to [query your data with natural language prompts](https://docs.aws.amazon.com/opensearch-service/latest/developerguide/natural-language-query.html) using the Piped Processing Language (PPL) query language on the **Discover** page. For example, you can write queries like the following:
+ Are there any errors in my error logs?
+ What's the average request size by week?
+ How many requests were there group by response code last week?

In response, AI Assistant generates natural language summaries of your query results based on the first ten records, like the following:

![\[An example of an AI Assistant natural language query and summary.\]](http://docs.aws.amazon.com/opensearch-service/latest/developerguide/images/AmazonQQuery.gif)


The combination of natural language query generation and query summaries can add an additional level of inquiry when troubleshooting an alert or a user-friendly means of understanding your data without having to write complex queries.

**To view AI Assistant generated query result summaries on the Discover page**

1. Verify that you've [set up AI Assistant for OpenSearch Service](https://docs.aws.amazon.com/opensearch-service/latest/developerguide/AI-Assistant-setting-up.html).

1. In the OpenSearch Dashboards main menu, choose **Discover**.

1. In the query language drop-down list, choose **PPL**.

1. In the AI Assistant text box, enter a prompt, and then click the button beside the text box to run the query. AI Assistant can take up to 10 seconds to return a summary. After your initial query, you must choose **Generate summary** for subsequent summaries.

**Note**  
You can turn summary generation off from the **AI Assistant** drop-down list in **Discover**.

# View recommended anomaly detectors
<a name="AI-assistant-anomaly-detectors"></a>

Anomaly detection in Amazon OpenSearch Service automatically detects anomalies in your OpenSearch data in near-real time by using the Random Cut Forest (RCF) algorithm. RCF is an unsupervised machine learning algorithm that models a sketch of your incoming data stream. The algorithm computes an `anomaly grade` and `confidence score` value for each incoming data point. Anomaly detection uses these values to differentiate an anomaly from normal variations in your data. 

To simplify the process of creating anomaly detectors, AI Assistant can generate suggested detectors based on your selected data source on the **Discover** page. AI Assistant supports suggested anomaly detectors for any language.

**To view AI Assistant recommended anomaly detectors**

1. Verify that you've [set up AI Assistant for OpenSearch Service](https://docs.aws.amazon.com/opensearch-service/latest/developerguide/AI-Assistant-setting-up.html).

1. In the OpenSearch UI main menu, choose the **Discover** page, and then choose a data source.

1. From the **AI Assistant** menu, choose **Suggest anomaly detector**, as shown in the following screen shot.  
![\[An image showing how to locate the button to create a suggested anomaly detector.\]](http://docs.aws.amazon.com/opensearch-service/latest/developerguide/images/AmazonQAnomalyDetectorButton.gif)

   AI Assistant can take a few seconds to generate the features for the detector.

1. Choose **Create detector**.

# Access AI Assistant chat for OpenSearch-related questions
<a name="AI-assistant-chat-interface"></a>

If you have questions about Amazon OpenSearch Service, including conceptual or procedural questions related to OpenSearch Service features or functionality, you can ask AI Assistant for information. The chatbot supports a conversational chat that preserves context of your discussion. It also saves a history of your conversations for later reference. To access the chatbot, click the AI Assistant icon at the top-right corner of any OpenSearch Service page. Type a question in the text box and click **Go**. AI Assistant can take up to 30 seconds to generate a response.

![\[The AI Assistant chatbot user experience in OpenSearch Service.\]](http://docs.aws.amazon.com/opensearch-service/latest/developerguide/images/AmazonQChatUI.gif)


Here is an example response from AI Assistant.

![\[Example of an AI Assistant chatbot response.\]](http://docs.aws.amazon.com/opensearch-service/latest/developerguide/images/AmazonQChatResponse.gif)
