Update model metadata

This page shows you how to update BigQuery ML model metadata. You canupdate model metadata by:

  • Using the Google Cloud console.
  • Using thebq update command in the bq command-line tool.
  • Calling themodels.patchAPI method directly or by using the client libraries.

The following model metadata can be updated:

  • Description: Can be updated by using theGoogle Cloud console, bq command-line tool, API, or client libraries.
  • Labels: Can be updated by using the Google Cloud console,bq command-line tool, API, or client libraries.
  • Expiration time: Can be updated by using the bq tool,API, or client libraries.

Required permissions

To update model metadata, you must be assigned theWRITERrole on the dataset, or you must be assigned a project-level Identity and Access Management (IAM) role thatincludesbigquery.models.updateMetadata permissions. If you are grantedbigquery.models.updateMetadata permissions at the project level, you canupdate metadata for models in any dataset in the project. The followingpredefined, project-level IAM roles includebigquery.models.updateMetadatapermissions:

  • bigquery.dataEditor
  • bigquery.dataOwner
  • bigquery.admin

For more information on IAM roles and permissions in BigQuery ML,seeAccess control.

Update a model's description

A model's description is a text string that is used to identify themodel.

To update a model's description:

Console

  1. In the Google Cloud console, go to the BigQuery page.

    Go to the BigQuery page

  2. In the left pane, clickExplorer:

    Highlighted button for the Explorer pane.

    If you don't see the left pane, clickExpand left pane to open the pane.

  3. In theExplorer pane, expand your project, clickDatasets, andthen click the dataset.

  4. Click theModels tab, and then click a model nameto select the model.

  5. Click theDetails tab.

  6. To update the model's description, clickEdit.

  7. In theEdit detail dialog, update the description and thenclickSave.

bq

To update a model's description, issue thebq update command with the--model or-m flag and the--description flag.

If you are updating a model in a project other than your default project,add the project ID to the dataset in the following format:[PROJECT_ID]:[DATASET].

bq update --model --description "[STRING]"PROJECT_ID:DATASET.MODEL

Replace the following:

  • STRING is the text string that describes your model in quotes.
  • PROJECT_ID is your project ID.
  • DATASET is the name of the dataset.
  • MODEL is the name of the model.

The command output looks like the following:

Model 'myproject.mydataset.mymodel' successfully updated.

You can confirm your changes by issuing thebq show command. For moreinformation, seeGet model metadata.

Examples:

Enter the following command to update the description ofmymodel inmydataset in your default project.

bq update --model --description "My updated description" \mydataset.mymodel

Enter the following command to update the description ofmymodel inmydataset inmyotherproject.

bq update --model --description "My updated description" \myotherproject:mydataset.mymodel

API

To update a model's description by using the API, call themodels.patchmethod and provide theprojectId,datasetId, andmodelId. To modifythe description, add to or update the "description" property for themodel resource.

Go

Before trying this sample, follow theGo setup instructions in theBigQuery quickstart using client libraries. For more information, see theBigQueryGo API reference documentation.

To authenticate to BigQuery, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.

import("context""fmt""cloud.google.com/go/bigquery")// updateModelDescription demonstrates fetching BigQuery ML model metadata and updating the// Description metadata.funcupdateModelDescription(projectID,datasetID,modelIDstring)error{// projectID := "my-project-id"// datasetID := "mydataset"// modelID := "mymodel"ctx:=context.Background()client,err:=bigquery.NewClient(ctx,projectID)iferr!=nil{returnfmt.Errorf("bigquery.NewClient: %w",err)}deferclient.Close()model:=client.Dataset(datasetID).Model(modelID)oldMeta,err:=model.Metadata(ctx)iferr!=nil{returnfmt.Errorf("couldn't retrieve model metadata: %w",err)}update:=bigquery.ModelMetadataToUpdate{Description:"This model was modified from a Go program",}if_,err=model.Update(ctx,update,oldMeta.ETag);err!=nil{returnfmt.Errorf("couldn't update model: %w",err)}returnnil}

Java

Before trying this sample, follow theJava setup instructions in theBigQuery quickstart using client libraries. For more information, see theBigQueryJava API reference documentation.

To authenticate to BigQuery, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.

importcom.google.cloud.bigquery.BigQuery;importcom.google.cloud.bigquery.BigQueryException;importcom.google.cloud.bigquery.BigQueryOptions;importcom.google.cloud.bigquery.Model;importcom.google.cloud.bigquery.ModelId;// Sample to update description on a modelpublicclassUpdateModelDescription{publicstaticvoidrunUpdateModelDescription(){// TODO(developer): Replace these variables before running the sample.StringdatasetName="MY_DATASET_NAME";StringmodelName="MY_MODEL_NAME";StringnewDescription="A really great model.";updateModelDescription(datasetName,modelName,newDescription);}publicstaticvoidupdateModelDescription(StringdatasetName,StringmodelName,StringnewDescription){try{// Initialize client that will be used to send requests. This client only needs to be created// once, and can be reused for multiple requests.BigQuerybigquery=BigQueryOptions.getDefaultInstance().getService();Modelmodel=bigquery.getModel(ModelId.of(datasetName,modelName));bigquery.update(model.toBuilder().setDescription(newDescription).build());System.out.println("Model description updated successfully to "+newDescription);}catch(BigQueryExceptione){System.out.println("Model description was not updated \n"+e.toString());}}}

Node.js

Before trying this sample, follow theNode.js setup instructions in theBigQuery quickstart using client libraries. For more information, see theBigQueryNode.js API reference documentation.

To authenticate to BigQuery, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.

// Import the Google Cloud client libraryconst{BigQuery}=require('@google-cloud/bigquery');constbigquery=newBigQuery();asyncfunctionupdateModel(){// Updates a model's metadata./**   * TODO(developer): Uncomment the following lines before running the sample   */// const datasetId = "my_dataset";// const modelId = "my__model";constmetadata={description:'A really great model.',};constdataset=bigquery.dataset(datasetId);const[apiResponse]=awaitdataset.model(modelId).setMetadata(metadata);constnewDescription=apiResponse.description;console.log(`${modelId} description:${newDescription}`);}

Python

Before trying this sample, follow thePython setup instructions in theBigQuery quickstart using client libraries. For more information, see theBigQueryPython API reference documentation.

To authenticate to BigQuery, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.

fromgoogle.cloudimportbigquery# Construct a BigQuery client object.client=bigquery.Client()# TODO(developer): Set model_id to the ID of the model to fetch.# model_id = 'your-project.your_dataset.your_model'model=client.get_model(model_id)# Make an API request.model.description="This model was modified from a Python program."model=client.update_model(model,["description"])# Make an API request.full_model_id="{}.{}.{}".format(model.project,model.dataset_id,model.model_id)print("Updated model '{}' with description '{}'.".format(full_model_id,model.description))

Update a model's labels

Labels are key-value pairs that you can attach to a resource. When you createBigQuery ML resources, labels are optional. For more information, seeAdding and using labels.

To update a model's labels:

Console

  1. In the left pane, clickExplorer:

    Highlighted button for the Explorer pane.

  2. In theExplorer pane, expand your project, clickDatasets, andthen click the dataset.

  3. Click theModels tab, and then click a model nameto select the model.

  4. Click theDetails tab.

  5. To update the model's labels, clickEdit.

  6. In theEdit detail dialog, add, delete, or modify labels, and thenclickSave.

bq

To update a model's labels, issue thebq update command with the--model or-m flag and the--set_label flag. Repeat the--set_labelflag to add or update multiple labels.

If you are updating a model in a project other than your default project,add the project ID to the dataset in the following format:[PROJECT_ID]:[DATASET].

bq update --model --set_labelKEY:VALUE \PROJECT_ID:DATASET.MODEL

Replace the following:

  • KEY:VALUE corresponds to a key:value pair for a label that you wantto add or update. If you specify the same key as an existing label,the value for the existing label is updated. The key must be unique.
  • PROJECT_ID is your project ID.
  • DATASET is the name of the dataset.
  • MODEL is the name of the model.

The command output looks like the following.

Model 'myproject.mydataset.mymodel' successfully updated.

You can confirm your changes by issuing thebq show command. For moreinformation, seeGet model metadata.

Examples:

To update thedepartment label onmymodel, enter thebq update commandand specifydepartment as the label key. For example, to update thedepartment:shipping label todepartment:logistics, enter the followingcommand.mydataset is inmyotherproject, not your default project.

bq update --model --set_label department:logistics \myotherproject:mydataset.mymodel

API

To update a model's labels by using the API, call themodels.patchmethod and provide theprojectId,datasetId, andmodelId. To modifythe labels, add to or update the "labels" property for themodel resource.

Update a model's expiration time

A model's expiration time is a timestamp value that dictates when a model isdeleted. You can set a model's expiration time when the model is created byusing the CLI, the API, or the client libraries. You can also set or update theexpiration time on a model after it is created. A model's expiration time isoften referred to as "time to live" or TTL.

If you don't set an expiration time on a model, the model never expires and youmustdelete the model manually.

Note: Setting or updating the expiration time on a model is notsupported by the Google Cloud console.

The value for the expiration time is expressed differently dependingon where the value is set. Use the method that gives you the appropriatelevel of granularity:

  • In the command-line tool, expiration is expressed in seconds from the currentUTC time. When you specify the expiration on the command line, the integervalue in seconds is added to the current UTC timestamp.
  • In the API, expiration is expressed in milliseconds since the epoch. If youspecify an expiration value that is less than the current timestamp, the modelexpires immediately.

To update the expiration time for a model:

Console

Setting or updating the expiration time on a model is notsupported by the Google Cloud console.

bq

To update a model's expiration time, issue thebq update command with the--model or-m flag and the--expiration flag.

If you are updating a model in a project other than your default project,add the project ID to the dataset in the following format:[PROJECT_ID]:[DATASET].

bq update --model --expirationINTEGER \PROJECT_ID:DATASET.MODEL

Replace the following:

  • INTEGER is the lifetime (in seconds) for the model. Theminimum value is 3600 seconds (one hour). The expiration timeevaluates to the current UTC time plus the integer value.
  • PROJECT_ID is your project ID.
  • DATASET is the name of the dataset.
  • MODEL is the name of the model.

The command output looks like the following.

Model 'myproject.mydataset.mymodel' successfully updated.

You can confirm your changes by issuing thebq show command. For moreinformation, seeGet model metadata.

Examples:

Enter the following command to update the expiration time ofmymodel inmydataset to 5 days (432000 seconds).mydataset is in your defaultproject.

bq update --model --expiration 432000 mydataset.mymodel

Enter the following command to update the expiration time ofmymodel inmydataset to 5 days (432000 seconds).mydataset is inmyotherproject,not your default project.

bq update --model --expiration 432000 myotherproject:mydataset.mymodel

API

To update a model's expiration by using the API, call themodels.patchmethod and provide theprojectId,datasetId, andmodelId. To modifythe expiration, add to or update the "expirationTime" property for themodel resource."expirationTime" is expressed in milliseconds since the epoch.

What's next

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.