Vertex AI RAG Engine の検索と生成の出力

このページでは、Vertex AI RAG Engine の出力の各フィールドについて説明します。

retrieveContexts

このセクションでは、retrieveContexts API で定義されている各フィールドについて説明し、サンプルコードでフィールドを使用します。

フィールド

フィールド名 説明
source_uri RAG にインポートされる前の元のソースファイル。ファイルが Cloud Storage または Google ドライブからインポートされた場合、source_uri は Cloud Storage またはドライブの元のファイル URI です。ファイルがアップロードされている場合、source_uri はファイルの表示名です。
source_display_name ファイルの表示名。
text クエリに関連するテキスト チャンク。
score クエリとテキスト チャンクの類似性または距離。類似性または距離は、選択した vectorDB によって異なります。ragManagedDB の場合、スコアは COSINE_DISTANCE です。

出力例

このコードサンプルは、フィールドを使用してサンプル出力を生成する方法を示しています。

contexts {
    source_uri: "gs://sample_folder/hello_world.txt"
    source_display_name: "hello_world.txt"
    text: "Hello World!"
    score: 0.60545359030757784
  }

generateContent

generateContent API 用に定義されたフィールドのほとんどは、レスポンスの本文で確認できます。

フィールド

このセクションでは、generateContent API の grounding_metadata 部分で定義されている各フィールドについて説明し、サンプルコードでフィールドを使用します。

フィールド名 説明
text Gemini によって生成されたレスポンス。
grounding_chunks Vertex AI RAG Engine から返されるチャンク。
retrieved_context 生成されたコンテンツの基盤として使用されるチャンクを 0 個以上含めることができる繰り返しフィールド。
  • uri
  • source_uri には、データが元々保存されている場所を指定します。
  • title
  • source_display_name は、元のファイルのファイル名または表示名です。
  • text
  • テキスト チャンクは、Gemini の回答をグラウンディングするために使用されます。
grounding_supports 生成されたコンテンツとグラウンドング チャンクの関係。これは繰り返しフィールドです。各 grounding_supports フィールドは、生成されたコンテキストの 1 つのテキスト セグメントと、RAG によって取得された 1 つ以上のテキスト チャンクの間の関連を示します。
segment 生成されたテキストのグラウンドされたテキスト セグメント。
  • start_index
  • グラウンドされたテキストの最初のインデックス。start_index がない場合、start_index0 です。
  • end_index
  • グラウンドされたテキストの最後のインデックス。
  • text
  • グラウンドされたテキスト。
grounding_chunk_indices テキスト セグメントの接地に使用されるチャンク。テキストの基盤として使用されるチャンクは複数存在できます。インデックスは 0 から始まり、これは grounding_chunks フィールドの最初のチャンクを表します。地面はチャンク全体に存在します。レスポンスを接地するチャンクの部分が指定されていません。
confidence_scores 特定のチャンクにテキストを配置するために使用されるスコア。スコアの上限は 1 で、スコアが高いほど信頼度が高くなります。各スコアは各 grounding_chunk_indices と一致します。出力には、信頼スコアが 0.6 以上のチャンクのみが含まれます。

出力例

このコードサンプルは、フィールドを使用してサンプル出力を生成する方法を示しています。

candidates {
  content {
    role: "model"
    parts {
      text: "The rectangle is red and the background is white. The rectangle appears to be on some type of document editing software. \n"
    }
  }
  grounding_metadata {
    grounding_chunks {
      retrieved_context {
        uri: "a.txt"
        title: "a.txt"
        text: "Okay ,  I  see  a  red  rectangle  on  a  white  background .  It looks like it\'s on some sort of document editing software. It has those small squares and circles around it, indicating that it\'s a selected object ."
      }
    }
    grounding_chunks {
      retrieved_context {
        uri: "b.txt"
        title: "b.txt"
        text: "The  video  is  identical  to  the  last  time  I  described  it .  It shows a blue rectangle on a white background."
      }
    }
    grounding_chunks {
      retrieved_context {
        uri: "c.txt"
        title: "c.txt"
        text: "Okay ,  I  remember  the  rectangle  was  blue  in  the  past  session . Now it is red.\n The  red  rectangle  is  still  there .  It \' s  still  in  the same position on the white background, with the same handles around it. Nothing new is visible since last time.\n You \' re  welcome .  The  red  rectangle  is  still  the  only  thing visible."
      }
    }
    grounding_supports {
      segment {
        end_index: 49
        text: "The rectangle is red and the background is white."
      }
      grounding_chunk_indices: 2
      grounding_chunk_indices: 0
      confidence_scores: 0.958192229
      confidence_scores: 0.992316723
    }
    grounding_supports {
      segment {
        start_index: 50
        end_index: 120
        text: "The rectangle appears to be on some type of document editing software."
      }
      grounding_chunk_indices: 0
      confidence_scores: 0.98374176
    }
  }
}

次のステップ