RAG 操作の設定

Retrieval-Augmented Generation (RAG) とは、関連コンテンツを取得し、そのコンテンツを使用して追加のコンテキストで AI プロンプトを増強することで、AI が生成した出力を拡張する技術です。この追加情報で LLM をグラウンディングすることで、より正確で信頼性の高い応答を提供できます。

RAG Load Document 操作の設定

RAG load document​ 操作では、メモリ内エンベディングストアからプレーンテキストプロンプトに基づいて情報を取得します。

RAG load document​ 操作を設定する手順は、次のとおりです。

  1. Anypoint Code Builder または Studio キャンバスで操作を選択します。

  2. 操作の ​[General (一般)]​ プロパティタブで、次の値を入力します。

    • Data

      LLM と応答先のエンベディングストアに送信するプロンプト。

    • Context Path (コンテキストパス)

      エンベディングストアに取り込むドキュメントの完全なファイルパスを含めます。ファイルパスにアクセスできることを確認します。

      この項目では DataWeave 式を使用することもできます。次に例を示します。

      mule.home ++ "/apps/" ++ app.name ++ "/customer-service.pdf"
      dataweave
  3. 操作の ​[Context (コンテキスト)]​ セクションで ​[File Type (ファイル種別)]​ を選択します。

    • text

      JSON、XML、TXT、CSV などのテキストファイル。

    • URL

      取り込む Web コンテンツを参照する単一 URL。

この操作の XML 設定を次に示します。

<ms-aichain:rag-load-document
  doc:name="RAG load document"
  doc:id="3d3edd66-4970-4dad-a5bf-2a8eae123da4"
  config-ref="MAC_AI_Llm_configuration"
  data="#[payload.prompt]"
  contextPath="#[payload.contextPath]"
/>
xml

出力設定

この操作の応答には、メイン LLM 応答を含む JSON ペイロードが含まれます。また、トークン利用状況などの属性がメインペイロード内ではなくメタデータ (属性) の一部として含まれます。

JSON ペイロードの応答例を次に示します。

{
  "response": "Wakanda, a technologically advanced and environmentally conscious nation in Africa, is renowned for its unique integration of ancient traditions with cutting-edge innovations, powered by the rare metal Vibranium. With a population of 12.5 million, it emphasizes sustainable growth, quality education, and healthcare, while maintaining a zero carbon footprint through advanced eco-tech solutions. Despite its peaceful nature, Wakanda's formidable military and cultural heritage, led by King T’Challa and the Dora Milaje, ensure its resilience and unity as a symbol of progress and tradition."
}
json

この操作では、メイン JSON ペイロード内に含まれない属性も返されます。これには、トークン利用状況に関する情報が含まれます。次に例を示します。

{
  "tokenUsage": {
      "outputCount": 9,
      "totalCount": 18,
      "inputCount": 9
  },
  "additionalAttributes": {}
}
json
  • tokenUsage

    属性として返されるトークン利用状況メタデータ

  • outputCount

    出力の生成で使用されたトークン数

  • totalCount

    入力と出力で使用されたトークンの合計数

  • inputCount

    入力の処理で使用されたトークン数