LoginSignup
14
3

ビジュアルデータを含む資料を使ったマルチモーダルRAGをさくっと試す

Last updated at Posted at 2023-12-10

本記事は「KDDIアジャイル開発センター(KAG) Advent Calendar 2023」、11日目の記事です。

はじめに

こんにちは、KDDIアジャイル開発センターのはしもと(仮名)です。
LLM大好き!LLM大好き!

LLMのマルチモーダル対応

LLMの開発競争は凄まじく、流暢に多言語を話したかと思えば、最近では画像や動画、音声などの入力に対応した マルチモーダルモデル が続々と発表されています。

トップランナーOpenAIの「GPT-4 Vision」だけでなく、最近ではGoogleが「Gemini」を発表し、その高い性能と汎用性にワクワクした記憶も新しいです。
(内容についてはSNSなどでも色々語られていますが、一個人としては純粋にその将来性に期待したいと感じました)

マルチモーダルRAG

LLM の代表的なユースケースのひとつにチャットボットがあります。
更にその高度化で、モデルが内部で保有していない情報に対しても回答を生成できるように外部から情報を与えてあげる、通称 RAG という技術が用いられます。

この記事では、マルチモーダルLLMを使用してRAG構成を組み、任意のPDFドキュメント内に含まれる画像情報に関する受け答えを行ってみたのでそれについて記載します。

検証方法について

言語モデルやライブラリの組み合わせによって複数の検証方法が考えられますが、今回は LangChain がXでポストしているテンプレートを使用して検証します。

使用する LangChain Templates

LLMへの入力(プロンプト)の一部を変数化し再利用性を持たせる機能「プロンプトテンプレート」とは異なるものなのでご注意ください。

言語モデルなど

元のドキュメントを検索可能な形式に変換・保存しておくためのEmbeddingsモデルやデータベース、実際にユーザーとのやり取りを行うLLMは以下を利用します。

ベクトルデータベース Embeddings モデル 回答生成用 LLM
Chroma ViT-H-14 GPT-4V

今回のようにビジュアルデータを使用したRAGを行う場合は、これら3要素がマルチモーダル対応である必要があります。

対象ドキュメント

テンプレートのデフォルトで指定されているDatadog社の資料を利用します。(リポジトリ/docs内に含まれています)

本来であれば英語ではなく日本語の資料で試したかったのですが、日本語でのマルチモーダル対応の Embeddings モデルを見つけることができず、別の機会に検証したいと思います。

検証

対象リポジトリをcloneし、手順に沿って進めます。

環境準備

ベクトルストアへのインデックス作成

git clone https://github.com/langchain-ai/langchain.git
cd langchain/templates/rag-chroma-multi-modal

poetry install
python ingest.py

ここまでの手順で、以下を実施しています。

  • 必要なライブラリが揃ったPython実行環境構築
  • /docs内のPDFドキュメントをページごとに分割 (jpg形式)
  • 画像化した各ページのEmbedding結果をchroma_db_multi_modal配下にエクスポート

LangChain CLI のインストール

アプリケーション実行時、LangChain CLI を使用します。
以下のコマンドでインストールをします。

pip install -U langchain-cli

OpenAI API キーの設定

OpenAI のモデルを呼び出すために必要な認証情報を設定します。
ターミナルで以下のコマンドを実行します。

export OPENAI_API_KEY=<自分のAPIキー>

実行ファイルの作成

server.pyを作成し、以下のコードを記述します。

from rag_chroma_multi_modal import chain as rag_chroma_multi_modal_chain

add_routes(app, rag_chroma_multi_modal_chain, path="/rag-chroma-multi-modal")

これで準備は完了です。アプリケーションを実行しましょう。

アプリケーションの起動

以下のコマンドを実行すると、FastAPI を使ったアプリケーションが http://localhost:8000/ で起動します。

langchain serve

ブラウザを開き、http://localhost:8000/playground/にアクセスすると、

image.png

起動できました!!!!!!

質問してみる

PDFに記載された内容について質問してみます。
マルチモーダルRAGということなので、テキスト部分と画像部分それぞれについて確認します。

テキスト部分

以下のページの情報について尋ねてみます。
Datadogが提供する各機能が、どのドメインに属しているかが一覧で書かれています。

image.png

「Security」にはどんなものが含まれるか聞いてみます。

Q. What features does the Datadog platform offer in the area of security domain?

A. 
The Datadog platform offers several features in the area of security, as indicated in the first image. These features include:

1. Cloud Security Management
2. Application Security Management
3. Cloud SIEM (Security Information and Event Management)
4. Application Vulnerability Management

These features are designed to enhance security monitoring and management within the infrastructure that Datadog is monitoring.

ばっちりですね。スライドで構造的に整理されている部分も正しく理解できています。

逆に、他のドメインに該当する機能についても聞いてみます。

Q. Does Datadog provide *CI Visibility* in the security area?

A.
No, according to the information provided in the first image, *CI Visibility* is listed under the "Developer Experience" area, not under the "Security" area.
The "Security" area includes features like Cloud Security Management, Application Security Management, Cloud SIEM, and Application Vulnerability Management.

素敵やん

画像部分

次はテキストではなく、グラフなどビジュアルデータの内容について質問します。

このページから、TAMの推移を答えてもらいましょう。
image.png

TAMとは、Total Addressable Marketの頭文字を取った略称であり、日本語で「ある事業が獲得できる可能性のある全体の市場規模」を意味する言葉だそうです。

Q. Explain Datadog's TAM trends.

A.
The first image provided shows a bar graph representing Datadog's Total Addressable Market (TAM) trends over a period from 2022 to 2026.
The graph indicates a consistent growth in the TAM for Datadog's observability products.
Here are the key points from the graph:

- In 2022, the TAM is valued at $41 billion.
- There is a projected increase to $45 billion in 2023.
- The TAM is expected to grow to $51 billion in 2024.
- A further increase to $56 billion is anticipated in 2025.
- By 2026, the TAM is forecasted to reach $62 billion.

This trend suggests that Datadog's market opportunity is expanding significantly over the five-year period, indicating a positive outlook for the company's growth potential in the observability space.
The title "Long-term growth drivers are still in early stages" implies that the market is still developing, and there is a substantial opportunity for growth in the future.

The first image provided shows a bar graph representing Datadog's Total Addressable Market (TAM) trends over a period from 2022 to 2026.とあるように、時系列のデータが含まれていることを理解しています。
数値に関しても資料の内容どおりでいい感じです!!!!

この特徴的な図についてはどうでしょう。
「Datadogの一番の競合はどこだと思うか、根拠もよろ!」と聞いてみます。

image.png

Q.
Regarding the Forrester Wave report, indicate which company is Datadog's biggest competitor in the IT operations field, along with its rationale.

A.
Based on the Forrester Wave report depicted in the first image, Datadog's biggest competitor in the IT operations field appears to be Dynatrace. 
This is inferred from the positioning of the companies on the graph, where both Datadog and Dynatrace are placed in the "Leaders" quadrant, with Dynatrace being the closest to Datadog in terms of both axes, which represent the strength of the current offering and the strength of strategy.
The proximity of Dynatrace to Datadog on this graph suggests that it is the most significant competitor among the companies evaluated in the report.

both Datadog and Dynatrace are placed in the "Leaders" quadrantとあり、DatadogとDynatraceがこの評価において同じグルーピングということを根拠に答えてくれました。

素敵やん。

まとめ

マルチモーダル対応のモデルを使用して、ビジュアルデータに対する質問についてもRAGを適用し、LLM経由で適切な回答を得ることができました。

みんな大好きエンタープライズサーチで検索したい社内文書には、パワーポイントやPDFファイルなどの図やグラフを多く含んでおり、純粋なテキストファイルしかないというケースは稀なのではないでしょうか。

LLMの進化にともない適用分野・ユースケースもどんどん拡大していきます。
生成AIでなんかさせたい偉いやつ(通称:SNE)の理不尽な依頼でも華麗にさばける、ナウでヤングなエンジニアに私はなりたいです。

はしもと(仮名)でした。

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