Google 发布 Developer Knowledge API 生态系统,为 AI 智能体提供官方文档检索
Supercharge your development with the Google Developer Knowledge API ecosystem
Google 推出 Developer Knowledge API 生态系统,为 Google Cloud、Firebase、Android 等开发者文档提供官方程序化来源,以结构化 API 和 Markdown 格式文档取代脆弱的网页抓取。
官方为 AI 智能体和开发工具提供结构化文档检索入口,覆盖 CLI、MCP 技能和多语言客户端库,可替代网页抓取。
2026年10月7日
如果你在 Google Cloud 上构建 AI 代理或开发者工具,请不要再依赖脆弱的网页抓取,也不要再与过时的 LLM 训练截止日期较劲。
使用 Google Developer Knowledge API 生态系统,更快、更智能、更有信心地构建——其中包括我们的 gcloud CLI 界面、官方代理技能、API Explorer 以及多语言客户端库。无论你是在命令行终端中操作、向 AI 代理发出提示、交互式测试请求,还是编写生产软件,我们的工具都能提供 Google 文档。
什么是 Developer Knowledge API?
Developer Knowledge API 是 Google 官方的、以编程方式访问的开发者文档权威来源,涵盖 Google Cloud、Firebase、Android 等内容。它专为现代 AI 代理、IDE 扩展和自动化工作流而设计,用结构化的 API 取代了脆弱的网页抓取,提供最新、Markdown 格式的文档。
通过提供语义搜索和关键词搜索、智能文档分块以及有依据的问答能力,该 API 可确保你的代理和开发者工具保持准确且令牌高效。
Developer Knowledge API 会频繁建立索引,以确保可预测的检索、最新的文档,并将上游更新与代理访问之间的延迟降至最低。
工具概览与能力
借助 Developer Knowledge API 的各类接口,开发者和 AI 代理可以在终端、IDE 和后端代码库中发现、检索并综合出以 Google 官方文档为依据的答案。
gcloud CLI
Developer Knowledge API gcloud CLI 界面将官方文档搜索、检索和有依据的问答集成到你的命令行环境中。它已预装在 Cloud Shell 中,并可在 Linux、macOS 和 Windows 上的标准 Google Cloud SDK 安装中使用,无需额外插件或配置。
主要能力与命令:
answer-query:在终端中获取有依据的答案。documents search-chunks:在 Google 文档中搜索文档片段和分块。documents describe:检索特定文档的元数据和内容。
示例:
# Get grounded answers
gcloud developer-knowledge answer-query --query="How do I create a BigQuery dataset?"
# Search document chunks
gcloud developer-knowledge documents search-chunks --query="Firestore transactions"
# Retrieve metadata and content for a specific document
gcloud developer-knowledge documents describe "documents/docs.cloud.google.com/storage/docs/creating-buckets"
# Troubleshoot an error trace by piping it directly into the answer-query command
gcloud developer-knowledge answer-query --query="$(cat error.txt)"Shell
已复制
要开始使用 gcloud CLI,请参阅 gcloud CLI 快速入门。
代理技能
Developer Knowledge 代理技能在 AI 编码助手与 Google 文档生态系统之间建立连接,使自主工具能够访问最新的技术规范。
主要优势
- 有依据并减少幻觉:为 AI 编码助手和代理工作流提供对最新 Google 开发者文档的访问,减少因 LLM 训练截止日期过时而产生的幻觉。
- 优化令牌与上下文使用:采用多步检索工作流——先使用
searchDocumentChunks检查代码和文档分块,然后再用documents.get获取完整的 Markdown 页面,或使用answerQuery提供有依据的答案。 - 广泛的工具兼容性:在 Google Antigravity、Claude Code、Cursor、GitHub Copilot 及自定义代理框架中使用标准 MCP 集成。该技能会指导你的助手如何使用 Developer Knowledge MCP 服务器(或通过
curl回退到 REST API)。
配置代理技能
在终端中运行以下 CLI 辅助命令来配置该技能:
npx skills add google/skills --skill retrieving-developer-knowledgeShell
已复制
此命令会在你的项目中安装 Developer Knowledge 代理技能。该技能会指导你的助手如何使用 Developer Knowledge MCP 服务器(或使用 curl 回退到 REST API)。
如需在 IDE 中连接到 MCP 服务器,或使用应用默认凭据或 API 密钥配置身份验证,请参阅连接到 Developer Knowledge MCP 服务器。
客户端库
客户端库可让你将文档检索、搜索和基于依据的答案生成嵌入生产系统、自动化 CI/CD 流水线和企业知识机器人中。
主要优势:
- 编程访问:提供对
AnswerQuery、SearchDocumentChunks、GetDocument和BatchGetDocuments的编程访问。 - 惯用集成:为每个受支持的语言生态系统量身定制的原生类型定义、构建器模式、错误处理和异步执行。
- 批处理和效率:像
BatchGetDocuments这样的方法可在单次 API 调用中检索最多 20 个文档。 - 企业级安全性和可靠性:支持 Google Cloud 应用默认凭据、自动重试和结构化引用跟踪。
支持的语言:
按照快速入门进行操作,以设置你的环境、安装库并开始检索开发者文档。
代码示例:
以下示例演示了 AI 代理如何使用 Python 客户端库获取最新的产品版本说明,从而确保其响应基于超出其训练截止时间的数据:
from google.cloud import developer_knowledge_v1
def FetchMyProductReleaseNotes(my_product_name: str) -> str:
"""Fetches the latest release notes to bridge a model's knowledge cutoff."""
# Initialize the Developer Knowledge API client
my_api_client = developer_knowledge_v1.DeveloperKnowledgeClient()
# Formulate a targeted query for the specific product's release notes
my_search_query = f"{my_product_name} latest release notes"
my_request = developer_knowledge_v1.SearchDocumentChunksRequest(
query=my_search_query,
)
# Retrieve and return the relevant documentation chunks
my_response = my_api_client.search_document_chunks(request=my_request)
# Extract the chunk text
my_release_notes = [my_chunk.text for my_chunk in my_response.chunks]
return "\n".join(my_release_notes)
# Example usage:
# my_latest_notes = FetchMyProductReleaseNotes("Firestore")Python
已复制
各种任务的代码示例:
APIs Explorer
用于 Developer Knowledge API 的 Google APIs Explorer 提供了一个集成到 Google 开发者网站中的交互式零代码界面,可用于试验和验证 API 请求及响应结构。
通过 APIs Explorer,你可以测试以下核心端点:
后续步骤
准备好将 Google 开发者文档集成到你的工作流和 AI 工具中了吗?以下是一些入门方法:
- 如果你已有 gcloud CLI:你可以立即使用 gcloud CLI 接口查询官方文档。
- 如果你没有 gcloud CLI:将代理技能交给你的 AI 编码助手或代理,以启用基于依据的检索。
上一页
下一页
来源:Google Developers Blog · developers.googleblog.com