Make predictions with remote models on Vertex AI Stay organized with collections Save and categorize content based on your preferences.
In this tutorial, you register a Vertex AI endpoint as a remote modelin BigQuery. Then, you use theML.PREDICT function to makepredictions using the remote model.
You can use remote models when a model is too large to import intoBigQuery. They are also useful when you want to have a singlepoint of inference for online, batch, and micro-batch use cases.
Note: For a version of this tutorial that uses Python in a BigQuerynotebook, see theBQML Remote Model Tutorial in GitHub.Objectives
- Import a pretrained TensorFlow model into the Vertex AIModel Registry.
- Deploy the model to a Vertex AI endpoint.
- Create a Cloud resource connection.
- Use the
CREATE MODELstatement to create a remote model inBigQuery. - Use the
ML.PREDICTfunction to make predictions with the remote model.
Costs
In this document, you use the following billable components of Google Cloud:
To generate a cost estimate based on your projected usage, use thepricing calculator.
When you finish the tasks that are described in this document, you can avoid continued billing by deleting the resources that you created. For more information, seeClean up.
Before you begin
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Note: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
- Create a project: To create a project, you need the Project Creator role (
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission.Learn how to grant roles.
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Note: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
- Create a project: To create a project, you need the Project Creator role (
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission.Learn how to grant roles.
Verify that billing is enabled for your Google Cloud project.
Enable the BigQuery, Vertex AI, Cloud Storage, and BigQuery Connection APIs.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission.Learn how to grant roles.- Ensure that you have thenecessary permissions to perform the tasks in this document.
Required roles
If you create a new project, you are the project owner, and you are granted allof the required IAM permissions that you need to complete thistutorial.
If you are using an existing project do the following.
Make sure that you have the following role or roles on the project:
- BigQuery Studio Admin (
roles/bigquery.studioAdmin) - Vertex AI User (
roles/aiplatform.user) - BigQuery Connection Admin (
roles/bigquery.connectionAdmin)
Check for the roles
In the Google Cloud console, go to theIAM page.
Go to IAM- Select the project.
In thePrincipal column, find all rows that identify you or a group that you're included in. To learn which groups you're included in, contact your administrator.
- For all rows that specify or include you, check theRole column to see whether the list of roles includes the required roles.
Grant the roles
In the Google Cloud console, go to theIAM page.
Go to IAM- Select the project.
- ClickGrant access.
In theNew principals field, enter your user identifier. This is typically the email address for a Google Account.
- In theSelect a role list, select a role.
- To grant additional roles, clickAdd another role and add each additional role.
- ClickSave.
For more information about IAM permissions in BigQuery,seeBigQuery permissions.
Import the model to the Vertex AI Model Registry
In this tutorial you use a pretrained TensorFlow model that isavailable in Cloud Storage atgs://cloud-samples-data/bigquery/ml/remote_model_tutorial/. TheCloud Storage bucket is in theUS multi-region location.
The model is a TensorFlow model that's namedsaved_model.pb. It is acustomized sentiment analysis model that was created by fine-tuning a BERT modelwith plain text IMDB movie reviews. The model uses text input from the moviereviews and returns sentiment scores between zero and one. When you import themodel into the Model Registry, you use a prebuilt TensorFlowcontainer.
Follow these steps to import the model.
In the Google Cloud console, go to the Vertex AIModelRegistry page.
ClickImport.
ForStep one: Name and region, do the following:
SelectImport as new model.
ForName, enter
bert_sentiment.ForDescription, enter
BQML tutorial model.ForRegion, select
us-central1. You must choose a US-based regionbecause the Cloud Storage bucket is in theUSmulti-regionlocation.ClickContinue.
ForStep two: Model settings, do the following:
SelectImport model artifacts into a new prebuilt container.
In thePrebuilt container settings section, do the following:
ForModel framework, chooseTensorFlow.
ForModel framework version, choose2.15.
ForAccelerator type, chooseGPU.
ForModel artifact location, enter
gs://cloud-samples-data/bigquery/ml/remote_model_tutorial/.Leave the default values for all remaining options and clickImport.
After the import is complete, your model appears on theModel Registry page.
Deploy the model to a Vertex AI endpoint
Follow these steps to deploy the model to an endpoint.
In the Google Cloud console go to the Vertex AIModelRegistry page.
In theName column, click
bert_sentiment.Click theDeploy & Test tab.
ClickDeploy to endpoint.
For step one,Define your endpoint, do the following:
ClickCreate new endpoint.
ForEndpoint name, enter
bert sentiment endpoint.Leave the remaining default values and clickContinue.
For step two,Model settings, do the following:
In theCompute settings section, forMinimum number of computenodes, enter
Note: In production, you should set the maximum number of compute nodes.This option turns on the autoscaling capability in Vertex AI,and it allows the endpoint to process more requests when yourBigQuery table has a large number of rows.1. This is the number of nodes that need to beavailable to the model at all times.In theAdvanced scaling options section, forMachine type,chooseStandard (n1-standard-2). Because you chose GPU as theaccelerator type when you imported the model, after you choose themachine type, the accelerator type and accelerator count are setautomatically.
Leave the remaining default values and clickDeploy.
When the model is deployed to the endpoint, the status changes to
Active.Copy the numeric endpoint ID in theID column and the value in theRegion column. You'll need them later.
Create a dataset
Create a BigQuery dataset to store your ML model.
Console
In the Google Cloud console, go to theBigQuery page.
In theExplorer pane, click your project name.
ClickView actions > Create dataset
On theCreate dataset page, do the following:
ForDataset ID, enter
bqml_tutorial.ForLocation type, selectMulti-region, and then selectUS (multiple regions in United States).
Leave the remaining default settings as they are, and clickCreate dataset.
bq
To create a new dataset, use thebq mk commandwith the--location flag. For a full list of possible parameters, see thebq mk --dataset commandreference.
Create a dataset named
bqml_tutorialwith the data location set toUSand a description ofBigQuery ML tutorial dataset:bq --location=US mk -d \ --description "BigQuery ML tutorial dataset." \ bqml_tutorial
Instead of using the
--datasetflag, the command uses the-dshortcut.If you omit-dand--dataset, the command defaults to creating adataset.Confirm that the dataset was created:
bqls
API
Call thedatasets.insertmethod with a defineddataset resource.
{"datasetReference":{"datasetId":"bqml_tutorial"}}
BigQuery DataFrames
Before trying this sample, follow the BigQuery DataFrames setup instructions in theBigQuery quickstart using BigQuery DataFrames. For more information, see theBigQuery DataFrames reference documentation.
To authenticate to BigQuery, set up Application Default Credentials. For more information, seeSet up ADC for a local development environment.
importgoogle.cloud.bigquerybqclient=google.cloud.bigquery.Client()bqclient.create_dataset("bqml_tutorial",exists_ok=True)Create a BigQuery Cloud resource connection
You must have a Cloud resource connection to connect to a Vertex AIendpoint.
Console
Go to theBigQuery page.
In the left pane, clickExplorer:

If you don't see the left pane, clickExpand left pane to open the pane.
In theExplorer pane, clickAdd data.
TheAdd data dialog opens.
In theFilter By pane, in theData Source Type section, selectDatabases.
Alternatively, in theSearch for data sources field, you can enter
Vertex AI.In theFeatured data sources section, clickVertex AI.
Click theVertex AI Models: BigQuery Federation solution card.
In theConnection type list, selectVertex AI remote models,remote functions and BigLake (Cloud Resource).
In theConnection ID field, enter
bqml_tutorial.Verify thatMulti-region—US is selected.
ClickCreate connection.
At the bottom of the window, clickGo to connection. Alternatively, intheExplorer pane, clickConnections, and then click
us.bqml_tutorial.In theConnection info pane, copy the Service account ID. You needthis ID when you configure permissions for the connection. When you createa connection resource, BigQuery creates a unique systemservice account and associates it with the connection.
bq
Create a connection:
bqmk--connection--location=US--project_id=PROJECT_ID\--connection_type=CLOUD_RESOURCEbqml_tutorial
Replace
PROJECT_IDwith yourGoogle Cloud project ID. The--project_idparameter overrides thedefault project.When you create a connection resource, BigQuery creates aunique system service account and associates it with the connection.
Troubleshooting: If you get the following connection error,update the Google Cloud SDK:
Flags parsing error: flag --connection_type=CLOUD_RESOURCE: value should be one of...
Retrieve and copy the service account ID for use in a laterstep:
bqshow--connectionPROJECT_ID.us.bqml_tutorial
The output is similar to the following:
name properties1234.REGION.CONNECTION_ID {"serviceAccountId": "connection-1234-9u56h9@gcp-sa-bigquery-condel.iam.gserviceaccount.com"}
Set up connection access
Grant the Vertex AI User role to the Cloud resource connection's serviceaccount. You must grant this role in the same project where you created theremote model endpoint.
Note: If the connection is in a different project, this error is returned:bqcx-1234567890-xxxx@gcp-sa-bigquery-condel.iam.gserviceaccount.com does not have the permission to accessresource.To grant the role, follow these steps:
Go to theIAM & Admin page.
ClickGrant Access.
In theNew principals field, enter the Cloud resource connection'sservice account ID that you copied previously.
In theSelect a role field, chooseVertex AI, and then selectVertex AI User.
ClickSave.
Create a BigQuery ML remote model
You create a BigQuery ML remote model by using theCREATE MODELstatement with theREMOTE WITH CONNECTION clause. For more information ontheCREATE MODEL statement, seeThe CREATE MODEL statement for remote modelsover custom models.
You create your model in theUS multi-region location. In aBigQuery multi-region (US,EU) dataset, you can only create aremote model that connects to an endpoint deployed in a region within the samemulti-region location (US,EU).
When you create the remote model, you need the endpoint ID that was generatedwhen youdeployed the model to Vertex AI. Also, the input andoutput field names and types need to be exactly same as the Vertex AImodel's input and output. In this example, the input is a textSTRING, and theoutput is anARRAY of typeFLOAT64.
Console
In the Google Cloud console, go to theBigQuery page.
ForCreate new, clickSQL query.
In the query editor, enter this
CREATE MODELstatement, and then clickRun:CREATEORREPLACEMODEL`PROJECT_ID.bqml_tutorial.bert_sentiment`INPUT(textSTRING)OUTPUT(scoresARRAY<FLOAT64>)REMOTEWITHCONNECTION`PROJECT_ID.us.bqml_tutorial`OPTIONS(ENDPOINT='https://us-central1-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/endpoints/ENDPOINT_ID')
Replace the following:
- PROJECT_ID: your project name.
- ENDPOINT_ID: the endpoint ID that you copied previously.
When the operation is complete, you see a message similar to
Successfully created model named bert_sentiment.Your new model appears in theResources panel. Models areindicated by the model icon:
.If you select the new model in theResources panel, informationabout the model appears below theQuery editor.
bq
Create the remote model by entering the following
CREATE MODELstatement:bqquery--use_legacy_sql=false\"CREATEORREPLACEMODEL`PROJECT_ID.bqml_tutorial.bert_sentiment`INPUT(textSTRING)OUTPUT(scoresARRAY<FLOAT64>)REMOTEWITHCONNECTION`PROJECT_ID.us.bqml_tutorial`OPTIONS(ENDPOINT='https://us-central1-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/endpoints/ENDPOINT_ID')"
Replace the following:
- PROJECT_ID: your project name.
- ENDPOINT_ID: the endpoint ID that you copied previously.
After you create the model, verify that the model appears in thedataset:
bq ls -m bqml_tutorial
The output is similar to the following:
IdModelTypeLabelsCreationTime-----------------------------------------------------bert_sentiment28Jan17:39:43
Get predictions usingML.PREDICT
You use theML.PREDICT function to get sentiment predictions from the remotemodel. The input is a text column (review) that contains reviews of moviesfrom thebigquery-public-data.imdb.reviews table.
In this example, 10,000 records are selected and sent for prediction. The remotemodel defaults to a batch size of 128 instances for requests.
Console
In the Google Cloud console, go to theBigQuery page.
In theCreate new section, clickSQL query.
In the query editor, enter this query that uses the
ML.PREDICTfunction, and then clickRun.SELECT*FROMML.PREDICT(MODEL`PROJECT_ID.bqml_tutorial.bert_sentiment`,(SELECTreviewastextFROM`bigquery-public-data.imdb.reviews`LIMIT10000))
The query results should look similar to the following:

bq
Enter this command to run the query that usesML.PREDICT.
bq query --use_legacy_sql=false \'SELECT *FROM ML.PREDICT (MODEL`PROJECT_ID.bqml_tutorial.bert_sentiment`, ( SELECT review as text FROM`bigquery-public-data.imdb.reviews` LIMIT 10000 ))'
Clean up
To avoid incurring charges to your Google Cloud account for the resources used in this tutorial, either delete the project that contains the resources, or keep the project and delete the individual resources.
Delete the project
Console
gcloud
Delete individual resources
Alternatively, to remove the individual resources used in this tutorial:
What's next
- For an overview of BigQuery ML, seeIntroduction toAI and ML in BigQuery ML.
- For more information about using the
CREATE MODELstatement forremote models, seeThe CREATE MODEL statement forremote models over custom models. - For more information on using a BigQuery notebook, seeIntroduction to notebooks.
- For more information about BigQuery regions andmulti-regions, see theSupported locations page.
- To learn more about importing models in Vertex AI Model Registry,seeImport models to Vertex AI.
- To learn more about model versioning in Vertex AI Model Registry,seeModel versioning with Model Registry.
- For information on using Vertex AI VPC Service Controls, seeVPC Service Controls with Vertex AI.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-15 UTC.