
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
The Cloud Retail service and the Retail API enable customers to build end-to-end personalized recommendation systems without requiring a high level of expertise in machine learning, recommendation system, or Google Cloud.
In this lab, you will configure Retail Recommendations AI prediction models and serving configs, generate user product recommendations using the Retail Recommendations AI console and API, and upload user event data that includes Recommendations AI attribution tokens to improve Recommendations AI prediction model performance.
This lab uses the Retail product catalog and event data you imported in a previous lab. This catalog data was created using Google Merchant Center data.
In this lab, you will learn how to complete the following tasks:
For each lab, you get a new Google Cloud project and set of resources for a fixed time at no cost.
Sign in to Qwiklabs using an incognito window.
Note the lab's access time (for example, 1:15:00
), and make sure you can finish within that time.
There is no pause feature. You can restart if needed, but you have to start at the beginning.
When ready, click Start lab.
Note your lab credentials (Username and Password). You will use them to sign in to the Google Cloud Console.
Click Open Google Console.
Click Use another account and copy/paste credentials for this lab into the prompts.
If you use other credentials, you'll receive errors or incur charges.
Accept the terms and skip the recovery resource page.
While in Google Cloud you can operate Google Cloud remotely from your own machine. This lab uses both the Google Cloud Console and the Cloud Shell, a command line environment running in Google Cloud.
From the Cloud Console, click Activate Cloud Shell.
Here's what that one-time screen looks like:
It should only take a few moments to provision and connect to Cloud Shell.
Cloud Shell provides you with terminal access to a virtual machine hosted in the cloud. The virtual machine includes all the development tools that you'll need. It offers a persistent 5GB home directory and runs in Google Cloud, greatly enhancing network performance and authentication. Much, if not all, of your work in this lab can be done through the Cloud Console and Cloud Shell using only a browser.
Once connected to Cloud Shell, you should see that you are already authenticated and that the project is already set to your project ID.
Run the following command in Cloud Shell to confirm that you are authenticated:
Output:
To set the active account, run:
Run the following command to confirm that you are using the correct project for this lab:
Output:
If the correct project is not listed, you can set it with this command:
Output:
Before you can begin using the Retail Recommendations AI or Retail Search APIs, you must enable the Retail API.
On the Google Cloud console title bar, in the Search field, type Search for Retail, click Search, and then click Search for Retail.
Click Turn On API.
Click Continue and accept the data terms by clicking Accept.
Click Continue.
Click on Turn On to turn on the Retail Search.
Click Get Started.
In this task, you will import product catalog data from BigQuery and user event data from Cloud Storage.
In this task, import product data into the catalog from a BigQuery table that uses the Retail products schema.
In the Search for Retail console, select Data from the left-hand side menu to open the Retail Data management page.
Make sure the Catalog tab is selected and click Import.
Configure the import parameters as follows to import the product catalog:
For Big Query table, click Browse.
Enter products in the search box and click Search.
Select the radio button for products Dataset: retail table.
Click Select.
Click Import.
You need to wait for a pop-up message to appear with a message similar to the following:
When the import task is scheduled you will also see the details of a gcloud scheduler
command displayed that you can use to schedule a regular data import task.
Click X to close the popup that appeared to tell you that the import operation was successfully scheduled.
Click Cancel to close the import page and return to the Retail Data page to check the status of your catalog data import task.
In the Search for Retail navigation menu, click Data and then click Activity status to monitor the progress of the import task.
The import task will take a minute or two for the status of the import task in the Product catalog import activity section to change to Succeeded. A total of 1268 items will have been imported.
In this task, import user event data from a BigQuery table.
In the Search for Retail console, select Data from the left-hand side menu to open the Retail Data management page.
Make sure the Events tab is selected and click Import.
Configure the import parameters as follows to import the product catalog:
For Google Cloud Storage location, click the Browse button.
Navigate to the storage bucket called recent_retail_events.json
.
Click the Filename to make sure it is selected.
Click Select.
Click Import.
You need to wait for a pop-up message to appear with a message similar to the following:
When the import task is scheduled you will also see the details of a gcloud scheduler
command displayed that you can use to schedule a regular event import task.
Click X to close the popup that appeared to tell you that the import operation was successfully scheduled.
Click Cancel to close the import page and return to the Retail Data page to check the status of your event data import task.
In the Search for Retail navigation menu, click Data and then click Activity status to monitor the progress of the import task.
The import task will take a minute or two for the status of the import task in the User events section to change to Succeeded. Approximately 32,000 items will have been imported and 5 items will have failed.
In this task, you will configure a new Retail Recommendations AI model. Training a model can take a number of days so you will not be able to interact with the model that you configure during the lab session but you can explore how to work with models using the default recently_viewed model that is created automatically for you when the initial batch of event data was imported.
In the Search for Retail navigation menu, click Models.
Click Create model.
For Model name, enter Others you may like
.
For Model type, select Others you may like.
For Business Objective, select Click-through rate (CTR).
Note that in the Data Requirements met? section that you have meet the criteria for this model:
Click Cancel.
The model training process takes a number of days to complete and will not be ready while this lab is running. You should proceed to the next step where you will work with a default model that is already prepared.
You will now create a Serving Config using the default recently_viewed Recommendations AI model. Serving configurations are invoked by your site when surfacing recommendations or search results. The Retail API references the serving configuration's associated model or controls at serving time to determine the recommendations or search results to generate.
In the Search for Retail navigation menu, click Serving configs.
Click Create Serving Config.
In the Select product stage, select the Recommendation product type.
For Serving config name, type Test Recommendation.
The Serving config ID field is automatically filled for you with a default value, test-recommendation. If you change this default you will need to adjust variables in later steps yourself.
Click Continue.
In the Include Model stage, select the Items you recently viewed model.
Click Continue
In the Preferences stage, leave the Price reranking and Result diversification options at their defaults.
Click Create.
Click the Test Recommendation serving config that you have just created.
Click Evaluate tab to open the Recommendations AI evaluation console.
For Visitor ID enter GA1.3.1260529204.1622654859
.
Click Prediction Preview.
You will see a list of product links, and images for those products, that this visitor has recently viewed along with. This is a trivial model that does not provide any real insights but it is used here to demonstrate how to use the console for interactive testing of the results produced by a Recommendations AI serving config.
You will now use curl and other command line utilities to make calls to the Retail Recommendations AI API to explore how to make requests, get recommendations and then filter and refine the results.
Create an environment variable to store the Project ID:
Create an IAM service account for controlled access to the Retail API:
Bind the service account to the Retail Editor IAM role:
Creating a role binding on the service account for the lab user with the Service Account Token Creator role allows the lab user to use service account impersonation to safely generate limited duration authentication tokens for the service account. These tokens can then be used to interactively test access to APIs and services.
Create a role binding on the Retail API service account for your user account to permit impersonation:
Generate a temporary access token for the Retail API:
When calling the Retail Recommendations AI API to make predictions
you need to include some metadata as JSON payload data. The visitorID
identifies the user ID that the recommendations are to be generated for. The request should be accompanied by some user_event detail similar to the example you've seen earlier but can include a lot more data some of which is shown here. Some optional parameters for the Retail Recommendations AI API can also be included. The filter
parameter can be used to identify tags that can refine the recommendations, for example to filter the results for a specific promotion. The validateOnly
parameter instructs the API to perform a dry run test. The experiment_group
parameter can be used to identify groups for A/B testing.
The SERVING_CONFIG_ID
environment variable is used to construct the REST API URL specific Retail Recommendations AI serving config, and therefore the model, that should be used to generate the recommendations.
Store parameters in environment variables:
Store the Retail Recommendations AI prediction payload JSON data in an environment variable:
This payload data will be sent to the Recommendations AI API to generate a set of recommendations. The environment variables you defined in the previous step are substituted for the parameter values in the resulting DATA environment variable.
Store the Recommendations AI API URL for predictions in an environment variable:
This constructs the REST API URL for generating a Recommendations AI API recommendation using the appropriate serving config ID. Note that the URL again has the access token appended as an inline parameter called access_token
.
Call the API storing the results in a variable for reuse:
This will generate a list of Product IDs that correspond to recommendations produced by the recommendation model configured for the serving config ID you provided using the visitor ID, event data, and other parameters to refine the recommendation.
Each Retail Recommendations AI prediction includes an attribution token. You should include this token in user events that result from the recommendation in order to improve the quality of the Retail Recommendations AI model. You will learn how attribution tokens are used by Retail Recommendations AI to improve the performance of recommendation models later in the course.
Parse the Retail Recommendations AI prediction response using JQ to retrieve the attributionToken
:
Parse the Retail Recommendations AI prediction response using JQ to retrieve the product ID for the first recommendation:
Store sample user event JSON data for a detail-page-view
user event for the recommended product including the attribution token that associates this event with the prediction:
Store the REST API URL for writing user event data to your catalog using the Retail API userEvents.write
method in an environment variable:
Upload the user event using the REST API using curl:
The successful event upload results in a JSON response that includes the product details and user event time stamp similar to the following.
Congratulations, you've successfully created Retail Recommendations AI models and worked with recommendations using the Retail API.
When you have completed your lab, click End Lab. Google Cloud Skills Boost removes the resources you’ve used and cleans the account for you.
You will be given an opportunity to rate the lab experience. Select the applicable number of stars, type a comment, and then click Submit.
The number of stars indicates the following:
You can close the dialog box if you don't want to provide feedback.
For feedback, suggestions, or corrections, please use the Support tab.
Copyright 2022 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