グラウンディング

生成 AI において、グラウンディングとは、モデルの出力を検証可能な情報源に紐付ける仕組みを指します。特定のデータソースにアクセスできるモデルを用意することで、グラウンディングによりその出力が特定のデータに紐づけされ、コンテンツのねつ造が起こりにくくなります。

Vertex AI では、次の方法でモデル出力をグラウンディングできます。

  • Google 検索でグラウンディングする - 一般公開されているウェブデータでモデルをグラウンディングします。
  • 独自のデータにグラウンディングする - Vertex AI Search の独自のデータをデータストアとしてモデルをグラウンディングします。

グラウンディングの詳細については、グラウンディングの概要をご覧ください。

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

パラメータ リスト

実装の詳細については、をご覧ください。

GoogleSearchRetrieval

レスポンスを一般公開データでグラウンディングします。

パラメータ

google_search_retrieval

必須: Object

一般公開されているウェブデータでグラウンディングします。

Retrieval

Vertex AI Search の限定公開データをデータストアとして使用してレスポンスをグラウンディングします。モデルが外部情報にアクセスするために呼び出せる検索ツールを定義します。

パラメータ

source

必須: VertexAISearch

Vertex AI Search のデータソースでグラウンディングします。

VertexAISearch

パラメータ

datastore

必須: string

Vertex AI Search の完全修飾データストア リソース ID(形式: projects/{project}/locations/{location}/collections/default_collection/dataStores/{datastore}

Google 検索を使用して一般公開のウェブデータでレスポンスをグラウンディングする

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

Python

インストール

pip install --upgrade google-genai

詳しくは、SDK リファレンス ドキュメントをご覧ください。

Vertex AI で Gen AI SDK を使用するための環境変数を設定します。

# Replace the `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION` values
# with appropriate values for your project.
export GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT
export GOOGLE_CLOUD_LOCATION=global
export GOOGLE_GENAI_USE_VERTEXAI=True

from google import genai
from google.genai.types import (
    GenerateContentConfig,
    GoogleSearch,
    HttpOptions,
    Tool,
)

client = genai.Client(http_options=HttpOptions(api_version="v1"))

response = client.models.generate_content(
    model="gemini-2.5-flash",
    contents="When is the next total solar eclipse in the United States?",
    config=GenerateContentConfig(
        tools=[
            # Use Google Search Tool
            Tool(google_search=GoogleSearch())
        ],
    ),
)

print(response.text)
# Example response:
# 'The next total solar eclipse in the United States will occur on ...'

Go

Go をインストールまたは更新する方法について学びます。

詳しくは、SDK リファレンス ドキュメントをご覧ください。

Vertex AI で Gen AI SDK を使用するための環境変数を設定します。

# Replace the `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION` values
# with appropriate values for your project.
export GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT
export GOOGLE_CLOUD_LOCATION=global
export GOOGLE_GENAI_USE_VERTEXAI=True

import (
	"context"
	"fmt"
	"io"

	genai "google.golang.org/genai"
)

// generateWithGoogleSearch shows how to generate text using Google Search.
func generateWithGoogleSearch(w io.Writer) error {
	ctx := context.Background()

	client, err := genai.NewClient(ctx, &genai.ClientConfig{
		HTTPOptions: genai.HTTPOptions{APIVersion: "v1"},
	})
	if err != nil {
		return fmt.Errorf("failed to create genai client: %w", err)
	}

	modelName := "gemini-2.5-flash"
	contents := []*genai.Content{
		{Parts: []*genai.Part{
			{Text: "When is the next total solar eclipse in the United States?"},
		},
			Role: "user"},
	}
	config := &genai.GenerateContentConfig{
		Tools: []*genai.Tool{
			{GoogleSearch: &genai.GoogleSearch{}},
		},
	}

	resp, err := client.Models.GenerateContent(ctx, modelName, contents, config)
	if err != nil {
		return fmt.Errorf("failed to generate content: %w", err)
	}

	respText := resp.Text()

	fmt.Fprintln(w, respText)

	// Example response:
	// The next total solar eclipse in the United States will occur on March 30, 2033, but it will only ...

	return nil
}

Vertex AI Search を使用して限定公開データでレスポンスをグラウンディングする

Vertex AI Search データストアのデータを使用してレスポンスをグラウンディングします。詳細については、AI アプリケーションをご覧ください。

非公開データでレスポンスをグラウンディングする前に、データストア検索アプリを作成します。

警告: 現時点では、この「グラウンディング」インターフェースは Vertex AI Search の「チャンクモード」をサポートしていません。

Gen AI SDK for Python

from google import genai
from google.genai.types import (
    GenerateContentConfig,
    HttpOptions,
    Retrieval,
    Tool,
    VertexAISearch,
)

client = genai.Client(http_options=HttpOptions(api_version="v1"))

# Load Data Store ID from Vertex AI Search
# datastore = "projects/111111111111/locations/global/collections/default_collection/dataStores/data-store-id"

response = client.models.generate_content(
    model="gemini-2.5-flash",
    contents="How do I make an appointment to renew my driver's license?",
    config=GenerateContentConfig(
        tools=[
            # Use Vertex AI Search Tool
            Tool(
                retrieval=Retrieval(
                    vertex_ai_search=VertexAISearch(
                        datastore=datastore,
                    )
                )
            )
        ],
    ),
)

print(response.text)
# Example response:
# 'The process for making an appointment to renew your driver's license varies depending on your location. To provide you with the most accurate instructions...'

次のステップ

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