Empowering Retailers with Google quality Search & Recommendations — Part 1

Yash Badani
Google Cloud - Community
6 min readOct 27, 2022

Ever wondered, how major retailers are powering search & recommendations on their e-commerce websites ? How is it done ?

Looking for Part 2? Click here

Photo by Franki Chamaki on Unsplash

Let’s take a physical shopping experience example for a customer:

Consider that you are at a huge supermarket/store and you have limited time to complete your shopping list. You are in a hurry & finding your ways through the store - asking people where X Y & Z is available.

It could be at the completely opposite corner of the store or just next to you! Infact, the items may not be placed at the store in the exact same order of your shopping list. This becomes a hustle and you end up spending more time while you travel through the long aisles at the store. We wish that it’s not only quicker (like searching on any e-commerce website) but also ensure we end up crossing by the right aisles to pick the exact products you wished or purchased previously or you forgot to add in the list.

Let’s suppose that you also had a couple things to purchase, but you missed out on them completely — like buying a Loofah while looking for a Towel OR buying Drinks while you looked for Snacks OR buying Disposable glasses for the party you have tonight! Sounds familiar ?

What is Retail Search ?

  • Google Cloud’s Discovery solutions help e-retailers to convert casual browsers to legit buyers as well as personalizing the overall shopping experience for the buyers/customers.
  • Retail Search is built upon Google’s overall understanding of user shopping behavior, intents, context and overall SKUs. This guides the user on your store with increased engagement and revenue per order using Google powered state-of-the-art AI Recommendations.
  • In addition, you can supply your own business rules to modify the catalog viewing experience, expand the overall search query to retrieve related items, boost & bury results and so on

Let’s head to the console and create magic!

Enabling Retail Search

If you are visiting the Retail console for the first time, please follow the instructions here to accept the T&C as well as enabling the Retail Search.

Note that enabling Retail Search will show as “Optional” after you enable the Recommendations AI, but make sure you enable it as this blog focuses on Retail Search.

To get started, you need DATA - That helps Retail Search understand about your Catalog and User Interactions for providing relevant suggestions.

Feeding data to Retail Search

Head to the Data page from Retail console’s menu and here you’ll see tabs for Catalog & Events. For the simplicity of this blog, lets focus on Catalog data and how to feed your product catalog into Retail Search.

There are multiple ways you can import data:

  • BigQuery Import from Table/View
  • Cloud Storage Import from Newline-delimited JSON file(s)
  • Google Merchant Center Sync
  • Inline Import by specifying data in API Request Body

Lets use the BigQuery Import option.

BigQuery Import Method

For this, you need to create a schema in the BigQuery Product Catalogs Schema format specified by Retail Search. Or you can create a BigQuery View on any existing catalog table and the View should conform to the Product Catalogs Schema.

Note that the structure of Catalog data conforms to a Product Catalogs Schema format specified by Retail Search. Please refer the official documentation to know more about the fields & making necessary transformations to your data.

Retail provides 3 branches to import data into(0, 1, 2). One of the 3 branches is set as default_branch which is used to serve results. There are many reasons of having this silo:

  • To ensure that search results are reliable & up-to-date to end users
  • Graceful commissioning of well tested data to serve end users (by setting the given branch as default)
  • Graceful decommissioning of old data and also ensuring rollback to previous state, if needed
  • And more…
To import product catalog data to Retail Search

Head to the Data section from the menu on Retail console

  1. Click on “Import” from the top. A side modal will open.
  2. Import Type > Select “Product Catalog”
  3. Source of Data > Select “BigQuery”
  4. Import Branch > Select a branch you wish to import into (If you are doing it for first time, select your favorite number from 0, 1 or 2)
  5. Schema of data > Select “Retail Product Catalogs Schema” — This is the schema format we talked about.
  6. BigQuery table > Provide the complete Table ID in format of “projectId.datasetId.tableId” — This is the table/view that conforms to the Product Catalogs Schema

Click “Import”.

Bonus:

You can also import data using the Retail APIs. Below is an example to run the POST API products.import using the CURL command (SSH should have appropriate IAM Accesses)

$ PROJECT_ID="test-retail"
$ PROJECT_NUMBER="123456789"
$ DATASET_ID="testretail"
$ TABLE_ID="product_catalog"
$ curl -X POST \
-H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d '{
"inputConfig": {
"bigQuerySource": {
"projectId": "'$PROJECT_ID'",
"datasetId": "'$DATASET_ID'",
"tableId": "'$TABLE_ID'",
"dataSchema": "product"
}
},
"reconciliationMode": "FULL"
}' \
'https://retail.googleapis.com/v2/projects/'$PROJECT_NUMBER'/locations/global/catalogs/default_catalog/branches/default_branch/products:import'

The API field reconciliationMode provides an option to either import data INCREMENTAL-ly or FULL refresh.

If you import data using the Console UI, it defaults to INCREMENTAL. To import data with FULL refresh, you can Purge the data(check below screenshot) and import data a-fresh!

To Purge/delete data in the branch

Tracking your import activity

Once your import starts successfully, head straight to the “Activity Status” modal on “Data” Page

Activity Status for import & purge activities
  • Observe the ongoing operation; Items succeeded will show the number of products imported. Note that each record should represent single unique product.
  • In the above screenshot, an old operation succeeded with 27974 products imported and 2 products not imported, having a schema or data problem. Hence, products are imported partially with error logs provided for debugging as well.
  • If you purged a branch, it takes time. So you must wait for purge operation to complete before importing new data, which can be tracked here in Activity Status modal.

In the background, Retail Search will do re/indexing operations for returning correct results for search queries. You can now start using Retail Search for normal search operations. This should give you correct results.

Let’s Search

  • Go to the Retail Console > Select Serving Configs. Retail Search creates a default configuration to use.
  • Click on “default_search” Serving Config > Click Evaluate from top
  • Provide a search query based on your data
Search results for “spray”

Now, you can implement this on your website using the SDKs provided by Retail Search. Below is an example to run the POST API placements.search using the CURL command (SSH should have appropriate IAM Accesses)

$ PROJECT_NUMBER="123456789"$ curl -X POST \
-H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d '{
"branch": "projects/'$PROJECT_NUMBER'/locations/global/catalogs/default_catalog/branches/default_branch",
"query": "spray",
"visitorId": "yash",
"pageSize": 28
}' \
"https://retail.googleapis.com/v2/projects/$PROJECT_NUMBER/locations/global/catalogs/default_catalog/placements/default_search:search"

You may need to add “X-Goog-User-Project: $PROJECT_NUMBER” header (if required) to let Retail Search know which project to bill. You can checkout more options in the API documentation for filtering search results & browsing categories.

Congratulations on your first step into Google Cloud Retail Discovery Solutions. Next, we’ll discuss what are Serving Configurations, Serving Controls & Dynamic Facets.

Click here for Part 2

References

--

--