Leveraging Machine Learning Product Recommendations

Coveo Machine Learning (Coveo ML) Product Recommendations (PR) use usage analytics events to provide your customers with relevant and adaptive item suggestions.

Coveo ML PR enhances your customers’ shopping experience by offering them products that suit their profile, context, and buying behaviors. In order to provide relevant suggestions, the model continuously learns from your end users’ feedback by scoping their buyer profile and analyzing their positive and negative interactions with different products. Thanks to its multiple algorithms, Coveo ML PR can easily adapt its approach to your digital commerce strategy.

This article details the required steps to deploy Coveo ML PR in a Coveo for Commerce solution.

Step 1: Configure a PR Model

  1. Ensure your commerce interfaces track commerce usage analytics events.

  2. Create a PR model.

  3. Associate the PR model with the desired query pipeline.

Step 2: Query the Desired Model

Coveo ML PR offers different strategies to adapt its recommendations according to the current user context.

To leverage one of those strategies in your commerce solution, you must write code that:

  • Calls the Coveo Search API to query the desired ML PR model.

  • Renders the recommendations returned by the Coveo Search API.

You can use the JavaScript Search Framework to request and render recommendations.

Here’s an example of a product page that renders a list of recommendations at the bottom:

<!DOCTYPE html>
<html lang="en">
<head>
  <!-- The product id is stored as metadata, which is retrieved later on. -->
  <!-- You may replace this with your own method of storage. -->
  <meta name="productid" content="123">
  <link rel="stylesheet" href="./css/CoveoFullSearch.css" />
  <script class="coveo-script" src="js/CoveoJsSearch.Lazy.js"></script>
  <script>
    document.addEventListener('DOMContentLoaded', function () {
      // The product id is retrieved.
      // You may replace this with your own method of retrieval.
      const productId = document.querySelector('meta[name="productid"]').content;
      // The search endpoint is configured here with the itemId parameter
      // because it leverages the Frequently bought together strategy.
      Coveo.SearchEndpoint.configureCloudV2Endpoint(
        <MY_ORGANIZATION_ID>,
        <MY_SEARCH_TOKEN>,
        "https://platform.cloud.coveo.com/rest/search",
        {
          "queryStringArguments": {
            "mlParameters": {
              "itemId": productId
            }
          }
        }
      )
      const root = document.getElementById('coveoFrequentlyBoughtTogetherRecommendations');
      // The framework is initialized with a recommendation interface.
      Coveo.initRecommendation(root);
    })
  </script>
</head>
<body>
  <!-- ... -->
  <!-- The CoveoRecommendation component is a CoveoSearchInterface -->
  <!-- that displays recommendations. -->
  <div id="coveoFrequentlyBoughtTogetherRecommendations"
       class="CoveoRecommendation"
       data-pipeline="MyFrequentBoughtPipeline">
    <div class="coveo-recommendation-body">
      <div class="CoveoResultList">
        <!-- ... -->
      </div>
    </div>
  </div>
  <!-- ... -->
</body>
</html>

Depending on the strategy used by the targeted ML PR model, the query may have to include different ML query parameters:

Interest-Based Recommender (user)

No additional ML query parameters need to be provided for the model to provide its recommendations.

Frequently Bought Together (frequentBought)

When leveraging the Frequently bought together strategy, you need to pass the input product SKU in the itemId ML query parameter for the model to provide its recommendations.

{"mlParameters": {"itemId": "<ITEM_SKU>"}}

Frequently Viewed Together (frequentViewed)

When leveraging the Frequently viewed together strategy, you need to pass the input product SKU in the itemId ML query parameter for the model to provide its recommendations.

{"mlParameters": {"itemId": "<ITEM_SKU>"}}

If the model is queried from a commerce interface where multiple items are shown, multiple SKUs can be provided by using the itemIds ML query parameter instead.

{"mlParameters": {"itemIds": ["<ITEM1_SKU>", "<ITEM2_SKU>", "<ITEM3_SKU>"]}}

Cart Recommender (cart)

When leveraging the Cart recommender strategy, you need to pass the input product SKU in the itemIds ML query parameter for the model to provide its recommendations.

{"mlParameters": {"itemIds": ["<ITEM1_SKU>", "<ITEM2_SKU>", "<ITEM3_SKU>"]}}

You can specify as many ITEM_SKU as you want.

No additional ML query parameters need to be configured for the model to provide its recommendations.

However, you may want to filter the provided recommendations by specific category and/or brand. You can achieve this by passing the input product category and brand respectively in the categoryFilter and brandfilter ML query parameters.

For the time being, analytics data is used by the model to retrieve the product’s category and brand. In the future, this information will be retrieved from the commerce catalog directly.

categoryFilter

Passing the input product category in the categoryFilter ML query parameter:

{"mlParameters": {"categoryFilter": "<CATEGORY>"}}

Make sure that your commerce interface sends the product category to Coveo Analytics.

brandFilter

Passing the input product brand in the brandFilter ML query parameter:

{"mlParameters": {"brandFilter": "<BRAND>"}}

Make sure that your commerce interface sends the product brand to Coveo Analytics.

No additional ML query parameters need to be configured for the model to provide its recommendations.

However, you may want to filter the provided recommendations by specific category and/or brand. You can achieve this by passing the input product category and brand respectively in the categoryFilter and brandfilter ML query parameters.

For the time being, analytics data is used by the model to retrieve the product’s category and brand. In the future, this information will be retrieved from the commerce catalog directly.

categoryFilter

Passing the input product category in the categoryFilter ML query parameter:

{"mlParameters": {"categoryFilter": "<CATEGORY>"}}

Make sure that your commerce interface sends the product category to Coveo Analytics.

brandFilter

Passing the input product brand in the brandFilter ML query parameter:

{"mlParameters": {"brandFilter": "<BRAND>"}}

Make sure that your commerce interface sends the product brand to Coveo Analytics.

Recommended Articles