Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Table of contents
1.
Introduction
2.
Importing catalog information to the Retail API
3.
Purging Data from Catalog Branches
4.
Connecting merchant center to Retail API
5.
Unlinking Merchant Center Account
6.
Importing Catalog Data from Merchant Center
7.
Importing Catalog Data from Cloud Storage
8.
Optimum procedures for capturing user events
9.
Use a JavaScript pixel to keep track of user activities
10.
Setting up the Retail API
11.
Setting up the Retail API for an existing Project
12.
Turning off the Retail API
13.
Setting up authentication for your application
14.
Creating a Service Account
15.
Creating an API Key
16.
Creating a Recommendation Model
17.
Requirements for creating a Recommendation Model
18.
Frequently Asked Questions
18.1.
What is Deep Learning?
18.2.
What is NLP?
18.3.
What is Artificial Neural Network?
19.
Conclusion
Last Updated: Mar 27, 2024
Medium

Basics of Recommendations AI

Author Ayush Mishra
1 upvote

Introduction

Recommendations AI enables the creation of high-quality personalized product recommendation systems without requiring extensive knowledge of machine learning, system design, or operations.

In this blog, we will discuss the Basics of Recommendations AI in detail. The series of Recommendations AI consists of three parts. This is the second part; for the other two parts, you may refer to Introduction to Recommendations AI and Advanced Concepts of Recommendations AI. Let’s start going!

Basics of Recommendation AI

Importing catalog information to the Retail API

In this part, we will learn how to import catalog information to the Retail API to use Recommendation AI and Retail Search.

Implements the following practices before importing catalog data:-

🧨 When deciding which products or groups of products are primary and which are variants, be sure to give it some careful thought. It takes a lot of effort to change product-level configuration after you've imported any data. Search results or recommendations are returned as primary items.

🧨 Observe the import limit for product items.

🧨 Ensure that the correct and complete catalog information is included and do not use the placeholder value.

🧨 Include as much supplementary catalog data as you can.

🧨 Especially if you intend to use the Google Cloud console to obtain revenue metrics, ensure that all of your events use a single currency. The use of multiple currencies per catalog is not supported by the Retail API.

🧨 Update your catalog frequently.

🧨 For product items that haven't been imported yet, don't record user events.

🧨 Review your project's error reporting and logging data after importing the catalog information.

Purging Data from Catalog Branches

Steps to purge data from the catalog branch are:-

🚀 Go to the Google Cloud console's Retail Data page.

🚀 A catalog branch can be chosen in the Branch name field.

🚀 Select the Purge branch from the three-dot menu next to the Branch name field.

🚀 To remove the catalog data from the branch, enter the branch and then click Confirm.

Connecting merchant center to Retail API

Steps to connect merchant center to Retail API are:-

🦾 Go to the Google Cloud console's Retail Data page.

🦾 To access the Import Data panel, click Import.

🦾 Choose the Product catalog.

🦾 As your data source, pick Merchant Center Sync.

🦾 Select Merchant Center as your account.

🦾 Pick the branch where you want to upload your catalog.
🦾 Click "Import."

Unlinking Merchant Center Account

Steps to unlink merchant center account are:-

🧨 Go to the Google Cloud console's Retail Data page.

🧨 A list of your connected Merchant Center accounts will appear when you click the Merchant Center button in the top right corner of the page.

🧨 To unlink a Merchant Center account, click Unlink next to it, then confirm your decision in the following pop-up dialogue.

Importing Catalog Data from Merchant Center

Steps to import catalog data from the merchant center are:-

🚀 Set up a transfer from Merchant Center to BigQuery by following the instructions in Merchant Center transfers.

🚀 Set your dataset expiration time to two days, but set your transfer to repeat daily.

🚀 Configure the necessary permissions so that the Retail API can access the BigQuery dataset if it is part of another project.

🚀 Use the Retail API to import your catalog data from BigQuery.

      a. Go to the Google Cloud console's Retail Data page.   

      b. To access the Import panel, click Import.

      c. Choose the Product catalog.

      d. Make BigQuery your data source of choice.

      e. Choose the branch to which you'll upload your catalog.

      f. Choose the Merchant Center data schema.

      g. Enter the BigQuery table containing your data.

      h. As a temporary storage location for your data, enter the location of a Cloud Storage bucket in your project.

      i. Decide whether or not to plan a recurring upload of your catalog's information.

      j. Select the product levels if this is your first time importing your catalog or if you are doing so after purging it.

      k. Click Import.

Importing Catalog Data from Cloud Storage

Steps to import catalog data from the Cloud Storage are:-

🦾 Verify that the Retail service account is authorized to read from and write to the bucket.

🦾 Use the Retail API to import your catalog data.

         a. Go to the Google Cloud console's Retail Data page.

         b. To access the Import panel, click Import.

         c. Choose the Product catalog.

         d. Choose the branch to which you'll upload your catalog.

         e. As the schema, pick Retail Product Catalogs Schema.

         f. Enter the location of your data's cloud storage.

         g. Select the product levels if Retail Search is not active.

         h. Click Import.

Optimum procedures for capturing user events

Implements the following practices before capturing user events:-

🖋️  Join any user events recorded before the catalog import was finished if you record them before or during the catalog import.

🖋️ Update your catalog frequently.

🖋️ Try to keep the size of the data you're importing for a bulk user event import under control.

🖋️ Check your error reporting after a bulk import to make sure your data was imported properly.

🖋️ Include an exact timestamp for each user event when importing user event data, and avoid importing consecutive user events with the same timestamp.

🖋️  Discuss how to fix the issue with your Retail contact if you have incorrectly imported user events.

🖋️ Keep your user event data continuous wherever you can. User event data gaps can make models less accurate.

🖋️ To ensure user privacy and to maintain user anonymity to Retail, employ a secure version of unique identification. Your responsibility is to redirect PII (personally identifying information) from your data, such as home addresses or email addresses.

Use a JavaScript pixel to keep track of user activities

The sample that follows uses a JavaScript pixel to capture a detail-page-view UserEvent.

<script type="text/javascript">
var user_event = 
{
  "eventType" : "detail-page-view",
  
  "visitorId": "visitor-id",
  
  "userInfo": {
      "userId": "user-id"
 	},

  "attributionToken": "attribution-token",
  
  "experimentIds": "experiment-id",
  
  "productDetails": [
      {
        "product": {"id": "123"}
      }
  ]
};

var _gre = _gre || []; // Credentials for the project.

_gre.push(['apiKey', 'api-key']);

_gre.push(['logEvent', user_event]);

_gre.push(['projectId', 'project-id']);

_gre.push(['locationId', 'global']);

_gre.push(['catalogId', 'default_catalog']);

(function()
	 {
  var gre = document.createElement('script'); gre.type = 'text/javascript'; gre.async = true;
  gre.src = 'https://www.gstatic.com/retail/v2_event.js';
  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(gre, s);
	})();

</script>


A set visitor to the Google Analytics client ID if you imported user events using Google Analytics 360. Keep in mind that the whole name of the _ga cookie only contains part of the Google Analytics client ID (for instance, client ID 123456789.123456789 is part of _ga cookie GA1.3.123456789.123456789).

The syntax for establishing the client ID in a user event is demonstrated in the following condensed example. Substitute your Google Analytics tracking ID for "UA-XXXXXX-N."

<script type="text/javascript">

var tracker = ga.getByName('UA-XXXXXX-N');
var user_event = {
      "visitorId": tracker.get('clientId')
};
</script>

Setting up the Retail API

Steps to setup the Retail API are:-

✒️ Go to the Google Cloud console's Retail Data page.

✒️ Click Turn on API on the page for setting up the retail API.

✒️ Click Continue when Retail API and Recommendations AI appear as On. 

✒️ Read the terms for using data from Discovery Solutions, and click Accept if you agree.

✒️ Click Get Started if you only want to use the project with Recommendations AI.

✒️ Do the following if you want to enable Retail Search in addition to Recommendations AI:

      a. On the Turn on Retail Search (Optional) page, click Turn on after selecting Continue.

      b. Select Get Started.

Setting up the Retail API for an existing Project

Steps to setup the Retail API for an existing project are:-

✏️ Go to the Google Cloud console's Retail Data page.

✏️ Read the Discovery Solutions data use terms on the Data use terms page, and then click Accept if you accept them.

✏️ Click Get Started if you only want to use the project with Recommendations AI.

✏️ Do the following if you want to enable Retail Search in addition to Recommendations AI:

      a. On the Turn on Retail Search (Optional) page, click Turn on after selecting Continue.

      b. Select Get Started.

Turning off the Retail API

Steps to turn off the Retail API are:-

✒️  Go to the Google Cloud console's Retail Data page.

✒️ Select Disable API.

✒️ Click Disable in the Disable Retail API? box.

✒️ Click Disable in the Disable Recommendations AI? Box.

Setting up authentication for your application

In order to access the Retail API, the following authentication methods must be set up.

Service Account:- Applications authenticate calls to the Product using a service account.

API Key:- When calling user event logging APIs, applications use an API key.

Creating a Service Account

Steps to create a service account are:-

🧷 Go to the Credentials page for the Google Cloud console.

🧷 Decide which project you want to create a service account for (the project might already be selected).

🧷 Select Service account and then click addCreate credentials.

🧷 Fill out the following fields under "Service account details":

  • Service Account Name: An display name for your service account.
  • Service Account ID: Your service account's distinctive name. You can use the provided default ID or change it to a unique one.
  • Service Account Description:  A description of your account.

 

🧷 To create a service account and proceed with giving it access to your project, click Create and then Continue.

🧷 The following roles can be added by selecting the box next to Grant this service account access to the project:

  • Service Accounts > Service Account Token Creator
  • Other > Retail Editor

 

🧷 Optional: Click Continue and enter the account details for any users or groups you want to give access to so they can act on this service account.

🧷 To save your changes, click Done.

Creating an API Key

Steps to create an API Key are:-

🖊️ Go to the Credentials page for the Google Cloud console.

🖊️ Choose your project from the project drop-down menu at the top of the Google Cloud console page (the project may already be selected).

🖊️ Select the API key after clicking Create credentials. No referrer restrictions should be added. It is well known that some user privacy settings do not pass the referrer URL.

🖊️ Add an HTTP restriction to your API Key to limit access to the Retail service at *https://retail.googleapis.com/* in order to increase security.

Creating a Recommendation Model

Steps to create a recommendation model are:-

🖲️ Go to the Google Cloud console's Retail Data page.

🖲️ Select Create model.

🖲️ Please give your model a name.

🖲️ Select the kind of Recommendation.

🖲️ Depending on the model, pick the business objective.

🖲️ Decide if tags should be created automatically for filtering.

🖲️ To create the new recommendation model, click Create.

Requirements for creating a Recommendation Model

The steps required to start using a new recommendation model are:-

🔋 If you haven't already, import your catalog to Retail and put procedures in place to update the uploaded catalog.

🔋 If you haven't already, begin recording user events to Retail while adhering to the recommended procedures for doing so.

🔋 Decide on the optimization objective and recommendation type you want to use.

🔋 Find out what user event data is necessary for the desired recommendation type and goal.

🔋 To satisfy the minimal event data requirements, either import historical user event data or wait until the user event data collection satisfies the minimal requirements.

🔋 Make your serving configurations and your model.

🔋 Make sure your model is operating properly by using the prediction preview.

🔋 Construct your A/B test.

Check out this article - Padding In Convolutional Neural Network

Frequently Asked Questions

What is Deep Learning?

A part of machine learning called "deep learning" imitates how the human brain functions. It is modeled after the neurons found in the human brain and uses neural networks to tackle challenging real-world issues. Deep neural learning or the deep neural network are other names for it.

What is NLP?

The term "NLP" stands for "Natural Language Processing," which is a subset of AI. It makes it possible for machines to comprehend, interpret, and work with human language.

What is Artificial Neural Network?

Artificial neural networks are statistical constructs modeled after how human brain's neurons function. Numerous AI techniques, including deep learning and machine learning, are used in these neural networks.

Conclusion

Congratulations on finishing the blog! We have studied Basic of  Recommendation AI. We further looked at the uploading catalog, recording events, setting up of Retail API, and creating models.

We hope this blog has helped you enhance your knowledge regarding Recommendation AI, and if you want to learn more, then you can check articles on:-

 

Please refer to our guided pathways on Code studio to learn more about DSACompetitive ProgrammingJavaScriptSystem Design, etc. Enroll in our courses, and use the accessible sample exams and questions as a guide. For placement preparations, look at the interview experiences and interview package.

Please do upvote our blogs if you find them helpful and informative!

Happy learning!

Live masterclass