📝

S3 をナレッジベースにした Amazon Q in Connect を日本語で使用してみた

に公開

AWS CLIで、Amazon Q in Connect のコンテンツ検索を日本語ロケールに設定してみた | DevelopersIO
S3 をナレッジベースとして上記ブログの内容をやってみました。

前提

  • Amazon Connect インスタンス作成済み
  • バージニア北部リージョンを使用

ナレッジベース用の資料作成

What is AWS? - Cloud Computing with AWS - Amazon Web Services
上記ページの内容をもとに英語版と日本語版の資料を作成しておきます。

  • 英語の資料
WhatIsAWS.txt
AWS has significantly more services, and more features within those services, than any other cloud provider–from infrastructure technologies like compute, storage, and databases–to emerging technologies, such as machine learning and artificial intelligence, data lakes and analytics, and Internet of Things. This makes it faster, easier, and more cost effective to move your existing applications to the cloud and build nearly anything you can imagine.
  • 日本語の資料
AWSについて.txt
AWS には、コンピューティング、ストレージ、データベースなどのインフラストラクチャテクノロジーから機械学習、AI、データレイクと分析、IoT などの最新鋭のテクノロジーに至るまで、他のどのクラウドプロバイダーよりもはるかに多くのサービスを提供しており、それぞれのサービスが豊富な機能を備えています。より速く、より簡単に、より高い費用対効果で既存のアプリケーションをクラウドに移行し、想像できるものはほぼすべて構築することが可能です。

S3 バケットの作成

デフォルト設定で S3 バケットを作成しておきます。

動作確認のためにこの時点では資料のアップロードは行いません。

KMS キーの作成

Enable Amazon Q in Connect for your instance - Amazon Connect

S3 バケットをナレッジとして使用する場合には CMK が必要なのでドキュメントに沿って作成しておきます。

  • キーのタイプ: 対称
  • キーの使用法: 暗号化および復号化
  • エイリアス: 任意 (今回は Amazon_Q_in_Connect_Key という名称を指定)
  • キーポリシー: ドキュメントの通り以下のように設定
{
    "Id": "key-consolepolicy-3",
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::your_accountId:root"
            },
            "Action": "kms:*",
            "Resource": "*"
        },
        {
            "Effect": "Allow",
            "Principal": {
                "Service": "connect.amazonaws.com"
            },
            "Action": [
                "kms:Decrypt",
                "kms:GenerateDataKey*",
                "kms:DescribeKey"
            ],
            "Resource": "*"
        }
    ]
}   

Amazon Connect インスタンスの設定

Enable Amazon Q in Connect for your instance - Amazon Connect
上記ドキュメントに沿って設定します。

Amazon Connect コンソールからインスタンスを選択し、左ペインの「Amazon Q」 > ドメインを追加の順にクリックします。

ドメイン名には任意の名称を指定し、暗号化設定はデフォルトキーを使用するよう設定しました。

ドメインの作成後、「統合を追加」をクリックします。

新しい統合を作成で S3 を選択し、任意の統合名を入力します。

S3 バケットおよび KMS キーでは作成済みのバケットとキーを選択します。

問題なければ統合を追加します。

資料追加前にインスタンス内で動作確認

Amazon Connect インスタンスにログインし、エージェント Workspace をクリックします。

チャット欄で AWS に関する質問を入力してみます。

英語でも日本語でも以下のメッセージが表示され、AWS に関する回答を得られないことを確認しておきます。

このリクエストに対するソリューションを生成できませんでした。別の質問をすることを検討してください。

S3 バケットに資料をアップロード

まずは S3 バケットに英語の資料をアップロードします。

1 ~ 2 分ほど待ってから再度チャット欄で AWS に関する質問を入力してみます。

英語でも日本語でも英語の資料の内容で回答を得られました。

次に、S3 バケットに日本語の資料をアップロードします。

1 ~ 2 分ほど待ってから再度チャット欄で AWS に関する質問を入力しても日本語の資料の内容での回答を得られません。

ロケールを変更してみる

AWS CLIで、Amazon Q in Connect のコンテンツ検索を日本語ロケールに設定してみた | DevelopersIO
上記ブログに沿ってロケール設定を変更してみます。

まずは現状の確認としてアシスタントの設定を確認してみます。

list-assistants の結果
$ aws qconnect list-assistants
{
    "assistantSummaries": [
        {
            "aiAgentConfiguration": {
                "ANSWER_RECOMMENDATION": {
                    "aiAgentId": "3025a3fa-5419-4c9c-a040-877213b93f70:4"
                },
                "MANUAL_SEARCH": {
                    "aiAgentId": "652f0287-1610-4fee-bbe3-c687c13f5ec3:4"
                },
                "SELF_SERVICE": {
                    "aiAgentId": "529207fe-80fd-42be-bcf2-facd2141aec7:1"
                }
            },
            "assistantArn": "arn:aws:wisdom:us-east-1:012345678901:assistant/16e02991-ed51-4a02-87ab-c362a1b92409",
            "assistantId": "16e02991-ed51-4a02-87ab-c362a1b92409",
            "capabilityConfiguration": {
                "type": "V2"
            },
            "integrationConfiguration": {
                "topicIntegrationArn": "arn:aws:sns:us-east-1:012345678901:wisdom-d7257000-940b-418c-a7be-be0bbbb74bd4"
            },
            "name": "test",
            "status": "ACTIVE",
            "tags": {
                "AmazonConnectEnabled": "True"
            },
            "type": "AGENT"
        }
    ]
}
MANUAL_SEARCH に対する get-ai-agent の結果
$ aws qconnect get-ai-agent \
--ai-agent-id 652f0287-1610-4fee-bbe3-c687c13f5ec3:4  \
--assistant-id 16e02991-ed51-4a02-87ab-c362a1b92409

{
    "aiAgent": {
        "aiAgentArn": "arn:aws:wisdom:us-east-1:012345678901:ai-agent/16e02991-ed51-4a02-87ab-c362a1b92409/652f0287-1610-4fee-bbe3-c687c13f5ec3:4",
        "aiAgentId": "652f0287-1610-4fee-bbe3-c687c13f5ec3",
        "assistantArn": "arn:aws:wisdom:us-east-1:012345678901:assistant/16e02991-ed51-4a02-87ab-c362a1b92409",
        "assistantId": "16e02991-ed51-4a02-87ab-c362a1b92409",
        "configuration": {
            "manualSearchAIAgentConfiguration": {
                "answerGenerationAIPromptId": "b6e05fe6-6ed5-4b75-83e7-7c625d5cf6b9:4",
                "locale": "en_US"
            }
        },
        "modifiedTime": "1970-01-01T00:00:00+00:00",
        "name": "QinConnectManualSearchAIAgent",
        "origin": "SYSTEM",
        "status": "ACTIVE",
        "type": "MANUAL_SEARCH",
        "visibilityStatus": "PUBLISHED"
    },
    "versionNumber": 4
}

デフォルトでは localeen_US になっていることを確認できました。
このロケール設定を変えていきます。

create-ai-agent の結果
$ aws qconnect create-ai-agent \
--assistant-id 16e02991-ed51-4a02-87ab-c362a1b92409 \
--name jp_manual_search_ai_agent \
--visibility-status PUBLISHED \
--type MANUAL_SEARCH \
--configuration '{"manualSearchAIAgentConfiguration": {"locale": "ja_JP"}}'

{
    "aiAgent": {
        "aiAgentArn": "arn:aws:wisdom:us-east-1:012345678901:ai-agent/16e02991-ed51-4a02-87ab-c362a1b92409/73515101-73f6-4f5f-a342-fae8605f3687",
        "aiAgentId": "73515101-73f6-4f5f-a342-fae8605f3687",
        "assistantArn": "arn:aws:wisdom:us-east-1:012345678901:assistant/16e02991-ed51-4a02-87ab-c362a1b92409",
        "assistantId": "16e02991-ed51-4a02-87ab-c362a1b92409",
        "configuration": {
            "manualSearchAIAgentConfiguration": {
                "locale": "ja_JP"
            }
        },
        "modifiedTime": "2025-03-06T11:52:20+00:00",
        "name": "jp_manual_search_ai_agent",
        "origin": "CUSTOMER",
        "status": "ACTIVE",
        "tags": {},
        "type": "MANUAL_SEARCH",
        "visibilityStatus": "PUBLISHED"
    }
}
create-ai-agent-version の結果
$ aws qconnect create-ai-agent-version \
--assistant-id 16e02991-ed51-4a02-87ab-c362a1b92409 \
--ai-agent-id 73515101-73f6-4f5f-a342-fae8605f3687

{
    "aiAgent": {
        "aiAgentArn": "arn:aws:wisdom:us-east-1:012345678901:ai-agent/16e02991-ed51-4a02-87ab-c362a1b92409/73515101-73f6-4f5f-a342-fae8605f3687:1",
        "aiAgentId": "73515101-73f6-4f5f-a342-fae8605f3687",
        "assistantArn": "arn:aws:wisdom:us-east-1:012345678901:assistant/16e02991-ed51-4a02-87ab-c362a1b92409",
        "assistantId": "16e02991-ed51-4a02-87ab-c362a1b92409",
        "configuration": {
            "manualSearchAIAgentConfiguration": {
                "locale": "ja_JP"
            }
        },
        "modifiedTime": "2025-03-06T11:52:20+00:00",
        "name": "jp_manual_search_ai_agent",
        "origin": "CUSTOMER",
        "status": "ACTIVE",
        "type": "MANUAL_SEARCH",
        "visibilityStatus": "PUBLISHED"
    },
    "versionNumber": 1
}
update-assistant-ai-agent の結果
$ aws qconnect update-assistant-ai-agent \
--assistant-id 16e02991-ed51-4a02-87ab-c362a1b92409 \
--ai-agent-type MANUAL_SEARCH \
--configuration '{
"aiAgentId": "73515101-73f6-4f5f-a342-fae8605f3687:1"
}'

{
    "assistant": {
        "aiAgentConfiguration": {
            "ANSWER_RECOMMENDATION": {
                "aiAgentId": "3025a3fa-5419-4c9c-a040-877213b93f70:4"
            },
            "MANUAL_SEARCH": {
                "aiAgentId": "73515101-73f6-4f5f-a342-fae8605f3687:1"
            },
            "SELF_SERVICE": {
                "aiAgentId": "529207fe-80fd-42be-bcf2-facd2141aec7:1"
            }
        },
        "assistantArn": "arn:aws:wisdom:us-east-1:012345678901:assistant/16e02991-ed51-4a02-87ab-c362a1b92409",
        "assistantId": "16e02991-ed51-4a02-87ab-c362a1b92409",
        "capabilityConfiguration": {
            "type": "V2"
        },
        "integrationConfiguration": {
            "topicIntegrationArn": "arn:aws:sns:us-east-1:012345678901:wisdom-d7257000-940b-418c-a7be-be0bbbb74bd4"
        },
        "name": "test",
        "status": "ACTIVE",
        "tags": {
            "AmazonConnectEnabled": "True"
        },
        "type": "AGENT"
    }
}

動作確認

ロケール設定変更後、再度チャット欄で日本語で質問してみます。

日本語の資料の内容で回答を得ることができました。
なお、英語で質問しても日本語の資料の内容で回答が返ってきたので、プロンプトを変更することで英語の場合は英語の内容で回答を得ることができました。

まとめ

今回は S3 をナレッジベースにした Amazon Q in Connect を日本語で使用してみました。
どなたかの参考になれば幸いです。

参考資料

Discussion