This guide provides examples of how to use the functions of the Developer Knowledge API: searching for documents, retrieving a single document, and retrieving multiple documents in a batch.
Before you begin, make sure you have enabled the API and generated a Developer Knowledge API key, and save your key to an environment variable:
export DEVELOPERKNOWLEDGE_API_KEY="YOUR_API_KEY"
Search for documents with SearchDocumentChunks
Use the documents.searchDocumentChunks
method to find document chunks that match a query string. The results include
chunks of content from the document and a parent reference that you can use
to retrieve the full document content.
The following example searches for documents matching "BigQuery":
curl "https://developerknowledge.googleapis.com/v1/documents:searchDocumentChunks?query=BigQuery&key=$DEVELOPERKNOWLEDGE_API_KEY"
You can refine search results using parameters like pageSize to limit the
number of results per page and pageToken to retrieve subsequent pages.
Filter search results
Use the filter parameter to apply a strict filter to the search results. The
filter is applied to the metadata of the documents associated with the search
result chunks.
Supported fields for filtering:
data_source(STRING): The source of the document, for example,docs.cloud.google.com.update_time(TIMESTAMP): The timestamp of when the document was last updated.uri(STRING): The document URI, e.g.,https://docs.cloud.google.com/bigquery/docs/tables.
Supported operators:
- STRING fields support
=(equals) and!=(not equals) for exact matches on the whole string. - TIMESTAMP fields support
=,<,<=,>, and>=. 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. Note that OR has higher precedence than AND.
The following example searches for documents matching "BigQuery" and restricts
results to those from docs.cloud.google.com:
curl "https://developerknowledge.googleapis.com/v1/documents:searchDocumentChunks?query=BigQuery&filter=data_source%3D%22docs.cloud.google.com%22&key=$DEVELOPERKNOWLEDGE_API_KEY"
Retrieve a document with GetDocument
Use the documents.get
method to retrieve the full content of a single document.
The following example retrieves a document with the name
documents/DOCUMENT_ID:
curl "https://developerknowledge.googleapis.com/v1/documents:get?name=documents/DOCUMENT_ID&key=$DEVELOPERKNOWLEDGE_API_KEY"
The response is the full
Document
resource, including the content field.
Retrieve multiple documents with BatchGetDocuments
Use the documents.batchGet
method to retrieve up to 100 documents by name in a single API call. This is
more efficient than making multiple GetDocument requests.
The following example retrieves two documents by name:
curl "https://developerknowledge.googleapis.com/v1/documents:batchGet?names=documents/DOCUMENT_ID_1&names=documents/DOCUMENT_ID_2&key=$DEVELOPERKNOWLEDGE_API_KEY"
The response contains a list of the requested
Document
resources.