跳到正文
Google Developers Blog·· 21 小时前精选AI 评分61

Google 发布 Developer Knowledge API 生态,为 AI 智能体提供官方文档检索

Supercharge your development with the Google Developer Knowledge API ecosystem

AI 导读

Google 推出 Developer Knowledge API 生态,作为 Google Cloud、Firebase、Android 等开发者文档的官方程序化来源,用结构化 API 和 Markdown 格式文档取代网页抓取,支持语义与关键词搜索、文档分块和有依据的问答。

推荐理由

官方为自己的开发者文档检索 API 提供了 CLI、agent skill、客户端库等多入口,可对照选型接入现有工作流。

正文 · AI 翻译

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 可确保你的智能体和开发者工具保持准确且 token 高效。

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 训练截止日期过时而产生的幻觉。
  • 优化 token 与上下文使用:采用多步检索工作流——先使用 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-knowledge

Shell

已复制

此命令会在你的项目中安装 Developer Knowledge agent skill。该技能会指导你的助手如何使用 Developer Knowledge MCP server(或使用 curl 回退到 REST API)。

要在你的 IDE 中连接到 MCP server,或使用 Application Default Credentials 或 API key 配置身份验证,请参阅 Connect to the Developer Knowledge MCP server。

客户端库

客户端库让你可以将文档检索、搜索和基于依据的答案生成嵌入到生产系统、自动化 CI/CD 流水线和企业知识机器人中。

主要优势:

  • 编程访问:提供对 AnswerQuery、SearchDocumentChunks、GetDocument 和 BatchGetDocuments 的编程访问。
  • 惯用集成:为每个受支持的语言生态系统量身定制的原生类型定义、构建器模式、错误处理和异步执行。
  • 批处理与效率:像 BatchGetDocuments 这样的方法可以在单次 API 调用中检索最多 20 个文档。
  • 企业安全性与可靠性:支持 Google Cloud Application Default Credentials、自动重试和结构化引用跟踪。

支持的语言:

按照 Quickstart 开始设置你的环境、安装库,并开始检索开发者文档。

代码示例:

以下示例演示了 AI agent 如何使用 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,你可以测试以下核心端点:

DK API blog draft

后续步骤

准备好将 Google 开发者文档集成到你的工作流和 AI 工具中了吗?以下是一些入门方法:

  • 如果你已有 gcloud CLI:你可以立即使用 gcloud CLI 界面查询官方文档。
  • 如果你没有 gcloud CLI:将 agent skill 交给你的 AI 编码助手或 agent,以启用基于依据的检索。

上一页

下一页

来源:Google Developers Blog · developers.googleblog.com