依托 Parallel Web Search 进行接地

Parallel Web Systems 提供了一个搜索 API,该 API 可访问 公开的网络数据,这些数据经过优化,可供大型语言 模型用于接地。本页面介绍了如何使用 Parallel 将 Gemini 回答接地。

在 Gemini Enterprise Agent Platform 上使用 Parallel 进行接地是一项单独的服务(如您的 Google Cloud 协议中所定义),可将 Gemini 模型连接到 Parallel Web Systems 搜索 API 提供的公开网络数据。借助此服务,Gemini 可以访问数十亿个网页中的实时信息,从而确保回答更加最新且基于事实。

使用场景

使用 Parallel 进行接地适用于以下使用场景:

  • 使用网络数据来完成或丰富信息。
  • 多跳智能体,需要更深入的网络搜索来回答更复杂的问题。
  • 构建集成网络搜索数据的 API。
  • 面向员工的助理,允许最终用户使用最新的网络信息提问和创建复杂的报告。
  • 面向消费者的应用(例如零售和旅游),允许用户做出明智的购买决策。
  • 自动智能体,可自主运行以执行自动化任务,例如新闻分析和 KYC 检查。
  • 垂直智能体(销售智能体、编码智能体、财务智能体)从网络获取最新的上下文。

示例

谁赢得了 2025 年拉斯维加斯 F1 大奖赛?

不接地 接地
2025 年拉斯维加斯大奖赛尚未举行。比赛定于 2025 年 11 月 20 日至 22 日的周末举行。因此,获胜者未知。 2025 年拉斯维加斯 F1 大奖赛的获胜者是红牛车队的马克斯·维斯塔潘。比赛于 2025 年 11 月 22 日举行。 来源 :domain1.com、domain2.com,...

支持的模型

以下模型支持使用 Parallel 网络搜索进行接地:

  • Gemini 2.5 Flash (gemini-2.5-flash)
  • Gemini 2.5 Flash-Lite (gemini-2.5-flash-lite)
  • Gemini 2.5 Pro (gemini-2.5-pro)
  • Gemini 3.1 Pro (gemini-3.1-pro-preview)
  • Gemini 3.1 Flash Lite (gemini-3.1-flash-lite)
  • Gemini 3.5 Flash (gemini-3.5-flash)

准备工作

如需使用“依托 Parallel Web Search 进行接地”,您必须设置访问权限。您有两种选择:

  • 直接在 Google Cloud Marketplace 上订阅“依托 Parallel Web Search 进行接地”,以便在现有云环境中进行简化集成。对于敏感型工作负载,您还可以选择“零数据 保留”服务。如需使用 ZDR,您必须订阅 ZDR 服务,并在 API 请求中设置相应的 enable_zero_data_retention 标志。

  • 使用现有的 Parallel API 密钥。

在 Google Cloud Marketplace 上订阅(推荐)

通过 Google Cloud Marketplace 进行集成,您可以直接在 Google Cloud中管理“依托 Parallel Web Search 进行接地”服务。如需开始使用,请在 Google Cloud Marketplace 上订阅“依托 Parallel Web Search 进行接地”服务,接受服务条款,并查看价格。

自带 API 密钥

如果您希望单独管理 Parallel 结算和 API 访问权限,可以提供自己的 API 密钥。如需使用此方法,您需要从 Parallel 开发者平台获取 API 密钥。此 API 密钥直接用于向 Gemini 发出的 REST API 请求。

使用 Parallel 将 Gemini 回答接地

您可以使用 控制台中的 Google Cloud Agent Studio、 Google Gen AI SDK 或 REST API 向 Gemini 请求接地回答。为了获得最佳性能,我们建议您对可选参数使用默认设置,除非您严格要求使用非默认值。

如果您已在 Google Cloud Marketplace 上订阅“依托 Parallel Web Search 进行接地”服务 ,请验证用于订阅的结算账号在您的 Google Cloud 项目中是否处于活跃状态。

在运行示例之前,请完成前提条件, 包括在 Google Cloud Marketplace 上订阅或 提供 Parallel API 密钥。

每个 SDK 示例都会从其标签页中显示的环境变量读取您的项目和位置。在示例代码中,将 MODEL_ID 替换为受 支持的模型 ID,例如 gemini-2.5-flash

控制台

如需使用 Gemini Enterprise Agent Platform 上的 Agent Studio,使用 Parallel Web Search 将 Gemini 回答接地,请按以下步骤操作:

  1. 在 Google Cloud 控制台中,前往 Agent Studio 页面。

    前往 Agent Studio

  2. 在侧边栏中,依次点击模型设置 下的接地 部分, 然后开启合作伙伴 切换开关(来自接地合作伙伴的搜索结果 )。

  3. 选择 Parallel Web Search 作为接地合作伙伴,然后点击应用 。如需使用 Parallel Web Search,您必须先 在 Google Cloud Marketplace 上订阅它

  4. 在文本框中输入提示,然后提交。

您的提示回答现在使用“依托 Parallel Web Search 进行接地”。

Python

安装

pip install --upgrade google-genai

如需了解详情,请参阅 SDK 参考文档

设置环境变量以将 Google Gen AI SDK 与 Vertex AI 搭配使用:

# 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_ENTERPRISE=True

from google import genai
from google.genai import types

client = genai.Client()

response = client.models.generate_content(
    model="MODEL_ID",
    contents="Who won the 2025 Las Vegas F1 Grand Prix?",
    config=types.GenerateContentConfig(
        tools=[
            types.Tool(
                parallel_ai_search=types.ToolParallelAiSearch(
                    # Optional. Omit api_key if you subscribed to Grounding with
                    # Parallel Web Search on Google Cloud Marketplace. Otherwise,
                    # provide your Parallel API key.
                    # api_key="API_KEY",
                    # Optional. Customize the search. See the REST tab for the
                    # full list of supported parameters. Keys inside custom_configs
                    # are Parallel.ai Search API params (snake_case).
                    custom_configs={
                        "mode": "basic",
                        "max_results": 10,
                        "source_policy": {"include_domains": ["wikipedia.org"]},
                    },
                )
            )
        ],
    ),
)

print(response.text)
# Example response:
# Max Verstappen won the 2025 Las Vegas F1 Grand Prix ...

# The grounding metadata contains the web sources used to ground the response.
print(response.candidates[0].grounding_metadata.grounding_chunks)

如需自定义搜索,请设置 ToolParallelAiSearchcustom_configs 字段。此字段接受 REST 标签页中介绍的相同可选参数,例如 source_policyexcerptsmax_resultsmode

Java

了解如何安装或更新 Java

如需了解详情,请参阅 SDK 参考文档

设置环境变量以将 Google Gen AI SDK 与 Vertex AI 搭配使用:

# 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_ENTERPRISE=True

import com.google.genai.Client;
import com.google.genai.types.GenerateContentConfig;
import com.google.genai.types.GenerateContentResponse;
import com.google.genai.types.Tool;
import com.google.genai.types.ToolParallelAiSearch;
import java.util.List;
import java.util.Map;

public class ParallelGroundingSample {
  public static void main(String[] args) {
    try (Client client = Client.builder().build()) {

      GenerateContentConfig config =
          GenerateContentConfig.builder()
              .tools(
                  // Omit apiKey if you subscribed to Grounding with Parallel Web
                  // Search on Google Cloud Marketplace. Otherwise, set apiKey to
                  // your Parallel API key.
                  Tool.builder()
                      .parallelAiSearch(
                          ToolParallelAiSearch.builder()
                              // Optional. Customize the search. See the REST tab
                              // for the full list of supported parameters. Keys
                              // inside customConfigs are Parallel.ai Search API
                              // params (snake_case).
                              .customConfigs(
                                  Map.of(
                                      "mode", "basic",
                                      "max_results", 10,
                                      "source_policy",
                                      Map.of(
                                          "include_domains",
                                          List.of("wikipedia.org"))))
                              .build())
                      .build())
              .build();

      GenerateContentResponse response =
          client.models.generateContent(
              "MODEL_ID", "Who won the 2025 Las Vegas F1 Grand Prix?", config);

      System.out.println(response.text());
    }
  }
}

如需自定义搜索,请设置 ToolParallelAiSearchcustomConfigs 字段。此字段接受 REST 标签页中介绍的相同可选参数,例如 source_policyexcerptsmax_resultsmode

Node.js

安装

npm install @google/genai

如需了解详情,请参阅 SDK 参考文档

设置环境变量以将 Google Gen AI SDK 与 Vertex AI 搭配使用:

# 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_ENTERPRISE=True

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

const ai = new GoogleGenAI({});

const response = await ai.models.generateContent({
  model: 'MODEL_ID',
  contents: 'Who won the 2025 Las Vegas F1 Grand Prix?',
  config: {
    tools: [
      // Omit apiKey if you subscribed to Grounding with Parallel Web Search on
      // Google Cloud Marketplace. Otherwise, set apiKey to your Parallel API key.
      {
        parallelAiSearch: {
          // Optional. Customize the search. See the REST tab for the full
          // list of supported parameters. Keys inside customConfigs are
          // Parallel.ai Search API params (snake_case).
          customConfigs: {
            mode: 'basic',
            max_results: 10,
            source_policy: {include_domains: ['wikipedia.org']},
          },
        },
      },
    ],
  },
});

console.log(response.text);

如需自定义搜索,请设置 parallelAiSearch 工具的 customConfigs 字段。此字段接受 REST 标签页中介绍的相同可选参数,例如 source_policyexcerptsmax_resultsmode

REST

在使用任何请求数据之前,请先进行以下替换:

  • LOCATION:处理请求的区域。如需使用 全球端点,请清除端点名称中的相应位置,并将资源位置配置为 `global`。
  • PROJECT_ID:您的 Google Cloud 项目 ID。
  • MODEL_ID:要使用模型的 ID。
  • TEXT:要发送给模型的文本提示。
  • API_KEY:您的 Parallel Web Search API 密钥。如果您指定了 API 密钥,并且还在 Google Cloud Marketplace 上订阅了“依托 Parallel Web Search 进行接地”服务,则 API 密钥优先。
  • ENABLE_ZERO_DATA_RETENTION:可选:切换到 Parallel Web Search 的 ZDR 版本,以便对敏感型工作负载启用“零数据保留”功能。设置为 true,以便为您的请求使用 ZDR 服务。您 必须订阅 ZDR 专用服务,这些请求才能成功。如果未指定,则默认为标准版本。ZDR 版本仅通过 Google Cloud Marketplace 提供。
  • EXCLUDE_DOMAINS:可选:要从接地来源中 排除的网域列表。如果指定了此项,则会排除来自这些网域的来源。 可接受的值为网域 (www.example.com) 或以句点开头的网域扩展名 ( .gov、.edu、.co.uk)。您最多可以指定 200 个网域。
  • INCLUDE_DOMAINS:可选:要包含在接地来源中的网域列表。如果指定了此项,则会包含来自这些网域的来源。 可接受的值为网域 (www.example.com) 或以句点开头的网域扩展名 ( .gov、.edu、.co.uk)。您最多可以指定 200 个网域。
  • MAX_CHARS_PER_RESULT:可选:每个搜索结果摘要中包含的最大字符数。如果未指定,则默认为 30000。允许的范围为 [1000, 100000]
  • MAX_CHARS_TOTAL:可选:所有搜索结果摘要中的最大总 字符数。如果未指定,则默认为 100000。 允许的范围为 [1000, 1000000]
  • MAX_RESULTS:可选:用于接地的搜索结果数量上限。如果未指定,则默认为 10。允许的范围 为 [1, 20]
  • MODE:可选:用于请求的模式,可以是 basicadvanced。默认值为 basic。如果您希望以更高的延迟为代价获得更全面的搜索结果,请考虑使用 advanced 模式。
  • SEARCH_LOCATION:可选:用于地理位置定位搜索结果的ISO 3166-1 alpha-2 国家/地区代码。示例:"us"

HTTP 方法和网址:

POST https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models/MODEL_ID:generateContent

请求 JSON 正文:

{
  "contents": [{
    "role": "user",
    "parts": [{
      "text": "TEXT"
    }]
  }],
  "tools": [{
    "parallelAiSearch": {
        "api_key": "API_KEY",
        "enable_zero_data_retention": ENABLE_ZERO_DATA_RETENTION,
        "customConfigs": {
            "mode": "MODE",
            "location": "SEARCH_LOCATION",
            "max_results": MAX_RESULTS,
            "source_policy": {
                "exclude_domains": ["EXCLUDE_DOMAINS"],
                "include_domains": ["INCLUDE_DOMAINS"]
            },
            "excerpts": {
                "max_chars_per_result": MAX_CHARS_PER_RESULT,
                "max_chars_total": MAX_CHARS_TOTAL
            }
        }
    }
}],
  "model": "projects/PROJECT_ID/locations/LOCATION/publishers/google/models/MODEL_ID"
}

如需发送您的请求,请展开以下选项之一:

您应该收到类似以下内容的 JSON 响应。

Quota

默认配额是每分钟 200 个提示。如需申请提高速率限制,请向相应联系人提供您的使用场景和要求:

  • 如果您已在 Google Cloud Marketplace 上订阅“依托 Parallel Web Search 进行接地”服务 :请与您的 Google 客户支持团队联系。

  • 如果您提供自己的 API 密钥:请与 support@parallel.ai和您的 Google 客户 支持团队联系。

结算

使用“依托 Parallel Web Search 进行接地”服务会产生以下费用:

  • Gemini token 消耗量 :您可能需要为以下各项付费:

    • 提示 token 数
    • 思考 token 数
    • 输出 token 数

    如需了解详情,请参阅 价格

  • Gemini 的“利用数据进行接地”:如需了解详情,请参阅 价格

  • 使用 Parallel Web Search API 的价格