14
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Bedrockの新評価機能 RAG評価(プレビュー) でRAGを評価してみた

Last updated at Posted at 2024-12-09

ジャーニーマン( @beajourneyman )です。長いの"ジャニ"と呼ばれています。

この記事は セゾンテクノロジー Advent Calendar 2024 シーズン1、9日目の記事です。

今回は AWS re:Invent 2024で発表された新機能を試します。Amazon Bedrock Knowledge Bases の評価機能がプレビューでリリースされ、AWSの統合された環境でRAGモデルの評価が可能になりました。

AWS News Blog

AWS Whats New

さっそく、先日作成したRAGを評価します。尚、ブラウザの機械翻訳を適用して日本語表示にして画面キャプチャを取得しております。

ナレッジベース評価基盤構築と評価結果確認の流れ

  • S3バケットを用意する
  • 評価用JSONLデータセットを用意してS3にアップロードする
  • 評価基盤を構築する
  • 評価結果を確認する

具体的には、冒頭の公式ブログを参考に RAG評価(プレビュー) を試してみた内容になります。

S3バケットを用意する

評価用の JSONL データセット、評価結果格納用にS3バケットを用意します。タグはお使いのアカウントのルールに則って必要に応じて設定してください。

image.png

評価用JSONLデータセットを用意してS3にアップロードする

Bedrock にサポートしてもらいながら、評価用の JSONL を準備します。冒頭セクションのAWSブログ内に詳細なフォーマットのサンプルがあります(以下画像箇所)。

image.png

RAGで Amazon Connect に関する記事を中心に書いている Qiita ブログを学習させてあるので、評価用の JSONL の内容は、Amazon Connect に関する知識のお手本データセットにしています。実際に投入した JSONL です(10行)。

{"conversationTurns":[{"referenceResponses":[{"content":[{"text":"Amazon Connect is a cloud-based contact center solution that allows businesses to create and manage customer interactions."}]}],"prompt":{"content":[{"text":"What is Amazon Connect?"}]}}]}
{"conversationTurns":[{"referenceResponses":[{"content":[{"text":"The main components of Amazon Connect include contact flows, agent workspace, flow designer, and real-time metrics."}]}],"prompt":{"content":[{"text":"What are the main components of Amazon Connect?"}]}}]}
{"conversationTurns":[{"referenceResponses":[{"content":[{"text":"A contact flow is a visual representation of the customer interaction process, defining the steps and actions taken during a customer call or chat."}]}],"prompt":{"content":[{"text":"What is a contact flow in Amazon Connect?"}]}}]}
{"conversationTurns":[{"referenceResponses":[{"content":[{"text":"The agent workspace is the interface that agents use to interact with customers, manage calls, and access customer information."}]}],"prompt":{"content":[{"text":"What is the agent workspace in Amazon Connect?"}]}}]}
{"conversationTurns":[{"referenceResponses":[{"content":[{"text":"The flow designer is a tool used to create and modify contact flows, allowing administrators to define the customer interaction process."}]}],"prompt":{"content":[{"text":"What is the flow designer in Amazon Connect?"}]}}]}
{"conversationTurns":[{"referenceResponses":[{"content":[{"text":"Real-time metrics provide insights into call and chat performance, enabling administrators to monitor and optimize contact center operations."}]}],"prompt":{"content":[{"text":"What are real-time metrics in Amazon Connect?"}]}}]}
{"conversationTurns":[{"referenceResponses":[{"content":[{"text":"Amazon Connect can integrate with various AWS services such as S3, DynamoDB, Lambda, and more, to enhance its functionality and data storage capabilities."}]}],"prompt":{"content":[{"text":"How can Amazon Connect integrate with other AWS services?"}]}}]}
{"conversationTurns":[{"referenceResponses":[{"content":[{"text":"Integrating Amazon Connect with a CRM system allows for seamless customer data management, providing agents with a complete view of customer interactions and history."}]}],"prompt":{"content":[{"text":"What is the purpose of using Amazon Connect with a CRM system?"}]}}]}
{"conversationTurns":[{"referenceResponses":[{"content":[{"text":"Amazon Connect enables businesses to provide consistent and efficient customer support across multiple channels, such as voice, chat, and email."}]}],"prompt":{"content":[{"text":"What is the benefit of using Amazon Connect for omnichannel customer support?"}]}}]}
{"conversationTurns":[{"referenceResponses":[{"content":[{"text":"By offering features such as IVR, call routing, and real-time analytics, Amazon Connect helps businesses deliver faster and more personalized customer support, enhancing overall customer experience."}]}],"prompt":{"content":[{"text":"How can Amazon Connect improve customer experience?"}]}}]}

S3バケットに評価データセットをアップロードしておきます。フォーマットにエラーがある場合は、次セクションの「評価基盤を構築する」際にエラーではじかれます。

image.png

結果を格納するフォルダを準備します(S3バケットそのものは、評価結果書き出し先のオブジェクトとして指定できないため)。

image.png

S3バケットの「アクセス許可」を開き、以下のドキュメント巻末に記載されている最低限のCORS設定を入れておきます。右の「編集」ボタンを押して、入力エリアにドキュメントの設定をコピペします。右下の「変更の保存」をします。

image.png

image.png

評価基盤を構築する

左ペインの「推論と評価」「評価」をクリックします。表示されたら「ナレッジベース」タブに切り替えます。真ん中の仕組み・自動のパートの白い「創造する」ボタンを押します。

image.png

任意の「評価名」を入れて、モデルに「Claude 3 haiku」を選択します。タグはお使いのアカウントのルールに則って必要に応じて設定してください。ブラウザの日本語翻訳で"haiku"が"俳句"になるのが味わい深いです。

image.png

作成済みの「ナレッジベース」をプルダウンから選択します。ナレッジベースの評価タイプは「検索と応答の生成」を選択し、モデルに「Claude 3 haiku」を選択します。メトリクスを全てチェックします。

image.png

image.png

「S3を参照」をクリックして先ほど準備したS3バケットのデータセットとフォルダを指定します。

image.png

image.png

KMSはデフォルト、サービスのアクセスは新しいサービスロールを作成して使用します。

image.png

image.png

作成されると既存のサービスロールが選択され、サービスロール名が自動設定されます。

image.png

準備ができたので「作成」ボタンを押します。こちらにはしばらく時間がかかります。

image.png

30分近くかかったでしょうか? 数十本のブログ記事をベースにしたRAGに対して10行の評価用データセットでしたが、それなりに時間がかかりました。本番運用では、バッチ実行が向いている気がしました。完了したので、評価結果を見てみます。

image.png

評価結果を確認する

こうやって確認できると非常にインパクトがあります。まずは「メトリックの概要」です。概ねひどい評価ではなさそうなので、ホッとしました。

image.png

続いて「生成メトリックの内訳」です。左の「メトリック」から各指標のグラフにジャンプできます。5つの「品質指標」、3つの「責任あるAIメトリクス」一気にご紹介します。

image.png

5つの品質指標

image.png

image.png

image.png

image.png

image.png

3つの責任あるAIメトリクス

image.png

image.png

image.png

会話の例

会話の例を開くと、評価データセットのお手本との評価結果が確認できます。

image.png

右上の青い最大化ボタンを押すと、拡大して確認できます。

image.png

まとめ

マネージドコンソールだけで一貫して評価まで行えるのは非常に効率的だと感じました。現在はプレビューですが、一般提供開始されると利用が拡大しそうです。

実際に作ってみて感じましたが、評価用JSONLデータセットを作るのはなかなか骨が折れました。Bedrockに伴走してもらいながら準備していましたが、最初は異なるフォーマットを準備しており、エラーの解消に時間がかかりました。与える情報の精査や書き方など、プロンプトエンジニアリングはなかなか難しいです。

以上です。

14
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?