
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 enables 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 Search, perform searches using the Retail Search API using the console and the command line, and then modify search behaviour using Retail Search Boost/Bury controls.
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 Navigation menu (), click View All Products, then in the Artificial Intelligence 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 navigation menu, click Data 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.
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 Cancel to close the import page and return to the Retail Data page to check the status of your catalog data import task.
Click X to close the popup that appeared to tell you that the import operation was successfully scheduled.
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 and purge activity status 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 navigation menu, click Data 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.
Wait for the import task to be scheduled with the gcloud scheduler
command displayed.
Click Cancel to close the import page and return to the Retail Data page to check the status of your event data import task.
Click X to close the popup that appeared to tell you that the import operation was successfully scheduled.
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 > Import activity status section to change to Succeeded. Approximately 32,000 items will have been imported and 5 items will have failed.
You will now create a Retail API serving config for Retail Search.
In the Search for Retail navigation menu, click Serving configs.
Click Create Serving Config.
In the Select product stage, select the Search and Browse product type.
For Serving config name, type Test search config.
The Serving config ID field is automatically filled for you with a default value, test-search-config. If you change this default you will need to adjust variables in later steps yourself.
Click Continue.
Click Create to create the Test search config serving config.
You will now see the new serving config listed below the Recently Viewed (Default) default recommendation serving config.
You will now explore the search results and experiment with the search syntax.
In the Search for Retail navigation menu, click Evaluate.
Navigate to Search tab.
Select Test search config from the Select serving config dropdown.
Leave the Select Branch selection set to Branch 0 (Default).
For Search Query, type Android and click Search Preview.
You will see search results containing items from the catalog that match a search for Android. Note that the search results include wearable items from the Apparel category.
You will now create a Boost/Bury control that will modify search results.
In the Search for Retail navigation menu, click Controls.
Click Create Control.
For Control name, type Test control ID.
For Product selection select Search option.
For Control Type, select Boost/bury controls and click Continue.
Type android for Partial match query terms and Exact match query terms. Click Continue.
In Boost/bury product field select Advanced Editor and copy in the following query string in rule section:
Drag the Boost value slider across until the Boost/bury value is set to 1.
Click Continue.
Click Apply to serving configs and select Test search config.
If you used a different name for your Retail Search serving config in a previous step then select that serving config name.
Click Continue.
Click Submit.
In the Search for Retail navigation menu, click Evaluate and navigate to Search tab.
Select Test search config from the Select serving config dropdown.
Leave the Select Branch selection set to Branch 0 (Default).
For Search Query, type Android and click Search Preview.
You will see search results containing items from the catalog that match a search for Android but the list of results now lists items from the Drinkware and Accessories categories ahead of the items in the Apparel categories.
You will now use curl and other command line utilities to make calls to the Retail API to explore how to make requests, get results and then filter and refine the results.
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.
When making a search request to the Retail API you need to include some metadata as JSON formatted payload data. To make it easier to modify this JSON object later you will use environment variables to store the parameters.
The VISITOR_ID
identifies the user that the results should be tailored for.
The SERVING_CONFIG_ID
identifies the specific Retail API Search serving config that should be used to generate the search results. The serving config is referred to as the placements resource in the API and contains the ID for the serving config you created earlier.
The QUERY_STRING
variable contains the query string that is passed to the search API and the PAGE_SIZE
variable is used to control the pagination of the results.
The full resource name for the placement resource, that includes the serving config ID, must be included in the request.
Note that the URL includes the desired serving config and again has the access token appended as an inline parameter called access_token
.
This will generate a list of Product IDs returned by the search model configured for the serving config you specified using the visitor ID, event data, and other parameters to refine the search result.
nextPagetoken
:Each page of results includes the nextPageToken
property to allow controlled delivery of search results.
nextPageToken
property:You can see from the output that the results are different for the request with the nextPageToken
defined.
Congratulations, you've successfully created a Retail Search Serving Config and used the Retail API to work with Retail Search.
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