适用于企业的 Web 接地

本页介绍了 Web Grounding for Enterprise 合规性控制,以及如何使用 Web Grounding for Enterprise API 生成基于网络信息的回答。编入索引的内容是 Google 搜索中提供的内容的子集,适合金融、医疗保健和公共部门等受严格监管的行业的客户。

如果您不需要合规性控制,请使用使用 Google 搜索接地,因为它可访问更广泛的 Web 索引。

概览

企业版 Web Grounding 使用网络索引来生成有依据的回答。该服务不会记录客户数据,并且支持 VPC Service Controls。由于系统不会保留任何客户数据,因此客户管理的加密密钥 (CMEK) 和 Access Transparency (AxT) 不适用。

使用 API

本部分提供了一些示例请求,展示了如何使用 Vertex AI 上的生成式 AI API Gemini 2 通过 Gemini 创建有事实依据的回答。如需使用该 API,您必须设置以下字段:

  • Contents.parts.text:用户要发送给 API 的文本查询。
  • tools.enterpriseWebSearch:提供此工具后,Gemini 可以使用企业版 Web Grounding。

Python

安装

pip install --upgrade google-genai

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

设置环境变量以将 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_VERTEXAI=True

from google import genai
from google.genai.types import (
    EnterpriseWebSearch,
    GenerateContentConfig,
    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 Enterprise Web Search Tool
            Tool(enterprise_web_search=EnterpriseWebSearch())
        ],
    ),
)

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

REST

将以下变量替换为值:

  • PROJECT_NUMBER:您的项目编号。
  • LOCATION:您的区域。
  • TEXT:您的提示。
  curl -X POST -H "Authorization: Bearer $(gcloud auth print-access-token)" -H "Content-Type: application/json" -H "x-server-timeout: 60" https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION/publishers/google/models/gemini-2.0-flash:generateContent -d '
  {
    "contents": [{
      "role": "user",
      "parts": [{
        "text": TEXT
      }]
    }],
    "tools": [{
      "enterpriseWebSearch": {
      }
    }]
  }
  '

后续步骤