Method: answerQuery

使用接地生成功能回答查询。

HTTP 请求

POST https://developerknowledge.googleapis.com/v1alpha:answerQuery

网址采用 gRPC 转码语法。

请求正文

请求正文中包含结构如下的数据:

JSON 表示法
{
  "query": string,
  "filter": string
}
字段
query

string

必需。要回答的查询。

filter

string

可选。对用于生成答案的搜索结果应用严格过滤条件。该表达式支持 https://google.aip.dev/160 中所述的部分语法。

支持过滤的字段:

  • contentLengthBytes (INTEGER):Document.content 字段的长度(以字节为单位)。
  • dataSource(字符串):文档的来源,例如 docs.cloud.google.com。如需查看语料库中数据源的完整列表,请访问 https://developers.google.com/knowledge/reference/corpus-reference
  • updateTime (TIMESTAMP):相应文档上次有意义的更新的时间戳。有意义的更新是指更改文档的 Markdown 内容或元数据。
  • uri(STRING):文档 URI,例如 https://docs.cloud.google.com/bigquery/docs/tables

INTEGER 字段支持 =<<=>>= 运算符。

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

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

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

示例:

  • 按“Document.content_length_bytescontentLengthBytes < 50000”过滤
  • dataSource = "docs.cloud.google.com" OR dataSource = "firebase.google.com"
  • dataSource != "firebase.google.com"
  • updateTime < "2024-01-01T00:00:00Z"
  • updateTime >= "2025-01-22T00:00:00Z" AND (dataSource = "developer.chrome.com" OR dataSource = "web.dev")
  • uri = "https://docs.cloud.google.com/release-notes"

filter 字符串不得超过 500 个字符;如果值超过 500 个字符,系统会返回 INVALID_ARGUMENT 错误。

响应正文

DeveloperKnowledge.AnswerQuery 的响应消息。

如果成功,响应正文将包含结构如下的数据:

JSON 表示法
{
  "answer": {
    object (Answer)
  }
}
字段
answer

object (Answer)

查询的答案。

授权范围

需要以下 OAuth 范围之一:

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

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

答案

对查询的回答。

JSON 表示法
{
  "answerText": string,
  "citations": [
    {
      object (AnswerCitation)
    }
  ],
  "references": [
    {
      object (AnswerReference)
    }
  ]
}
字段
answerText

string

包含答案的文本。

citations[]

object (AnswerCitation)

仅限输出。包含回答的引用。

references[]

object (AnswerReference)

仅限输出。包含回答的参考信息。

AnswerCitation

片段的引用信息。

JSON 表示法
{
  "startIndex": integer,
  "endIndex": integer,
  "sources": [
    {
      object (CitationSource)
    }
  ]
}
字段
startIndex

integer

仅限输出。指示片段的起始位置,以字节 (UTF-8 unicode) 为单位,含边界值。如果存在多字节字符(例如非 ASCII 字符),则索引长度会大于字符串长度。

endIndex

integer

仅限输出。指示片段结束位置的索引,以字节 (UTF-8 unicode) 为单位(不含)。如果存在多字节字符(例如非 ASCII 字符),则索引长度会大于字符串长度。

sources[]

object (CitationSource)

仅限输出。包含归因片段的引用来源。

CitationSource

引用来源。

JSON 表示法
{
  "referenceIndex": integer
}
字段
referenceIndex

integer

仅限输出。包含 references 重复字段中 Answer.AnswerReference 的索引。

AnswerReference

表示对来源的引用。

JSON 表示法
{

  // Union field content can be only one of the following:
  "documentReference": {
    object (DocumentReference)
  }
  // End of list of possible types for union field content.
}
字段
联合字段 content。包含引用的内容。content 只能是下列其中一项:
documentReference

object (DocumentReference)

仅限输出。参考文档。

DocumentReference

表示对文档的引用。

JSON 表示法
{
  "documentChunk": {
    object (DocumentChunk)
  }
}
字段
documentChunk

object (DocumentChunk)

仅限输出。包含文档块。未设置 documentChunk.id 字段,因此该字段将为空。