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 中所述的部分語法。

可篩選的欄位:

  • content_length_bytes (INTEGER):Document.content 欄位的長度 (以位元組為單位)。
  • 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。

INTEGER 欄位支援 =、<、<=、> 和 >= 運算子。

STRING 欄位支援 = (等於) 和 != (不等於) 運算子,可完全比對整個字串。系統不支援部分相符、前置字元相符和規則運算式相符。

TIMESTAMP 欄位支援 =、<、<=、> 和 >= 運算子。時間戳記必須採用 RFC-3339 格式,例如 "2025-01-01T00:00:00Z"。

您可以使用 AND、OR 和 NOT (或 -) 邏輯運算子合併運算式。OR 的優先順序高於 AND。使用括號明確分組,以指定優先順序。

範例:

  • 依Document.content_length_bytes篩選:content_length_bytes < 50000
  • 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 錯誤。

回應主體

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 表示法
{

  // The following is a list of mutually exclusive fields. At most one of the
  // fields will be set in a response:
  "documentReference": {
    object (DocumentReference)
  }
  // End of mutually exclusive fields.
}
欄位
包含參考資料的內容。以下列出互斥的欄位。回應中最多會設定一個欄位:
documentReference

object (DocumentReference)

僅供輸出。參考文件。

互斥欄位的結尾。

DocumentReference

代表文件的參照。

JSON 表示法
{
  "documentChunk": {
    object (DocumentChunk)
  }
}
欄位
documentChunk

object (DocumentChunk)

僅供輸出。包含文件區塊。「documentChunk.id」欄位未設定,因此會留空。