Package google.developers.knowledge.v1

索引

DeveloperKnowledge

Developer Knowledge API 提供对 Google 公共开发者文档的程序化访问权限,让您可以将此知识库集成到自己的应用和工作流中。

该 API 旨在成为以机器可读方式访问 Google 开发者文档的规范来源。

一个典型的用例是,先使用 DeveloperKnowledge.SearchDocumentChunks 根据查询查找相关网页 URI,然后使用 DeveloperKnowledge.GetDocumentDeveloperKnowledge.BatchGetDocuments 提取排名靠前的结果的完整内容。

所有文档内容均以 Markdown 格式提供。

BatchGetDocuments

rpc BatchGetDocuments(BatchGetDocumentsRequest) returns (BatchGetDocumentsResponse)

检索多个文档,每个文档都包含完整的 Markdown 内容。

授权范围

需要以下 OAuth 范围之一:

  • https://www.googleapis.com/auth/devprofiles.full_control
  • https://www.googleapis.com/auth/cloud-platform

如需了解详情,请参阅 OAuth 2.0 Overview

GetDocument

rpc GetDocument(GetDocumentRequest) returns (Document)

检索单个文档,其中包含完整的 Markdown 内容。

授权范围

需要以下 OAuth 范围之一:

  • https://www.googleapis.com/auth/devprofiles.full_control
  • https://www.googleapis.com/auth/cloud-platform

如需了解详情,请参阅 OAuth 2.0 Overview

SearchDocumentChunks

rpc SearchDocumentChunks(SearchDocumentChunksRequest) returns (SearchDocumentChunksResponse)

在 Google 的开发者文档中搜索开发者知识。根据用户的查询返回 DocumentChunk。同一 Document 中可能包含许多块。如需检索完整文档,请将 SearchDocumentChunksResponse.results 中返回的 DocumentChunk.parentDeveloperKnowledge.GetDocumentDeveloperKnowledge.BatchGetDocuments 结合使用。

授权范围

需要以下 OAuth 范围之一:

  • https://www.googleapis.com/auth/devprofiles.full_control
  • https://www.googleapis.com/auth/cloud-platform

如需了解详情,请参阅 OAuth 2.0 Overview

BatchGetDocumentsRequest

DeveloperKnowledge.BatchGetDocuments 的请求消息。

字段
names[]

string

必需。指定要检索的文档的名称。一个批次最多可以检索 20 个文档。文档将按照请求中 names 的顺序返回。

格式:documents/{uri_without_scheme} 示例:documents/docs.cloud.google.com/storage/docs/creating-buckets

view

DocumentView

可选。指定文档的 DocumentView。如果未指定,DeveloperKnowledge.BatchGetDocuments 默认使用 DOCUMENT_VIEW_CONTENT

BatchGetDocumentsResponse

DeveloperKnowledge.BatchGetDocuments 的响应消息。

字段
documents[]

Document

包含所请求的文档。

文档

文档表示开发者知识语料库中的一段内容。

字段
name

string

标识符。包含文档的资源名称。格式:documents/{uri_without_scheme} 示例:documents/docs.cloud.google.com/storage/docs/creating-buckets

uri

string

仅限输出。提供内容的 URI,例如 docs.cloud.google.com/storage/docs/creating-buckets

content

string

仅限输出。包含文档的完整内容(采用 Markdown 格式)。

description

string

仅限输出。提供文档的说明。

data_source

string

仅限输出。指定文档的数据源。数据源示例:firebase.google.com

title

string

仅限输出。提供文档的标题。

update_time

Timestamp

仅限输出。表示上次更新文档内容或元数据时的时间戳。

view

DocumentView

仅限输出。指定文档的 DocumentView

DocumentChunk

DocumentChunk 表示 DeveloperKnowledge 语料库中 Document 的一段内容。如需提取整个文档内容,请将 parent 传递给 DeveloperKnowledge.GetDocumentDeveloperKnowledge.BatchGetDocuments

字段
parent

string

仅限输出。包含此块所来自的文档的资源名称。格式:documents/{uri_without_scheme} 示例:documents/docs.cloud.google.com/storage/docs/creating-buckets

id

string

仅限输出。指定此块在文档中的 ID。块 ID 在文档中是唯一的,但在文档之间不是全局唯一的。块 ID 不稳定,可能会随时间变化。

content

string

仅限输出。包含文档块的内容。

document

Document

仅限输出。表示此块所来自的 Document 的元数据。此 Document 消息的 DocumentView 将设置为 DOCUMENT_VIEW_BASIC。此处包含该字段是为了方便起见,这样客户端如果只需要元数据字段,就不需要调用 DeveloperKnowledge.GetDocumentDeveloperKnowledge.BatchGetDocuments。否则,客户端应使用 DeveloperKnowledge.GetDocumentDeveloperKnowledge.BatchGetDocuments 提取完整文档内容。

DocumentView

指定要包含的 Document 的字段。

枚举
DOCUMENT_VIEW_UNSPECIFIED 默认值 / 未设置的值。如果未指定 DocumentView,请参阅每个 API 方法的默认值。
DOCUMENT_VIEW_BASIC

仅包含基本元数据字段: - name - uri - data_source - title - description - update_time - view

这是 DeveloperKnowledge.SearchDocumentChunks 的默认视图。

DOCUMENT_VIEW_FULL 包含所有 Document 字段。
DOCUMENT_VIEW_CONTENT

包含 DOCUMENT_VIEW_BASIC 字段和 content 字段。

这是 DeveloperKnowledge.GetDocumentDeveloperKnowledge.BatchGetDocuments 的默认视图。

GetDocumentRequest

DeveloperKnowledge.GetDocument 的请求消息。

字段
name

string

必需。指定要检索的文档的名称。格式:documents/{uri_without_scheme} 示例:documents/docs.cloud.google.com/storage/docs/creating-buckets

view

DocumentView

可选。指定文档的 DocumentView。如果未指定,DeveloperKnowledge.GetDocument 默认使用 DOCUMENT_VIEW_CONTENT

SearchDocumentChunksRequest

DeveloperKnowledge.SearchDocumentChunks 的请求消息。

字段
query

string

必需。提供用户提供的原始查询字符串,例如“如何创建 Cloud Storage 存储分区?”。

page_size

int32

可选。指定要返回的结果数上限。服务返回的值可能小于此值。

如果未指定,则最多返回 5 个结果。

最大值为 20;如果值大于 20,则会导致 INVALID_ARGUMENT 错误。

page_token

string

可选。包含从之前的 SearchDocumentChunks 调用接收的页面令牌。利用其进行后续页面检索。

filter

string

可选。对搜索结果应用严格的过滤条件。该表达式支持 https://google.aip.dev/160 中介绍的语法的子集。

虽然 SearchDocumentChunks 返回 DocumentChunk,但过滤条件会应用于 DocumentChunk.document 字段。

支持过滤的字段:

  • data_source (STRING):文档的来源,例如 docs.cloud.google.com。如需查看语料库中的数据源的完整列表,请参阅 https://developers.google.com/knowledge/reference/corpus-reference
  • update_time (TIMESTAMP):文档上次有意义更新时的时间戳。有意义的更新是指更改文档的 Markdown 内容或元数据的更新。
  • uri (STRING):文档 URI,例如 https://docs.cloud.google.com/bigquery/docs/tables

STRING 字段支持 =(等于)和 !=(不等于)运算符,用于对整个字符串进行 完全匹配。不支持部分匹配、前缀匹配和正则表达式匹配。

TIMESTAMP 字段支持 =<<=>>= 运算符。时间戳必须采用 RFC-3339 格式,例如 "2025-01-01T00:00:00Z"

您可以使用 ANDORNOT(或 -)逻辑运算符组合表达式。OR 的优先级高于 AND。使用括号进行显式优先级分组。

示例:

  • data_source = "docs.cloud.google.com" OR data_source = "firebase.google.com"
  • data_source != "firebase.google.com"
  • update_time < "2024-01-01T00:00:00Z"
  • update_time >= "2025-01-22T00:00:00Z" AND (data_source = "developer.chrome.com" OR data_source = "web.dev")
  • uri = "https://docs.cloud.google.com/release-notes"

filter 字符串的长度不得超过 500 个字符;如果值超过 500 个字符,则会导致 INVALID_ARGUMENT 错误。

SearchDocumentChunksResponse

DeveloperKnowledge.SearchDocumentChunks 的响应消息。

字段
results[]

DocumentChunk

包含给定查询的搜索结果。此列表中的每个 DocumentChunk 都包含与搜索查询相关的内容片段。将每个结果的 DocumentChunk.parent 字段与 DeveloperKnowledge.GetDocumentDeveloperKnowledge.BatchGetDocuments 结合使用,以检索完整文档内容。

next_page_token

string

可选。提供一个令牌,该令牌可以作为 page_token 发送,以检索下一页。如果省略此字段,则不存在后续页面。