Grounding API

グラウンディングにより、モデルの出力を信頼できる情報源に関連付けることができます。グラウンディングにより、モデルの出力が特定のデータにリンクされるため、ハルシネーションを最小限に抑えることができます。Google 検索を使用して、一般公開されているウェブデータでグラウンディングを行うことができます。また、Vertex AI Search から取得した独自のデータをデータストアとして利用することもできます。

サポートされているモデル:

  • Gemini 1.0 Pro
    • gemini-1.0-pro-001
    • gemini-1.0-pro-002

制限

  • 英語のデータに対応しています。
  • グラウンディングはテキスト レスポンスに対してのみ使用できます。

パラメータ リスト

グラウンディングを有効にするには、リクエストで取得 tool を指定します。オプションは次のとおりです。

  • GoogleSearchRetrieval: 公開ウェブデータを使用してグラウンディングします。
  • Retrieval: Vertex AI Search を使用してプライベート データソースに接続します。

GoogleSearchRetrieval

レスポンスを一般公開データでグラウンディングします。リクエストに google_search_retrieval ツールを含めます。追加のパラメータは必要ありません。

Retrieval

Vertex AI Search を介してプライベート データでグラウンディングします。モデルが外部情報にアクセスするために呼び出せる検索ツールを定義します。

パラメータ

source

VertexAISearch

Vertex AI Search で使用されるデータソースを使用するように設定します。

VertexAISearch

グラウンディングのために Vertex AI Search データストアから取得します。詳細については、Vertex AI Agent Builder をご覧ください。

パラメータ

datastore

string

Vertex AI Search の完全修飾データストア リソース ID。projects/<>/locations/<>/collections/<>/dataStores/<>

  • PROJECT_ID = PROJECT_ID
  • REGION = us-central1
  • MODEL_ID = gemini-1.0-pro

一般公開のウェブデータでレスポンスをグラウンディングする

curl

curl -X POST \
  -H "Authorization: Bearer $(gcloud auth print-access-token)" \
  -H "Content-Type: application/json" \
  http://${REGION}-aiplatform.googleapis.com/v1/projects/${PROJECT_ID}/locations/${REGION}/publishers/google/models/${MODEL_ID}:generateContent \
  -d '{
    "contents": [{
      "role": "user",
      "parts": [{
        "text": "What did Lincoln do for fun?"
      }]
    }],
    "tools": [{
      "googleSearchRetrieval": {}
    }]
  }'

Python

import vertexai
from vertexai.generative_models import GenerativeModel, Tool
from vertexai.preview import generative_models as preview_generative_models

vertexai.init(project=PROJECT_ID, location=REGION)

gemini_model = GenerativeModel(MODEL_ID)
google_search_tool = Tool.from_google_search_retrieval(
    google_search_retrieval=preview_generative_models.grounding.GoogleSearchRetrieval()
)

model_response = gemini_model.generate_content(
    "What did Lincoln do for fun?", tools=[google_search_tool]
)

print(model_response)

Vertex AI Search を使用してプライベート データでレスポンスをグラウンディングする

前提条件: まず、検索データストアを作成する必要があります。

この例で使用するデータストア リソース パスを DATASTORE 変数に設定します。

curl

curl -X POST \
  -H "Authorization: Bearer $(gcloud auth print-access-token)" \
  -H "Content-Type: application/json" \
  http://${REGION}-aiplatform.googleapis.com/v1/projects/${PROJECT_ID}/locations/${REGION}/publishers/google/models/${MODEL_ID}:generateContent \
  -d '{
    "contents": [{
      "role": "user",
      "parts": [{
        "text": "How to make appointment to renew driving license?"
      }]
    }],
    "tools": [{
      "retrieval": {
        "vertexAiSearch": {
          "datastore": "'${DATASTORE}'"
        }
      }
    }]
  }'

Python

import vertexai
from vertexai.generative_models import GenerativeModel, Tool
from vertexai.preview import generative_models as preview_generative_models

vertexai.init(project=PROJECT_ID, location=REGION)

gemini_model = GenerativeModel(MODEL_ID)
vertex_search_tool = Tool.from_retrieval(
    retrieval=preview_generative_models.grounding.Retrieval(
        source=preview_generative_models.grounding.VertexAISearch(datastore=DATASTORE),
    )
)

model_response = gemini_model.generate_content(
    "How to make appointment to renew driving license?", tools=[vertex_search_tool]
)

print(model_response)

さらに詳しい情報

詳細なドキュメントについては、以下をご覧ください。