Google 検索によるグラウンディング

Google 検索によるグラウンディングは、Gemini モデルをリアルタイムのウェブ コンテンツに接続し、利用可能なすべての言語で動作します。これにより、Gemini はより正確な回答を提供し、ナレッジ カットオフを超えて検証可能なソースを引用できます。

グラウンディングは、次のことができるアプリケーションの構築に役立ちます。

  • 事実の正確性を高める: 実世界の情報を基に回答することで、モデルのハルシネーションを減らします。
  • リアルタイムの情報にアクセスする: 最近の出来事やトピックに関する質問に回答します。
  • 引用を提供する: モデルの主張のソースを示すことで、ユーザーの信頼を築きます。

Python

from google import genai

client = genai.Client()

interaction = client.interactions.create(
    model="gemini-3-flash-preview",
    input="Who won the euro 2024?",
    tools=[{"type": "google_search"}]
)

# Print the model's text response
for step in interaction.steps:
    if step.type == "model_output":
        for content_block in step.content:
            if content_block.type == "text":
                print(content_block.text)

JavaScript

import { GoogleGenAI } from "@google/genai";

const client = new GoogleGenAI({});

const interaction = await client.interactions.create({
    model: "gemini-3-flash-preview",
    input: "Who won the euro 2024?",
    tools: [{ type: "google_search" }]
});

const modelStep = interaction.steps.find(s => s.type === 'model_output');
if (modelStep) {
  for (const contentBlock of modelStep.content) {
    if (contentBlock.type === 'text') console.log(contentBlock.text);
  }
}

REST

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gemini-3-flash-preview",
    "input": "Who won the euro 2024?",
    "tools": [{"type": "google_search"}]
  }'

Google 検索によるグラウンディングの仕組み

google_search ツールを有効にすると、モデルは情報の検索、処理、引用のワークフロー全体を自動的に処理します。

grounding-overview

  1. ユーザー プロンプト: アプリケーションは、google_search ツールが有効になっている Gemini API にユーザーのプロンプトを送信します。
  2. プロンプトの分析: モデルはプロンプトを分析し、Google 検索で回答を改善できるかどうかを判断します。
  3. Google 検索: 必要に応じて、モデルは 1 つ以上の検索クエリを自動的に生成して実行します。
  4. 検索結果の処理: モデルは検索結果を処理し、情報を合成してレスポンスを作成します。
  5. グラウンディングされたレスポンス: API は、検索結果に基づいてグラウンディングされた、最終的なユーザーフレンドリーなレスポンスを返します。このレスポンスには、引用を含むインライン annotations を含むモデルのテキスト回答と、検索クエリと検索候補を含む google_search_call ステップと google_search_result ステップが含まれます。

グラウンディング レスポンスについて

レスポンスが正常にグラウンディングされると、モデルのテキスト出力には、テキスト コンテンツ ブロックに直接インライン annotations が含まれます。これらのアノテーションは、レスポンスの一部をソースにリンクする引用情報を提供します。

{
  "steps": [
    {
      "type": "thought",
      "summary": [
        {
          "type": "text",
          "text": "The user is asking for the winner of Euro 2024. I need to search for the result of the Euro 2024 final."
        }
      ],
      "signature": "CoMDAXLI2nynRYojJIy6B1Jh9os2crpWLfB0..."
    },
    {
      "type": "google_search_call",
      "arguments": {
        "queries": ["UEFA Euro 2024 winner"]
      }
    },
    {
      "type": "google_search_result",
      "call_id": "search_001",
      "result": [
        {
          "search_suggestions": "<!-- HTML and CSS for the search widget -->"
        }
      ]
    },
    {
      "type": "model_output",
      "content": [
        {
          "type": "text",
          "text": "Spain won Euro 2024, defeating England 2-1 in the final. This victory marks Spain's record fourth European Championship title.",
          "annotations": [
            {
              "type": "url_citation",
              "url": "https://www.aljazeera.com/sports/euro-2024-final",
              "title": "aljazeera.com",
              "start_index": 0,
              "end_index": 56
            },
            {
              "type": "url_citation",
              "url": "https://www.uefa.com/euro2024/news/spain-wins-euro-2024",
              "title": "uefa.com",
              "start_index": 57,
              "end_index": 124
            }
          ]
        }
      ]
    }
  ]
}

レスポンスのキーフィールド:

  • google_search_call : モデルが実行した検索 queries が含まれます。
  • google_search_result : UI で検索候補をレンダリングするための HTML スニペットである search_suggestions が含まれます。完全な使用要件については、 利用規約をご覧ください。
  • annotations を含む text : インライン引用を含むモデルの合成された回答。各 url_citation アノテーションは、テキスト セグメント(start_indexend_index で定義)をソース URL にリンクします。これは、インライン引用を作成するための鍵となります。

Google 検索によるグラウンディングは、URL コンテキスト ツールと組み合わせて使用して、レスポンスを 公開ウェブデータと指定した特定の URL の両方でグラウンディングすることもできます。

インライン引用でソースを帰属させる

API は、テキスト コンテンツ ブロックにインライン url_citation アノテーションを返します。これにより、ユーザー インターフェースでのソースの表示方法を完全に制御できます。 各アノテーションには、引用するテキストの部分を識別するための start_indexend_index が含まれています。抽出して表示する方法は次のとおりです。

Python

for step in interaction.steps:
    if step.type == "model_output":
        for content_block in step.content:
            if content_block.type == "text":
                print(content_block.text)
                if content_block.annotations:
                    print("\nCitations:")
                    for annotation in content_block.annotations:
                        if annotation.type == "url_citation":
                            cited_text = content_block.text[annotation.start_index:annotation.end_index]
                            print(f"  [{annotation.title}]({annotation.url})")
                            print(f"    Cited text: \"{cited_text}\"")

JavaScript

for (const step of interaction.steps) {
  if (step.type === 'model_output') {
    for (const contentBlock of step.content) {
      if (contentBlock.type === 'text') {
        console.log(contentBlock.text);
        if (contentBlock.annotations) {
          console.log("\nCitations:");
          for (const annotation of contentBlock.annotations) {
            if (annotation.type === 'url_citation') {
              const citedText = contentBlock.text.slice(annotation.startIndex, annotation.endIndex);
              console.log(`  [${annotation.title}](${annotation.url})`);
              console.log(`    Cited text: "${citedText}"`);
            }
          }
        }
      }
    }
  }
}

出力には、テキストとその引用が表示されます。

Spain won Euro 2024, defeating England 2-1 in the final. This victory marks Spain's record fourth European Championship title.

Citations:
  [aljazeera.com](https://www.aljazeera.com/sports/euro-2024-final)
    Cited text: "Spain won Euro 2024, defeating England 2-1 in the final."
  [uefa.com](https://www.uefa.com/euro2024/news/spain-wins-euro-2024)
    Cited text: "This victory marks Spain's record fourth European Championship title."

料金

Gemini 3 で Google 検索によるグラウンディングを使用する場合、モデルが実行すると判断した検索クエリごとにプロジェクトに課金されます。モデルが 1 つのプロンプトに回答するために 複数の検索クエリを実行すると判断した場合(たとえば、 同じ API 呼び出し内で "UEFA Euro 2024 winner""Spain vs England Euro 2024 final score" を検索する場合)、そのリクエストに対してツールの有料使用が 2 回とカウントされます。課金目的で、一意のクエリをカウントする際に空のウェブ検索クエリは無視されます。この課金モデルは Gemini 3 モデルにのみ適用されます。Gemini 2.5 以前のモデルで検索グラウンディングを使用する場合、プロジェクトにはプロンプトごとに課金されます。

料金の詳細については、Gemini API の料金 ページをご覧ください。

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

完全な機能については、モデル 概要ページをご覧ください。

モデル Google 検索によるグラウンディング
Gemini 3.1 Flash Image プレビュー ✔️
Gemini 3.1 Pro プレビュー ✔️
Gemini 3 Pro Image プレビュー ✔️
Gemini 3 Flash プレビュー ✔️
Gemini 2.5 Pro ✔️
Gemini 2.5 Flash ✔️
Gemini 2.5 Flash-Lite ✔️
Gemini 2.0 Flash ✔️

サポートされているツールの組み合わせ

Google 検索によるグラウンディングは、コード実行や URL コンテキストなどの他のツールと組み合わせて使用して、より複雑なユースケースに対応できます。

Gemini 3 モデルでは、組み込みツール(Google 検索によるグラウンディングなど)とカスタムツール(関数呼び出し)を組み合わせることができます。詳細については、 ツールの組み合わせのページをご覧ください。

次のステップ