The CREATE MODEL statement for remote models over Cloud AI services

This document describes the CREATE MODEL statement for creating remote models in BigQuery over Cloud AI services. For example, the Cloud Natural Language API.

CREATE MODEL syntax

{CREATE MODEL | CREATE MODEL IF NOT EXISTS | CREATE OR REPLACE MODEL}
`project_id.dataset.model_name`
REMOTE WITH CONNECTION `project_id.region.connection_id`
OPTIONS(REMOTE_SERVICE_TYPE = remote_service_type
[, DOCUMENT_PROCESSOR = document_processor]
[, SPEECH_RECOGNIZER = speech_recognizer]
);

CREATE MODEL

Creates and trains a new model in the specified dataset. If the model name exists, CREATE MODEL returns an error.

CREATE MODEL IF NOT EXISTS

Creates and trains a new model only if the model doesn't exist in the specified dataset.

CREATE OR REPLACE MODEL

Creates and trains a model and replaces an existing model with the same name in the specified dataset.

model_name

The name of the model you're creating or replacing. The model name must be unique in the dataset: no other model or table can have the same name. The model name must follow the same naming rules as a BigQuery table. A model name can:

model_name is not case-sensitive.

If you don't have a default project configured, then you must prepend the project ID to the model name in the following format, including backticks:

`[PROJECT_ID].[DATASET].[MODEL]`

For example, `myproject.mydataset.mymodel`.

REMOTE WITH CONNECTION

Syntax

`[PROJECT_ID].[LOCATION].[CONNECTION_ID]`

BigQuery uses a Cloud resource connection to interact with the Cloud AI service.

The connection elements are as follows:

You need to grant the Vertex AI User role to the connection's service account in the project where you create the model.

Example

`myproject.us.my_connection`

REMOTE_SERVICE_TYPE

Syntax

REMOTE_SERVICE_TYPE = { 'CLOUD_AI_NATURAL_LANGUAGE_V1' | 'CLOUD_AI_TRANSLATE_V3' | 'CLOUD_AI_VISION_V1' | 'CLOUD_AI_DOCUMENT_V1' | 'CLOUD_AI_SPEECH_TO_TEXT_V2' }

Description

Specifies the service to use to create the model:

After you create a remote model based on a Cloud AI service, you can use the model with one of the following BigQuery ML functions to analyze your BigQuery data:

Example

REMOTE_SERVICE_TYPE = 'CLOUD_AI_VISION_V1'

DOCUMENT_PROCESSOR

This option identifies the document processor to use when the REMOTE_SERVICE_TYPE value is CLOUD_AI_DOCUMENT_V1. You must use this option when creating a remote model over the Document AI API. You can't use this option with any other type of remote model.

A document processor from Document AI should exist when you specify this option to create the model in BigQuery. You can create a document processor supported by BigQuery in 2 ways:

The CREATE MODEL statement fails if you specify an unsupported processor, or if the processor isn't enabled.

The DOCUMENT_PROCESSOR value must be a string in the following format:

projects/PROJECT_NUMBER/locations/LOCATION/processors/PROCESSOR_ID/processorVersions/PROCESSOR_VERSION

Replace the following:

SPEECH_RECOGNIZER

This option identifies the speech recognizer to optionally use when the REMOTE_SERVICE_TYPE value is CLOUD_AI_SPEECH_TO_TEXT_V2. If you don't specify this option, you must specify a value for the recognition_config argument of the ML.TRANSCRIBE function if you reference the remote model. You can't use this option with any other type of remote model.

The SPEECH_RECOGNIZER value must be a string in the following format:

projects/PROJECT_NUMBER/locations/LOCATION/recognizers/RECOGNIZER_ID

Replace the following:

Example

The following example creates a BigQuery ML remote model that uses the Cloud Vision API:

CREATE MODEL `project_id.mydataset.mymodel`
REMOTE WITH CONNECTION `myproject.us.test_connection`
 OPTIONS(REMOTE_SERVICE_TYPE = 'CLOUD_AI_VISION_V1')

What's next

For more information about Generative AI in BigQuery ML, see Generative AI overview.