

支援終止通知：2025 年 9 月 15 日， AWS 將停止對 Amazon Lex V1 的支援。2025 年 9 月 15 日之後，您將無法再存取 Amazon Lex V1 主控台或 Amazon Lex V1 資源。如果您使用的是 Amazon Lex V2，請改參閱 [Amazon Lex V2 指南](https://docs.aws.amazon.com/lexv2/latest/dg/what-is.html)。

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 範例：為 Amazon Kendra 索引建立常見問答集機器人
<a name="faq-bot-kendra-search"></a>

此範例會建立使用 Amazon Kendra 索引的 Amazon Lex 機器人，以提供使用者問題的答案。常見問題機器人會管理使用者的對話方塊。它使用 `AMAZON.KendraSearchIntent` 意圖來查詢索引，並向使用者呈現回應。若要建立機器人，您需：

1. 建立機器人，讓您的客戶與其互動以從機器人取得答案。

1. 建立自訂意圖。您的機器人需要至少一個意圖，此意圖具有至少一個表達用語。此意圖讓您的機器人可以建置，但不會用於其他用途。

1. 將`KendraSearchIntent`意圖新增至您的機器人，並將其設定為使用 Amazon Kendra 索引。

1. 透過詢問存放在 Amazon Kendra 索引中的文件所回答的問題來測試機器人。

您必須先建立 Amazon Kendra 索引，才能使用此範例。如需詳細資訊，請參閱《*Amazon Kendra 開發人員指南*》中的 [ S3 儲存貯體 （主控台） 入門](https://docs.aws.amazon.com/kendra/latest/dg/gs-console.html)。

**建立常見問題機器人**

1. 登入 AWS 管理主控台 ，並在 [https://console.aws.amazon.com/lex/](https://console.aws.amazon.com/lex/)：// 開啟 Amazon Lex 主控台。

1. 在導覽窗格中，選擇 **Bots (機器人)**。

1. 選擇**建立**。

1. 選擇 **Custom bot (自訂機器人)**。設定機器人，如下所示：
   + **機器人名稱** – 為機器人命名，指出其用途，例如 **KendraTestBot**。
   + **輸出語音** – 選擇**無**。
   + **工作階段逾時** – 輸入 **5**。
   + **情緒分析** – 選擇**否**。
   + **COPPA** – 選擇**否**。
   + **使用者表達用語儲存** – 選擇**不儲存**。

1. 選擇**建立**。

若要成功建置機器人，您必須至少建立一個意圖，此意圖具有至少一個範例表達用語。建置 Amazon Lex 機器人時需要此意圖，但不會用於常見問答集回應。意圖的表達用語不得套用至您的客戶所提出的任何問題。

**建立必要的意圖**

1. 在 **Getting started with your bot (開始使用您的機器人)** 頁面上，選擇 **Create intent (建立意圖)**。

1. 針對 **Add intent (新增意圖)**，選擇 **Create intent (建立意圖)**。

1. 在 **Create intent (建立意圖)** 對話方塊中，指定意圖名稱，例如 **RequiredIntent**。

1. 在 **Sample utterances (範例表達用語)** 中，輸入表達用語，例如 **Required utterance**。

1. 選擇**儲存意圖**。

現在，建立意圖來搜尋 Amazon Kendra 索引及其應傳回的回應訊息。

**建立 AMAZON.KendraSearchIntent 意圖和回應訊息**

1. 在導覽窗格中，選擇 **Intents (意圖)** 旁邊的加號 (\$1)。

1. 針對 **Add intent (新增意圖)**，選擇 **Search existing intents (搜尋現有的意圖)**。

1. 在**搜尋意圖**方塊中，輸入 **AMAZON.KendraSearchIntent**，然後從清單中選擇它。

1. 對於 **Copy built-in intent (複製內建意圖)**，提供意圖的名稱，例如 **KendraSearchIntent**，然後選擇 **Add (新增)**。

1. 在意圖編輯器中，選擇 **Amazon Kendra query (Amazon Kendra 查詢)** 以開啟查詢選項。

1. 從 **Amazon Kendra index (Amazon Kendra 索引)** 功能表中，選擇您想要搜尋意圖的索引。

1. 在 **Response (回應)** 區段中，新增下列三則訊息：

   ```
   I found a FAQ question for you: ((x-amz-lex:kendra-search-response-question_answer-question-1)) and the answer is ((x-amz-lex:kendra-search-response-question_answer-answer-1)).
   I found an excerpt from a helpful document: ((x-amz-lex:kendra-search-response-document-1)).
   I think the answer to your questions is ((x-amz-lex:kendra-search-response-answer-1)).
   ```

1. 選擇 **Save intent (儲存意圖)**，然後選擇 **Build (建置)** 以建置機器人。

最後，使用主控台測試視窗來測試您的機器人的回應。您的問題應該位於索引支援的網域中。

**測試您的常見問題機器人**

1. 在主控台測試視窗中，輸入索引的問題。

1. 驗證測試視窗回應部分中的答案。

1. 若要重設其他問題的測試視窗，請選擇 **Clear chat history (清除聊天歷史記錄)**。