Method: answerQuery

グラウンディングされた生成を使用してクエリに回答します。

HTTP リクエスト

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

この URL は gRPC Transcoding 構文を使用します。

リクエストの本文

リクエストの本文には、次の構造のデータが含まれます。

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): ドキュメントが最後に更新されたときのタイムスタンプ。意味のある更新とは、ドキュメントのマークダウン コンテンツまたはメタデータを変更する更新のことです。
  • 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.
}
フィールド
参照の内容が含まれます。以下は、相互に排他的なフィールドのリストです。レスポンスで設定されるフィールドは最大で 1 つです。
documentReference

object (DocumentReference)

出力専用。参照ドキュメント。

相互に排他的なフィールドの終了。

DocumentReference

ドキュメントへの参照を表します。

JSON 表現
{
  "documentChunk": {
    object (DocumentChunk)
  }
}
フィールド
documentChunk

object (DocumentChunk)

出力専用。ドキュメント チャンクが含まれます。documentChunk.id フィールドは設定されず、空になります。