Method: answerQuery

Answers a query using grounded generation.

HTTP request

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

The URL uses gRPC Transcoding syntax.

Request body

The request body contains data with the following structure:

JSON representation
{
  "query": string,
  "filter": string
}
Fields
query

string

Required. The query to answer.

filter

string

Optional. Applies a strict filter to the search results used to ground the answer. The expression supports a subset of the syntax described at https://google.aip.dev/160.

Supported fields for filtering:

  • contentLengthBytes (INTEGER): The length of the Document.content field in bytes.
  • dataSource (STRING): The source of the document, e.g. docs.cloud.google.com. See https://developers.google.com/knowledge/reference/corpus-reference for the complete list of data sources in the corpus.
  • updateTime (TIMESTAMP): The timestamp of when the document was last meaningfully updated. A meaningful update is one that changes document's markdown content or metadata.
  • uri (STRING): The document URI, e.g. https://docs.cloud.google.com/bigquery/docs/tables.

INTEGER fields support =, <, <=, >, and >= operators.

STRING fields support = (equals) and != (not equals) operators for exact match on the whole string. Partial match, prefix match, and regexp match are not supported.

TIMESTAMP fields support =, <, <=, >, and >= operators. Timestamps must be in RFC-3339 format, e.g., "2025-01-01T00:00:00Z".

You can combine expressions using AND, OR, and NOT (or -) logical operators. OR has higher precedence than AND. Use parentheses for explicit precedence grouping.

Examples:

  • Filter by 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"

The filter string must not exceed 500 characters; values longer than 500 characters will result in an INVALID_ARGUMENT error.

Response body

Response message for DeveloperKnowledge.AnswerQuery.

If successful, the response body contains data with the following structure:

JSON representation
{
  "answer": {
    object (Answer)
  }
}
Fields
answer

object (Answer)

The answer to the query.

Authorization scopes

Requires one of the following OAuth scopes:

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

For more information, see the OAuth 2.0 Overview.

Answer

An answer to a query.

JSON representation
{
  "answerText": string,
  "citations": [
    {
      object (AnswerCitation)
    }
  ],
  "references": [
    {
      object (AnswerReference)
    }
  ]
}
Fields
answerText

string

Contains the text of the answer.

citations[]

object (AnswerCitation)

Output only. Contains citations for the answer.

references[]

object (AnswerReference)

Output only. Contains references for the answer.

AnswerCitation

Citation info for a segment.

JSON representation
{
  "startIndex": integer,
  "endIndex": integer,
  "sources": [
    {
      object (CitationSource)
    }
  ]
}
Fields
startIndex

integer

Output only. Indicates the start of the segment, measured in bytes (UTF-8 unicode), inclusive. If there are multi-byte characters, such as non-ASCII characters, the index measurement is longer than the string length.

endIndex

integer

Output only. Indicates the end of the segment, measured in bytes (UTF-8 unicode), exclusive. If there are multi-byte characters, such as non-ASCII characters, the index measurement is longer than the string length.

sources[]

object (CitationSource)

Output only. Contains citation sources for the attributed segment.

CitationSource

Citation source.

JSON representation
{
  "referenceIndex": integer
}
Fields
referenceIndex

integer

Output only. Contains the index of the Answer.AnswerReference in the references repeated field.

AnswerReference

Represents a reference to a source.

JSON representation
{

  // Union field content can be only one of the following:
  "documentReference": {
    object (DocumentReference)
  }
  // End of list of possible types for union field content.
}
Fields
Union field content. Contains the content of the reference. content can be only one of the following:
documentReference

object (DocumentReference)

Output only. The reference document.

DocumentReference

Represents a reference to a document.

JSON representation
{
  "documentChunk": {
    object (DocumentChunk)
  }
}
Fields
documentChunk

object (DocumentChunk)

Output only. Contains the document chunk. The documentChunk.id field is not set and will be empty.