Example gallery/Recommend products to a user
Example level
Simple
Endpoints
Dataset

Recommend products to a user

To understand the example better, please read what data the Generated Ecommerce dataset contains

The dataset contains products, purchase history, and users.

Simple recommendation

Recommendation which maximises the purchase likelyhood can be done with the query below. You can copy-paste the command to your terminal and test it out!

curl -X POST \
  https://aito-generated-ecom.api.aito.ai/api/v1/_recommend \
  -H 'content-type: application/json' \
  -H 'x-api-key: iIZThrosrFaIV1wYCBYRM1rtluY9ZIIY19P6VOTP' \
  -d '
  {
    "from": "impressions",
    "where": {
      "user": 1
    },
    "recommend": "product",
    "goal": { "purchase": true }
  }'

Response should look like:

{
  "offset" : 0,
  "total" : 10148,
  "hits" : [ {
    "$p" : 8.922444515351214E-4,
    "Reviews" : " ",
    "average_product_rating" : 0.0,
    "brand" : "Croscill Classics",
    "category" : "croscill classics",
    "category_tree" : "jcpenney|croscill classics",
    "description" : " ",
    "name" : "Croscill Classics® Bay Breeze 4-pc. Comforter Set & Accessories",
    "sale_price" : 259.855,
    "sku" : "pp5006451182",
    "total_number_reviews" : 0.0
  }, {
    "$p" : 6.531472200322731E-4,
    "Reviews" : " ",
    "average_product_rating" : 0.0,
    "brand" : "Croscill Classics",
    "category" : "comforters & bedding sets",
    "category_tree" : "jcpenney|bed-bath|comforters & bedding sets",
    "description" : " ",
    "name" : "Croscill Classics® Tan Chenille Jacobean 4-pc. Comforter Set & Accessories",
    "sale_price" : 47.51356,
    "sku" : "pp5007390351",
    "total_number_reviews" : 0.0

  ...

The response contains a list of products, sorted based on the likelyhood of purchase ("$p") in descending order. The "best" product would be the first item.

From the response, we can notice a few issues with the original dataset, for example that it's missing ratings for some products.

Why?

Why did Aito recommend these products? To get some more insight into that, we can select "$why". Let's limit the results to the first item as the explanation response is quite verbose.

curl -X POST \
  https://aito-generated-ecom.api.aito.ai/api/v1/_recommend \
  -H 'content-type: application/json' \
  -H 'x-api-key: iIZThrosrFaIV1wYCBYRM1rtluY9ZIIY19P6VOTP' \
  -d '
  {
    "from": "impressions",
    "where": {
      "user": 1
    },
    "recommend": "product",
    "goal": { "purchase": true },
    "select": ["$why"],
    "limit": 1
  }'

Response should look like:

{
  "offset" : 0,
  "total" : 10148,
  "hits" : [ {
    "$why" : {
      "type" : "product",
      "factors" : [ {
        "type" : "hitVariableLift",
        "variable" : "category:croscill classics",
        "value" : 2.567714532256169,
        "factors" : [ {
          "type" : "relatedVariableLift",
          "variable" : "user.postal_code:38600",
          "value" : 2.567714532256169
        } ]
      }, {
        "type" : "hitVariableLift",
        "variable" : "brand:Croscill Classics",
        "value" : 1.8518546420849247,
        "factors" : [ {
          "type" : "relatedVariableLift",
          "variable" : "user.postal_code:38600",
          "value" : 1.8518546420849247
        } ]
      }, {
        "type" : "hitVariableLift",
        "variable" : "description: ",
        "value" : 1.6510211103704036,
        "factors" : [ {
          "type" : "baseLift",
          "value" : 1.8756034083664594
        }, {
          "type" : "relatedVariableLift",
          "variable" : "user.age:8",
          "value" : 0.8793971733423044
        }, {
          "type" : "relatedVariableLift",
          "variable" : "user.postal_code:38600",
          "value" : 1.0009826448477892
        } ]
      },

  ...

There are a lot of different factors that can affect the likelyhood. You can read more about the different factors from our API docs.

More complex recommendation goal

Let's combine different aspects in a recommendation. Ideally our product data would contain the gross margin for each product and we would be able to recommend good products for the user, but also good products for the shop. The next best thing we can do with the dataset is combining likelyhood of purchase with the sales price. In a real world example you'd want to weigh the sales price or gross margin less, but the example is still relevant.

curl -X POST \
  https://aito-generated-ecom.api.aito.ai/api/v1/_recommend \
  -H 'content-type: application/json' \
  -H 'x-api-key: iIZThrosrFaIV1wYCBYRM1rtluY9ZIIY19P6VOTP' \
  -d '
  {
    "from": "impressions",
    "where": {
      "user": 1
    },
    "recommend": "product",
    "goal": {
      "$multiply": [
        { "$p": { "purchase": true } },
        { "$hit": "sale_price"}
      ]
    }
  }'

Recommend query is an easy way to get a list of items which maximise a given goal. See API docs for a few other examples.

Visit us

Annankatu 34 B

00100 Helsinki

Finland

See map

26 Underwood Street

N1 7JQ

London, UK

See map

Contact info

We'd love to hear from you.

hello@aito.ai

Follow us