
Before you begin
- Labs create a Google Cloud project and resources for a fixed time
- Labs have a time limit and no pause feature. If you end the lab, you'll have to restart from the beginning.
- On the top left of your screen, click Start lab to begin
Enable relevant APIs and set IAM roles
/ 10
Create a cloud resource connection
/ 10
Grant IAM permissions to the connection's service account
/ 10
Create the dataset and object table in BigQuery for movie poster images
/ 10
Create the Gemini Remote models in BigQuery
/ 15
Prompt Gemini to provide movie summaries for each poster
/ 20
Generate text embeddings for a subset of the IMDB dataset
/ 25
In this lab, you learn how to use BigQuery Machine Learning for inference with remote models (Gemini AI models) to analyze movie poster images and generate summaries of these posters as part of a Proof of Concept project.
BigQuery is a fully managed, AI-ready data analytics platform that helps you maximize value from your data and is designed to be multi-engine, multi-format, and multi-cloud. One of its key features is BigQuery Machine Learning for inference, which lets you create and run machine learning (ML) models by using GoogleSQL queries.
Gemini is a family of generative AI models developed by Google DeepMind that is designed for multimodal use cases. The Gemini API gives you access to the Gemini Pro Vision and Gemini Pro models.
Usually, performing ML or artificial intelligence (AI) on large datasets requires extensive programming and knowledge of ML frameworks. These requirements restrict solution development to a very small set of people within each company, and they exclude data analysts who understand the data but have limited ML knowledge and programming expertise. However, with BigQuery Machine Learning for inference, SQL practitioners can use existing SQL tools and skills to build models, and generate results from LLMs and Cloud AI APIs.
In this lab, you learn how to:
Read these instructions. Labs are timed and you cannot pause them. The timer, which starts when you click Start Lab, shows how long Google Cloud resources are made available to you.
This hands-on lab lets you do the lab activities in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials you use to sign in and access Google Cloud for the duration of the lab.
To complete this lab, you need:
Click the Start Lab button. If you need to pay for the lab, a dialog opens for you to select your payment method. On the left is the Lab Details pane with the following:
Click Open Google Cloud console (or right-click and select Open Link in Incognito Window if you are running the Chrome browser).
The lab spins up resources, and then opens another tab that shows the Sign in page.
Tip: Arrange the tabs in separate windows, side-by-side.
If necessary, copy the Username below and paste it into the Sign in dialog.
You can also find the Username in the Lab Details pane.
Click Next.
Copy the Password below and paste it into the Welcome dialog.
You can also find the Password in the Lab Details pane.
Click Next.
Click through the subsequent pages:
After a few moments, the Google Cloud console opens in this tab.
In this task, you configure the lab environment, so that you can use the Cloud AI Companion API for Gemini and the Vertex AI Platform API with your project.
Sign in to the Google Cloud console with your lab credentials, and open the Cloud Shell terminal window.
To set your project ID and region environment variables, in Cloud Shell, run the following commands:
To store the signed-in Google user account in an environment variable, run the following command:
Enable the Cloud AI Companion API for Gemini and Vertex AI API:
To use Gemini, grant the necessary IAM roles to your Google Cloud Qwiklabs user account:
Adding these roles lets the user use Gemini assistance.
To verify the objective, click Check my progress.
In this task you create a Cloud Resource connection in BigQuery so that you can work with Gemini Pro and Gemini Pro Vision models.
In the Google Cloud Console, on the Navigation menu, click BigQuery.
Click DONE on the Welcome pop-up.
To create a connection, click + ADD, and then click Connections to external data sources.
In the Connection type list, select Vertex AI remote models, remote functions and BigLake (Cloud Resource).
In the Connection ID field, enter gemini_conn for your connection.
For Location type, select Multi-region and then, from dropdown select US multi-region.
Use the defaults for the other settings.
Click Create connection.
Click GO TO CONNECTION.
In the Connection info pane, copy the service account ID to a text file for use in the next task. You will also see that the connection is added under the External Connections section of your project in the BigQuery Explorer.
Click Check my progress to verify the objective.
In this task, you grant the Cloud Resource connection's service account IAM permissions, through a role, to enable it access the Vertex AI services.
In the Google Cloud console, on the Navigation menu, click IAM & Admin.
Click Grant Access.
In the New principals field, enter the service account ID that you copied earlier.
In the Select a role field, enter Vertex AI, and then select Vertex AI User role.
Click Save.
The result is the service account ID now includes the Vertex AI User role.
Click Check my progress to verify the objective.
In this task, you create a dataset for the project and an object table within it to store the poster images.
In the Google Cloud console, select the Navigation menu (), and then select BigQuery.
In the Explorer panel, for ), and then select Create dataset.
You create a dataset to store database objects, including tables and models.
In the Create dataset pane, enter the following information:
Field | Value |
---|---|
Dataset ID | gemini_demo |
Location type | select Multi-region |
Multi-region | select US |
Leave the other fields at their defaults.
Click Create Dataset.
The result is the gemini_demo dataset is created and listed underneath your project in the BigQuery Explorer.
To create the object table you will use a SQL query.
Click the + to Create new SQL query.
In the query editor, paste the query below.
Run the query.
The result is movie_posters object table is added to the gemini_demo dataset and loaded with the URI (the Cloud Storage location) of each movie poster image.
In the Explorer, click on the movie_posters and review the schema and details. Feel free to query the table to review specific records.
Click Check my progress to verify the objective.
Now that the object table is created, you can begin to work with it. In this task, you create remote models for Gemini Pro and Gemini Pro Vision models in BigQuery.
Click the + to create a new SQL query.
In the query editor, paste the query below and run it.
The result is the gemini_pro model is created and you see it added to the gemini_demo dataset, in the models section.
In the Explorer, click on the gemini_pro model and review the details and schema.
Click the + to Create a new SQL Query.
In the query editor, paste the query below and run it.
The result is the gemini_pro_vision model is created and you see it added to the gemini_demo dataset, in the models section.
In the Explorer, click on the gemini_pro_vision model and review the details and schema.
Click Check my progress to verify the objective.
In this task, you will use Gemini (the Gemini Pro and Vision models you just created) to analyze the movie poster images and generate summaries for each movie.
Click the + to create a new SQL query.
In the query editor, paste the query below, and run it.
The result is the movie_posters_results table is created.
In the Explorer, click on the movie_posters_results table and review the schema and details.
Click the + to create a new SQL query.
In the query editor, paste and run the query below.
The result is rows for each movie poster with the URI (the Cloud Storage location of the movie poster image) and a JSON result including the movie title and the year the movie was released from the Gemini Pro Vision model.
You can retrieve these results in a more human readable way, by using the next query.
Click the + to create a new SQL query.
In the query editor, paste and run the query below.
The result is the movie_posters_result_formatted table is created.
You can query the table with the query below, to see the rows created.
Notice how the URI column results remain the same, but the JSON is now converted to the title and year columns for each row.
You can use Gemini Pro to provide movie summaries for each poster by running the query below.
Notice how the result is similar to the previous query, but now the prompt used with Gemini is displayed in the prompt column and the result of using this prompt is included in the ml_generate_text_llm_result field; this includes a short summary of the movie.
Click Check my progress to verify the objective.
In this task, you will generate text embeddings using a remote model so that you can perform further analysis.
To generate the text embeddings, you will need to use the remote text-multilingual-embedding-002 model hosted on the endpoint and then you can generate the embeddings.
Click the + to create a new SQL query.
In the query editor, paste and run the query below.
The result is the text_embedding model is created and appears in the explorer underneath the gemini_demo dataset.
You will need to create a table to store the results.
Click the + to create a new SQL query.
In the query editor, paste and run the query below.
The result is the movie_poster_results_embeddings table is created containing the results of creating embeddings for the text content (uri, movie title and year released) from the gemini_demo.movie_posters_results_formatted table.
You can view the results of the query using the new query below:
Here you see the embeddings (vectors represented by numbers) for each movie generated by the model.
You will create a new view that contains only the movies in the dataset that were released prior to 1935.
Create and run a new query with the following SQL statement.
The result is a new view containing a list of distinct movie IDs, titles, and year of release from the bigquery-public-data.imdb.reviews table for all movies in the dataset released before 1935.
Create and run a new query with the following SQL statement.
The result of the query is a table that contains the embeddings for the text content of the gemini_demo.imdb_movies table.
Create and run a new query with the following SQL statement.
The query uses the VECTOR_SEARCH function to find the nearest neighbor in the gemini_demo.imdb_movies_embeddings table for each row in the gemini_demo.movie_posters_results_embeddings table. The nearest neighbor is found using the cosine distance metric, which determines how similar two embeddings are.
This query can be used to find the most similar movie in the IMDB dataset for each of the movies identified by Gemini Pro Vision in the movie posters. For example, you could use this query to find the closest match for the movie "Au Secours!" (identified by Gemini Pro Vision in one of the movie posters) in the IMDB public dataset, which references this movie by its English-language title, "Help!".
Create and run a new query to join some additional information on movie ratings provided in the IMDB public dataset.
This query is similar to the previous query. It still uses special numerical representations called vector embeddings to find similar movies to a given movie poster. However, it also joins the average rating and number of votes for each nearest neighbor movie from a separate table from the IMDB public dataset.
Click Check my progress to verify the objective.
You successfully created an object table for your poster images in BigQuery, created remote Gemini models, used the models to prompt Gemini to analyze images and provided movie summaries, generated text embeddings for movie titles, and used embeddings to match movie poster images to the related movie title in the IMDB dataset.
...helps you make the most of Google Cloud technologies. Our classes include technical skills and best practices to help you get up to speed quickly and continue your learning journey. We offer fundamental to advanced level training, with on-demand, live, and virtual options to suit your busy schedule. Certifications help you validate and prove your skill and expertise in Google Cloud technologies.
Manual Last October 4, 2024
Lab Last Tested May 23, 2024
Copyright 2025 Google LLC All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.
This content is not currently available
We will notify you via email when it becomes available
Great!
We will contact you via email if it becomes available
One lab at a time
Confirm to end all existing labs and start this one