Anthropic Claude モデルを使用したウェブ検索

ウェブ検索は、Claude モデルがウェブからのリアルタイム データで知識を補強できるようにする機能です。Claude モデルは、ウェブ検索機能にサードパーティの検索プロバイダを使用します。ウェブ検索機能は、ソースを正確に引用する必要がある RAG(検索拡張生成)アプリケーションで特に強力です。

ウェブ検索機能は、次のユースケースに適しています。

  • 最新の技術ドキュメントを取得する: ソフトウェア デベロッパーは、最新の API ドキュメントや技術仕様について Claude に質問できます。Claude は、ソース ドキュメントから情報を直接取得して合成できます。
  • ビジネスと市場の情報を収集する: ビジネス アナリストは、意思決定プロセスをサポートするために、現在の市場データ、会社情報、業界ニュースを収集できます。
  • 調査の支援: ナレッジ ワーカーは、複数のウェブソースから情報を検索、合成、説明し、正確な引用を維持できる調査アシスタントとして Claude を使用できます。
  • お客様をサポートする: カスタマー サービス アプリケーションは、会社のウェブサイトから最新の商品情報、価格、サポート ドキュメントにアクセスできます。

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

Vertex AI は、次の Anthropic Claude モデルのウェブ検索をサポートしています。

API リクエストで新しい Anthropic ツール定義(web_search)を指定し、ベータ版ヘッダー("anthropic-beta": "web-search-2025-03-05")を含むリクエストを送信することで、ウェブ検索を有効にします。

たとえば、次のコード スニペットは、ウェブ検索を使用してリアルタイムの天気情報を取得します。

response = await client.messages.create(
    model="claude-4-sonnet-latest",
    max_tokens=1024,
    messages=[{
        "role": "user",
        "content": "What is the weather in San Francisco?"
    }],
    tools=[{
        "type": "web_search_20250305",
        "name": "web_search",
        "max_uses": 5
    }]
)

オプションのフィールドを使用して、許可されるドメインとブロックされるドメインを指定することもできます。次に例を示します。

tools=[{
  ...
  # Only one of allowed_domains and blocked_domains can be provided.
  # allowed_domains excludes everything except the specified domains
    "allowed_domains": ["example.com", "example.org"],

  # blocked_domains includes everything except the specified domains
  # Use the `NOT site:` search operator
    "blocked_domains": ["example.net"],
}]

オプション フィールドの詳細については、Claude ウェブ検索ツールのドキュメントをご覧ください。

モデルがウェブ検索が必要であると判断すると、API はツール呼び出しが不要になるまでウェブ検索ツールを呼び出します。レスポンスには、中間検索の詳細が含まれます。結果は暗号化されています。

次のコード スニペットは、ウェブ検索を含むレスポンスの例です。

{
  ...
  "role": "assistant",
  "content": [
    // Initial output from the model
    {
      "type": "text",
      "text": "I need to search the web to answer this question about the weather in San Francisco."
    },
    {
      "type": "server_tool_use",
      "id": "srvtoolu_9a90a390a",
      "name": "web_search",
      "input": {
        "query": "What is the weather in San Francisco?",
      }
    },
    // API sees an `</antml:function_calls>` stop sequence here, sees that
    // the tool use is for a server-side tool, and then runs that
    // tool. If there is a mix of client and server-side, the API would
    // need to return to the client and let it pass back client tool results
    // before continuing with server tools.
    {
      "type": "web_search_tool_result",
      // "name": "web_search", use this to determine what types of blocks are inside `content`
      "tool_use_id": "srvtoolu_9a90a390a",
      "content": [
        {
          "type": "web_search_result",
          "uri": "https://weather.com",
          "title": "National and Local Weather",
          "encrypted_content": "eyJlbmNyeXB0ZWRfa2V5Ijoic2VjcmV0LW...", // encrypted list of snippets from the web search provider
        },
        {
          "type": "web_search_result",
          "uri": "https://accuweather.com",
          "title": "San Francisco, CA Hourly Weather",
          "encrypted_content": "yaJlbmNyeXB0ZWRfa2V5Ijoic2VjcmV0LW...", // encrypted list of snippets from the web search provider
        },
      ],
    },
    // Server starts a new sampling run with the above content appended (unencrypted)
    // to the original request. Everything below is completion content from the
    // second sampling run.
    {
      "type": "text",
      "text": "The current weather in San Francisco, CA is 65 degrees Fahrenheit and partly cloudy."
    }
  ],
  // Server output is no longer 1-to-1 with a single sampling run. From the
  // user's perspective, there is just one "Message" with a single id
  "id": "msg_a930390d3",
  "usage": {
    "input_tokens": 3029,
    "output_tokens": 6039,
    "server_tool_use": {
      "web_search_requests": 2
    }
  },
  "stop_reason": "end_turn"
}

ウェブ検索によるストリーミング

ストリーミングが有効になっている場合、モデルはストリームの一部として検索イベントを返します。次に例を示します。

// Claude's decision to search

event: content_block_start
data: {"type": "content_block_start", "index": 1, "content_block": {"type": "server_tool_use", "id": "srvtoolu_xyz789", "name": "web_search"}}

// Search query streamed
event: content_block_delta
data: {"type": "content_block_delta", "index": 1, "delta": {"type": "input_json_delta", "partial_json": "{\"query\":\"latest quantum computing breakthroughs 2025\"}"}}

// Pause while search executes

// Search results streamed
event: content_block_start
data: {"type": "content_block_start", "index": 2, "content_block": {"type": "web_search_tool_result", "tool_use_id": "srvtoolu_xyz789", "content": [{"type": "web_search_result", "title": "Quantum Computing Breakthroughs in 2025", "url": "https://example.com"}]}}

使用量は測定され、message_delta メッセージに含まれます。これには、web_search アイテムの累積カウントが含まれます。次に例を示します。

event: message_delta
data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":10682,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":510,"server_tool_use":{"web_search_requests":1}}}

Claude 4.0 以降のモデルのウェブ検索機能は、Anthropic の Claude モデルのオプション機能です。リクエストでウェブ検索ツールを指定することで、この機能を有効にできます。この機能を有効にすると、Vertex AI は、リクエストから派生した検索クエリを Anthropic が選択したサードパーティの検索サービス プロバイダに送信するように Claude モデルに指示します。Google は、このサードパーティ プロバイダのデータ処理慣行について責任を負いません。検索クエリが送信されると、そのデータの取り扱いは Google ではなく、サードパーティ独自の利用規約とプライバシー ポリシーに準拠します。

ウェブ検索機能を有効にすると、データ ガバナンスとセキュリティ体制に直接影響します。顧客管理の暗号鍵(CMEK)やデータ所在地などの Vertex AI の追加コミットメントは、サードパーティの検索プロバイダによるデータ処理中は適用されません。コンシューマー プロジェクトが VPC-SC 境界内にある場合、Vertex AI は次のエラー メッセージでリクエストを拒否します。

{
  "error": {
    "code": 400,
    "message": "The requested model does not serve requests restricted by VPCSC",
    "status": "FAILED_PRECONDITION"
  }
}

この機能は Claude 4.0 以降のモデルでのみ使用できます。Vertex AI の古い Claude モデルでは使用できません。ウェブ検索機能が使用されている場合に、Anthropic ウェブ検索機能が呼び出すことができるサードパーティ検索サービスのリスト:

料金

ウェブ検索の料金は、ウェブ リクエストの量に基づいて、標準メッセージ API の使用量に対するアドオンとして請求されます。サンプリング呼び出しが追加されるため、追加の入力トークンについても課金されます。

詳細は、料金をご覧ください。