bqml_vertex_gemini — BigQuery × Vertex Gemini
bqml_vertex_gemini demonstrates how to invoke Vertex AI Gemini models from BigQuery ML remote functions, enabling LLM inference directly on warehouse-scale data without moving it out of BigQuery.
bash setup.sh --project YOUR_PROJECT --location us-central1SELECT GEMINI_GENERATE(description) FROM `project.dataset.products` LIMIT 100Features
Run Vertex AI Gemini LLM API calls directly from within BigQuery ML — no data movement, no external pipelines.
In-Database LLM
Call Gemini from a SQL SELECT statement — no Python, no ETL, no data movement.
Vertex AI Integration
Uses BigQuery ML remote functions to call the Vertex AI API with IAM-based auth.
Massively Parallel
BigQuery's distributed execution engine fans out Gemini calls across millions of rows in parallel.
Demo Included
Complete end-to-end demo: schema, remote function setup, sample queries, and result analysis.
Documentation & Architecture
This project demonstrates how to generate nutrition labels for food products using Google Cloud BigQuery and the Gemini Pro language model through BigQuery ML.
Prerequisites
Before you begin, ensure you have the following:
- Google Cloud Account: You need an active Google Cloud account.
- Google Cloud CLI (gcloud) Installed and Configured: Make sure you have the
gcloudcommand-line tool installed and configured to connect to your Google Cloud account. You can find installation instructions on the official Google Cloud documentation. Ensure you have initialized the CLI usinggcloud init. - BigQuery Enabled: The BigQuery API must be enabled in your Google Cloud project. You can enable it through the Google Cloud Console.
bqCommand-Line Tool: Thebqcommand-line tool, which is part of thegcloudCLI, should be available in your system’s PATH.- Vertex AI API Enabled: The Vertex AI API needs to be enabled in your Google Cloud project. You can enable it through the Google Cloud Console.
- Google Cloud Project:
sandboxportal: This project is specifically configured to use the project IDsandboxportal. Ensure yourgcloudCLI is configured to use this project. You can set the default project usinggcloud config set project sandboxportal. - BigQuery Dataset:
sandboxdataset: A BigQuery dataset namedsandboxdatasetmust exist within yoursandboxportalproject. You can create a dataset using the Google Cloud Console or using thebqcommand:bq mk --dataset sandboxportal:sandboxdataset
Project Files
food_products.csv: Contains the source data for food products (e.g., brand names).genai_food_labels.sql: The BigQuery SQL script that uses theML.GENERATE_TEXTfunction with the Gemini Pro model to generate nutrition labels.LICENSE: Contains the licensing information for the project.load_source.sh: A shell script to load thefood_products.csvfile into thefood_productsBigQuery table.README.md: This file, providing instructions and prerequisites for the project.run_genai_food_labels.sh: A shell script to execute thegenai_food_labels.sqlscript on BigQuery.setup_bqml_vertex.sh: A shell script to set up the BigQuery ML model that uses Vertex AI’s Gemini Pro model.
Running the Project
Follow these steps to run the food label generation project:
Ensure Prerequisites are Met: Verify that you have completed all the prerequisites listed in the Prerequisites section. This includes having a Google Cloud account,
gcloudCLI configured, BigQuery and Vertex AI APIs enabled, thesandboxportalproject set, and thesandboxdatasetcreated.Load Food Product Data: Navigate to the directory containing the project files in your terminal and run the
load_source.shscript. This will load the data fromfood_products.csvinto thefood_productstable in yoursandboxdataset../load_source.shSet Up the BigQuery ML Model (Gemini Pro): Execute the
setup_bqml_vertex.shscript. This script will create the BigQuery ML model (sandboxportal.sandboxdataset.model_cloud_ai_gemini_pro) that uses the Gemini Pro model from Vertex AI../setup_bqml_vertex.sh(Note: Ensure the script content correctly sets up the model.)
Execute the GenAI Query (Generate Food Labels): Run the
run_genai_food_labels.shscript. This script will execute the SQL query ingenai_food_labels.sql, which uses the Gemini Pro model to generate nutrition labels based on the data in thefood_productstable. The results will be stored in thegenai_food_labelstable within yoursandboxdataset../run_genai_food_labels.shVerify the Results: After the
run_genai_food_labels.shscript completes, you can verify the generated food labels by querying thegenai_food_labelstable in the Google Cloud Console or using thebqcommand:bq query --nouse_legacy_sql 'SELECT * FROM `sandboxportal.sandboxdataset.genai_food_labels` LIMIT 10;'
By following these steps in order, you should be able to successfully execute the GenAI query and generate food labels for your products.
Related Projects
More from the Mavgo ecosystem