Stay organized with collections Save and categorize content based on your preferences.
Handle quota errors by calling ML.GENERATE_TEXT iterativelyThis tutorial shows you how to use the BigQuery bqutil.procedure.bqml_generate_text
public stored procedure to iterate through calls to the ML.GENERATE_TEXT
function. Calling the function iteratively lets you address any retryable errors that occur due to exceeding the quotas and limits that apply to the function.
To review the source code for the bqutil.procedure.bqml_generate_text
stored procedure in GitHub, see bqml_generate_text.sqlx
. For more information about the stored procedure parameters and usage, see the README file.
This tutorial guides you through the following tasks:
gemini-2.0-flash
model.ML.GENERATE_TEXT
function, using the remote model and the bigquery-public-data.bbc_news.fulltext
public data table with the bqutil.procedure.bqml_generate_text
stored procedure.To run this tutorial, you need the following Identity and Access Management (IAM) roles:
roles/bigquery.admin
).roles/resourcemanager.projectIamAdmin
).These predefined roles contain the permissions required to perform the tasks in this document. To see the exact permissions that are required, expand the Required permissions section:
Required permissionsbigquery.datasets.create
bigquery.connections.*
bigquery.config.*
resourcemanager.projects.getIamPolicy
and resourcemanager.projects.setIamPolicy
bigquery.jobs.create
bigquery.models.create
bigquery.models.getData
bigquery.models.updateData
bigquery.models.updateMetadata
You might also be able to get these permissions with custom roles or other predefined roles.
CostsIn this document, you use the following billable components of Google Cloud:
To generate a cost estimate based on your projected usage, use the pricing calculator.
New Google Cloud users might be eligible for a
free trial.
For more information about BigQuery pricing, see BigQuery pricing.
For more information about Vertex AI pricing, see Vertex AI pricing.
Before you beginIn 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.Verify that billing is enabled for your Google Cloud project.
Enable the BigQuery, BigQuery Connection, and Vertex AI APIs.
Create a BigQuery dataset to store your models and sample data:
In the Google Cloud console, go to the BigQuery page.
In the Explorer pane, click your project name.
Click more_vert View actions > Create dataset.
On the Create dataset page, do the following:
For Dataset ID, enter sample
.
For Location type, select Multi-region, and then select US (multiple regions in United States).
Leave the remaining default settings as they are, and click Create dataset.
Create a remote model that represents a hosted Vertex AI gemini-2.0-flash
model:
In the Google Cloud console, go to the BigQuery page.
In the query editor, run the following statement:
CREATE OR REPLACE MODEL `sample.generate_text` REMOTE WITH CONNECTION DEFAULT OPTIONS (ENDPOINT = 'gemini-2.0-flash');
The query takes several seconds to complete, after which the generate_text
model appears in the sample
dataset in the Explorer pane. Because the query uses a CREATE MODEL
statement to create a model, there are no query results.
Run the bqutil.procedure.bqml_generate_text
stored procedure, which iterates through calls to the ML.GENERATE_TEXT
function using the sample.generate_text
model and the bigquery-public-data.bbc_news.fulltext
public data table:
In the Google Cloud console, go to the BigQuery page.
In the query editor, run the following statement:
CALL `bqutil.procedure.bqml_generate_text`( "bigquery-public-data.bbc_news.fulltext", -- source table "PROJECT_ID.sample.news_generated_text", -- destination table "PROJECT_ID.sample.generate_text", -- model "body", -- content column ["filename"], -- key columns '{}' -- optional arguments );
Replace PROJECT_ID
with the project ID of the project you are using for this tutorial.
The stored procedure creates a sample.news_generated_text
table to contain the output of the ML.GENERATE_TEXT
function.
When the query is finished running, confirm that there are no rows in the sample.news_generated_text
table that contain a retryable error. In the query editor, run the following statement:
SELECT * FROM `sample.news_generated_text` WHERE ml_generate_text_status LIKE '%A retryable error occurred%';
The query returns the message No data to display
.
appspot.com
URL, delete selected resources inside the project instead of deleting the whole project.If you plan to explore multiple architectures, tutorials, or quickstarts, reusing projects can help you avoid exceeding project quota limits.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-08-14 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-14 UTC."],[[["This tutorial demonstrates how to use the `bqutil.procedure.bqml_generate_text` stored procedure to iteratively call the `ML.GENERATE_TEXT` function in BigQuery, which is useful for managing quota limits and retryable errors."],["The process involves creating a remote model over a `gemini-1.5-flash-002` model, establishing necessary connections and permissions, and then using the stored procedure to process data from a public dataset."],["Proper permissions, including `bigquery.datasets.create`, `bigquery.connections.create`, and `resourcemanager.projects.setIamPolicy`, are required for creating datasets, connections, and managing service accounts, with additional permissions necessary for model creation and inference."],["Utilizing the `bqutil.procedure.bqml_generate_text` stored procedure results in a table that contains the output of `ML.GENERATE_TEXT`, and this table can be queried to ensure no retryable errors occurred during processing."],["There are costs associated with using BigQuery ML and Vertex AI, and the tutorial provides direction on where to learn more about pricing and how to use the pricing calculator to generate estimates."]]],[]]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4