生成 AI において、グラウンディングとは、モデルの出力を検証可能な情報源に紐付ける仕組みを指します。特定のデータソースにアクセスできるモデルを用意することで、グラウンディングによりその出力が特定のデータに紐づけされ、コンテンツのねつ造が起こりにくくなります。
Vertex AI では、次の方法でモデル出力をグラウンディングできます。
- Google 検索でグラウンディングする - 一般公開されているウェブデータでモデルをグラウンディングします。
- 独自のデータにグラウンディングする - Vertex AI Search の独自のデータをデータストアとしてモデルをグラウンディングします(プレビュー版)。
グラウンディングの詳細については、グラウンディングの概要をご覧ください。
サポートされているモデル:
モデル | バージョン |
---|---|
Gemini 1.5 Pro(テキスト入力のみ) | gemini-1.5-pro-002 gemini-1.5-pro-001 |
Gemini 1.5 Flash(テキスト入力のみ) | gemini-1.5-flash-002 gemini-1.5-flash-001 |
Gemini 1.0 Pro(テキスト入力のみ) | gemini-1.0-pro-001 gemini-1.0-pro-002 |
制限事項
- グラウンディングは、英語、スペイン語、日本語のデータソースのみをサポートしています。
- グラウンディングはテキスト リクエストに対してのみ使用できます。
構文の例
モデルをグラウンディングする構文。
curl -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json" \ https://${LOCATION}-aiplatform.googleapis.com/v1/projects/${PROJECT_ID}/locations/${LOCATION}/publishers/google/models/${MODEL_ID}:generateContent \ -d '{ "contents": [{ ... }], "tools": [{ "retrieval": { "googleSearchRetrieval": {} } }], "model": "" }'
パラメータ リスト
実装の詳細については、例をご覧ください。
GoogleSearchRetrieval
レスポンスを一般公開データでグラウンディングします。
パラメータ | |
---|---|
|
必須: 一般公開されているウェブデータでグラウンディングします。 |
Retrieval
Vertex AI Search の限定公開データをデータストアとして使用してレスポンスをグラウンディングします。モデルが外部情報にアクセスするために呼び出せる検索ツールを定義します。
パラメータ | |
---|---|
|
必須: Vertex AI Search のデータソースでグラウンディングします。 |
VertexAISearch
パラメータ | |
---|---|
|
必須: Vertex AI Search の完全修飾データストア リソース ID(形式: |
例
Google 検索を使用して一般公開のウェブデータでレスポンスをグラウンディングする
レスポンスを Google 検索の一般公開データでグラウンディングします。リクエストに google_search_retrieval
ツールを含めます。追加のパラメータは必要ありません。
リクエストのデータを使用する前に、次のように置き換えます。
LOCATION : リクエストを処理するリージョン。PROJECT_ID : 実際のプロジェクト ID。MODEL_ID : マルチモーダル モデルのモデル ID。TEXT : プロンプトに含める指示のテキスト。DYNAMIC_THRESHOLD : 動的取得の構成を呼び出すしきい値を設定するオプション フィールド。[0,1] の範囲内の浮動小数点値です。dynamicThreshold
フィールドを設定しない場合は、しきい値はデフォルトで 0.7 になります。
HTTP メソッドと URL:
POST https://LOCATION -aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID /locations/LOCATION /publishers/google/models/MODEL_ID :generateContent
リクエストの本文(JSON):
{ "contents": [{ "role": "user", "parts": [{ "text": "TEXT " }] }], "tools": [{ "googleSearchRetrieval": { "dynamicRetrievalConfig": { "mode": "MODE_DYNAMIC", "dynamicThreshold":DYNAMIC_THRESHOLD } } }], "model": "projects/PROJECT_ID /locations/LOCATION /publishers/google/models/MODEL_ID " }
リクエストを送信するには、次のいずれかのオプションを開きます。
curl(Linux、macOS、Cloud Shell)
リクエスト本文を request.json
という名前のファイルに保存して、次のコマンドを実行します。
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://LOCATION -aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID /locations/LOCATION /publishers/google/models/MODEL_ID :generateContent"
PowerShell(Windows)
リクエスト本文を request.json
という名前のファイルに保存して、次のコマンドを実行します。
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://LOCATION -aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID /locations/LOCATION /publishers/google/models/MODEL_ID :generateContent" | Select-Object -Expand Content
次のような JSON レスポンスが返されます。
{ "candidates": [ { "content": { "role": "model", "parts": [ { "text": "Chicago weather changes rapidly, so layers let you adjust easily. Consider a base layer, a warm mid-layer (sweater-fleece), and a weatherproof outer layer." } ] }, "finishReason": "STOP", "safetyRatings":[ "..." ], "groundingMetadata": { "webSearchQueries": [ "What's the weather in Chicago this weekend?" ], "searchEntryPoint": { "renderedContent": "....................." } "groundingSupports": [ { "segment": { "startIndex": 0, "endIndex": 65, "text": "Chicago weather changes rapidly, so layers let you adjust easily." }, "groundingChunkIndices": [ 0 ], "confidenceScores": [ 0.99 ] }, ] "retrievalMetadata": { "webDynamicRetrievalScore": 0.96879 } } } ], "usageMetadata": { "..." } }
Vertex AI Search を使用して限定公開データでレスポンスをグラウンディングする
Vertex AI Search データストアのデータを使用してレスポンスをグラウンディングします。詳細については、Vertex AI Agent Builder をご覧ください。
非公開データでレスポンスをグラウンディンする前に、検索データストアを作成します。
リクエストのデータを使用する前に、次のように置き換えます。
LOCATION : リクエストを処理するリージョン。PROJECT_ID : 実際のプロジェクト ID。MODEL_ID : マルチモーダル モデルのモデル ID。TEXT : プロンプトに含める指示のテキスト。
HTTP メソッドと URL:
POST https://LOCATION -aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID /locations/LOCATION /publishers/google/models/MODEL_ID :generateContent
リクエストの本文(JSON):
{ "contents": [{ "role": "user", "parts": [{ "text": "TEXT " }] }], "tools": [{ "retrieval": { "vertexAiSearch": { "datastore": projects/PROJECT_ID /locations/global/collections/default_collection/dataStores/DATA_STORE_ID } } }], "model": "projects/PROJECT_ID /locations/LOCATION /publishers/google/models/MODEL_ID " }
リクエストを送信するには、次のいずれかのオプションを開きます。
curl(Linux、macOS、Cloud Shell)
リクエスト本文を request.json
という名前のファイルに保存して、次のコマンドを実行します。
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://LOCATION -aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID /locations/LOCATION /publishers/google/models/MODEL_ID :generateContent"
PowerShell(Windows)
リクエスト本文を request.json
という名前のファイルに保存して、次のコマンドを実行します。
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://LOCATION -aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID /locations/LOCATION /publishers/google/models/MODEL_ID :generateContent" | Select-Object -Expand Content
次のような JSON レスポンスが返されます。
{ "candidates": [ { "content": { "role": "model", "parts": [ { "text": "You can make an appointment on the website https://dmv.gov/" } ] }, "finishReason": "STOP", "safetyRatings": [ "..." ], "groundingMetadata": { "retrievalQueries": [ "How to make appointment to renew driving license?" ], "groundingChunks": [ { "retrievedContext": { "uri": "https://vertexaisearch.cloud.google.com/grounding-api-redirect/AXiHM.....QTN92V5ePQ==", "title": "dmv" } } ], "groundingSupport": [ { "segment": { "startIndex": 25, "endIndex": 147 }, "segment_text": "ipsum lorem ...", "supportChunkIndices": [1, 2], "confidenceScore": [0.9541752, 0.97726375] }, { "segment": { "startIndex": 294, "endIndex": 439 }, "segment_text": "ipsum lorem ...", "supportChunkIndices": [1], "confidenceScore": [0.9541752, 0.9325467] } ] } } ], "usageMetadata": { "..." } }
次のステップ
詳細なドキュメントについては、以下をご覧ください。