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 (STRING):文件來源,例如 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 欄位支援 =<<=>>= 運算子。

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

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

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

範例:

  • Document.content_length_bytes篩選:contentLengthBytes < 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 個字元,否則會導致 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 欄位未設定,因此會留空。