
准备工作
- 实验会创建一个 Google Cloud 项目和一些资源,供您使用限定的一段时间
- 实验有时间限制,并且没有暂停功能。如果您中途结束实验,则必须重新开始。
- 在屏幕左上角,点击开始实验即可开始
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 order to use the Retail API product recommendations and product search services you must create or import product catalog data and user event data related to that catalog.
In this lab, you will prepare an environment for the Retail Recommendations AI and Product Search services by uploading product catalog and user event data using a variety of techniques. You will explore some common data ingestion errors, and examine Retail catalog and event data using the Cloud Console and the Retail API.
This lab uses a subset of the Google Merchant Center dataset for the product catalog. Data exported directly from Google Merchant Center uses a schema that is not compatible with the Retail data ingestion API so the dataset used in the lab has been modified to conform to the Retail Schema
.
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 under the Artificial Intelligence section select Search for Retail.
Click Turn On API.
Click Continue and accept the data terms by clicking Accept.
Click Get Started.
In this task, you will import product catalog data from BigQuery and user event data from Cloud Storage.
The merchant_center.products
table contains catalog data that has been exported from a test account on Google Merchant Center using the Google Merchant Center products table schema. This data set can be imported as catalog data using the older Recommendations AI Console or API. The Retail API, that replaces the Recommendations AI API, does not currently support importing data that uses the Merchant Center products table schema and all data imports must use the Retail Schema. You will still try to import this data using the Retail API in order to see how to inspect data import errors.
In the GCP Console, click Search for Retail > 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: merchant_center table.
You are unable to proceed as the source table does not have an id
field.
There are many more issues with the data because of the schema.
In this task, import product data into the catalog from a BigQuery table that uses the Retail products schema.
In the GCP Console, on the Navigation menu (), click View All Products under the Artificial Intelligence section select Search for Retail > 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 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 GCP Console, on the Navigation menu (), click View All Products under the Artificial Intelligence section select Search for Retail > 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 section to change to Succeeded. Approximately 32,000 items will have been imported and 5 items will have failed.
In this task, you will examine the data import jobs and explore some of the errors logged by the import tasks when invalid data is encountered.
In the Search for Retail navigation menu, click Data and then click Activity Status to monitor the progress of the import task.
Click the User Events tab and then click the View full error logs in the Detail column to examine the errors.
This will open the /error
folder in the Cloud Storage bucket where your source data was located.
Click the name of the file that corresponds to the event data file you imported. It will be about 1 kilobyte in size.
Click Download to download the file and then open it on your machine to examine the error details. You will see five events that failed to import due to a variety of issues with the data schema in those events.
Return to the Cloud Console and close the Cloud Storage tab.
Open the Retail Activity Status tab, and click Close to close the Activity Status pop-out.
In this task, you will examine the product and event data that you have imported.
In the Search for Retail navigation menu, click Data and then make sure the Catalog tab is selected.
for Branch Name, leave the branch set to Branch 0 (Default).
The Catalog product list displays the 1268 product records that were uploaded to the catalog, of which 746 are in stock.
For Filter, enter GGOEGCBT136699
.
This displays the product record for the Google Yellow YoYo. Note that the product is out of stock.
Click the Link icon to try to open the link. The page that is opened says that Sorry, This Page is Not Available.
Close the product tab that was opened to return to the Search for Retail Data page.
For Filter, enter GGOECAEB163612
.
This displays the product record for the Google Black Cloud Tee. Note that this product is in stock.
Click the Link icon to open the link. The product page on the Google Merchandise store opens.
Close the product tab that was opened to return to the Search for Retail Data page.
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:
You will upload a sample user event to the Retail API by passing user event data in JSON format to the Retail API userEvents:write
method.
Store sample user event JSON data in an environment variable:
Store the REST API URL for writing user event data to your catalog using the Retail API userEvents.write
method in an environment variable:
This is the REST API URL for writing user event data to the Retail API. Note that the URL includes bash environment variable substitutions for the Project ID and the access token inline parameter called access_token
. This token authenticates the request using the service account you generate previously using impersonation.
Upload a user event using the REST API using curl:
You have used curl to call the userEvents:write
method passing the event data as a JSON data payload in the POST request.
This will display the formatted data in the response if the upload was successful, including the associated product data such as the product url and image, as well as the event time stamp. Otherwise you will see an error. Most common errors will relate to either a malformed payload, URL, or invalid token.
Congratulations, you've successfully imported Retail product catalog and user event data using a variety of techniques and explored some common data ingestion errors, and examined Retail catalog and event data using the Cloud Console and 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.
此内容目前不可用
一旦可用,我们会通过电子邮件告知您
太好了!
一旦可用,我们会通过电子邮件告知您
一次一个实验
确认结束所有现有实验并开始此实验