User to Products API

Returns the products that are most likely to drive conversion for the given user. Depending on the conversion metrics you choose when training your Miso Engines in Dojo, this API returns products that are most likely to optimize those metrics (such as add_to_cart, checkout, or read).

This API considers both user's interests and the conversion probability. The user's interests are determined from their past interactions on the site and the context of their current browsing session, including recent trending products, time of the day, and recent search behavior.

Application scenarios

The User to Products API is usually used in homepage recommendations, such as "Inspired by your shopping trends" on Amazon, or "Recommended videos" on Youtube. It can also be used to run an email marketing campaign such as a newsletter from Medium with recent articles you can like. These recommendations work especially well in driving product discovery.

Basic usage

For basic usage of this API, you just need to let Miso knows the id of the current user or visitor via user_id or anonymous_id field. For example, for a currently logged-in user, your request looks like this:

POST /v1/recommendation/user_to_products
{"user_id": "user-123"}

For a un-signed visitor, your request looks like this:

POST /v1/recommendation/user_to_products
{"anonymous_id": "visitor-123"}

This API will respond with the recommended products for the specified user or visitor:

{
  "message": "success",
  "data": {
    "took": 37,
    "miso_id": "517452b0-0ccf-11eb-948d-66359cf29022",
    "products": [
      {
        "product_id": "tmdb-475557",
        "_personalization_score": 0.91
      },
      {
        "product_id": "tmdb-299534",
        "_personalization_score": 0.89
      },
      ...
    ]
  }
}
  • took: the amount of time (in milliseconds) Miso took to answer the query
  • miso_id: a UUID of the search request. Include miso_id in the Interaction records for every interactions that result from this search request, for example, a user clicking through to a product in the search results. Miso use miso_id to track the search performance and fine-tune the algorithm accordingly.
  • products: an array of Product records recommended to this user ranked by the probability that the user will be interested in this product. By default, only the product_id of the Product is returned. You can ask Miso to return additional fields by using the fl request argument (see example below)
  • products[ ]._personalization_score: the score assigned by Miso's personalization algorithm based on users' profile and their interactions on the site. This score quantifies the probability of whether users will be interested in this product or not.

You can use the fl request argument to ask Miso to return more product fields. For example, the following request asks Miso to additionally return the title and category fields of every recommended product:

POST /v1/recommendation/user_to_products
{
    "user_id": "user-123",
    "fl": ["title", "categories"]
}

The response will be like:

{
  "message": "success",
  "data": {
    "took": 37,
    "miso_id": "517452b0-0ccf-11eb-948d-66359cf29022",
    "products": [
      {
        "product_id": "tmdb-475557",
        "categories": [
          [
            "Crime"
          ],
          [
            "Thriller"
          ],
          [
            "Drama"
          ]
        ],
        "title": "Joker (2019)",
        "_personalization_score": 0.91
      },
      {
        "product_id": "tmdb-299534",
        "categories": [
          [
            "Adventure"
          ],
          [
            "Science Fiction"
          ],
          [
            "Action"
          ]
        ],
        "title": "Avengers: Endgame (2019)",
        "_personalization_score": 0.89
      },
     ...
    ]
  }
}

Filtering and Boosting

Like every other Miso API, User To Products API supports filter query (fq) and boost query (boost_fq) to generate recommendations that meet your business needs.

Filter Query

You can use filter query to filter recommendation results against arbitrary criteria, and Miso will guarantee to return sufficient number of recommendation results that meet the criteria. For example, the following requests will limit the recommendations to only Drama films:

POST /v1/recommendation/user_to_products
{
    "user_id": "user-123",
    "fl": ["title", "categories"],
    "fq": "categories:Drama"
}

For another example with custom_attributes, the following requests will limit the recommendations to only Drama films after 2010:

POST /v1/recommendation/user_to_products
{
    "user_id": "user-123",
    "fl": ["title", "categories"],
    "fq": "categories:Drama AND custom_attributes.year:[…"
}

Latency Consideration

Miso achieves instant recommendations by pre-computing a large pool of candidates (N>1,000) for each user with the products they are mostly likely to be interested in. However, when the given filter query do not match a sufficient number of candidates, Miso will fall back to Search API to find additional matches to fill in the remaining slots. While falling back to Search API will increase the latency, the latency increase is usually minimum if the same filter query is being used repeatedly due to Miso's caching mechanism.

Boost Query

You can use boost_fq to boost Products with arbitrary criteria. The relevant Products that match the boost_fq will be ranked at the top of the recommendations or at the positions specified in the boost_positions parameter. Boosting is useful for product promotions, for example sponsored products, to highlight the Products you want more impression.

For example, the following request will boost the Sci-Fi films directed by Ridley Scott:

POST /v1/recommendation/user_to_products
{
  "user_id": "user-123",
  "fl": [
    "title",
    "categories"
  ],
  "boost_fq": "categories:\"Sci-Fi\" AND custom_attribut…"
}

The response will be like:

{
  "message": "success",
  "data": {
    "took": 83,
    "miso_id": "54bf6d9a-dd32-11eb-99d6-a62d401473b5",
    "products": [
      {
        "product_id": "tmdb-286217",
        "title": "The Martian (2015)",
        "_personalization_score": 0.5364759309088403,
        "_boosted": true,
        "categories": [
          [
            "Drama"
          ],
          [
            "Adventure"
          ],
          [
            "Science Fiction"
          ]
        ]
      },
      ...
    ]
  }
}

The additional field products[ ].boosted is a boolean that indicates whether the Product matches the boost_fq.

You can also use boost_positions to specify the positions in the recommendation list you want the boosted Products to be placed. For example, the following request will place the boosted Product at the second place, and the third place (the boost_positions are 0-based):

POST /v1/recommendation/user_to_products
{
  "user_id": "user-123",
  "fl": [
    "title",
    "categories"
  ],
  "boost_fq": "categories:\"Sci-Fi\" AND custom_attribu…",
  "boost_positions": [
    1,
    2
  ]
}

Filtering "already seen" items

Typically, the User to Products API is used to let users discover new products. Therefore, it is important not to recommend products users have already interacted with recently. By default, the User to Products API filters out the most recent 50 products users have had interactions with (except for impression interactions)

Body·
required
application/json

Attributes for recommendation boosting

  • additional_interactions
    Type: array · Additional Interactions

    A list of additional interaction records. You can use this fields to simulate user interactions without actually writing them to the interaction dataset.

  • anonymous_id
    Type: string · Anonymous Id

    The anonymous visitor who made the query and for whom Miso will personalize the results. Either user_id or anonymous_id needs to be specified for personalization to work.

  • boost_fq
    Type: string · Boost Fq

    Defines a query in Elasticsearch query-string syntax (Lucene) that can be used to boost a subset of products to the top of the ranking, or to specific boost positions (See boost_positions parameter below.) For example, the query below will promote all the relevant products whose brand is Nike to the top of recommendation list:

    {
        "boost_fq": "brand:\"Nike\""
    }
    

    For a slightly more complex example, the query below will promote the Nike products which have also been tagged as ON SALE to the top of the ranking:

    {
       "boost_fq": "brand:\"Nike\" AND tags:\"ON SALE\""
    }
    

    It is worth mentioning that, Miso will only boost products that are relevant and have high likelihood to convert, and will not boost a low performance product only because it matches the boosting query.

    Depending on your boosting rules, in certain cases, you would like to prevent recommendation results from being too monotone due to boosting. With Miso, you have two tools to do so.

    First, you can specify boost_positions to place promoted products at specific positions in the ranking. For example, the query below will place boosted products only at the first and fourth places in the ranking (positions are 0-based), and place the remaining products in their original ranking, skipping these two positions.

    {
       "boost_fq": "brand:\"Nike\" AND tags:\"ON SALE\"",
       "boost_positions": [0, 3]
    }
    

    The second tool is diversification. diversification parameter, on a best-effort basis, will try to maintain a minimum distance between products that have the same attributes. For example, the following query will place products made by the same brand apart from each other.

    {
       "boost_fq": "brand:\"Nike\" AND tags:\"ON SALE\"",
       "diversification": {
           "brand": {"minimum_distance": 1}
        }
    }
    
  • boost_positions
    Type: array integer[] · Boost Positions

    Defines a list of 0-based positions you want to place the boosted products at.

    For example, the query below will promote products whose brand is Nike as the top and second recommendations:

    {
        "boost_fq": "brand:\"Nike\"",
        "boost_positions": [0, 1]
    }
    

    If boost_positions is not specified (which is the default behavior), all the boosted products will be ranked higher than the rest of the products.

  • boost_rule_name
    Type: string · Boost Rule Name

    Name of the boosting rule. Use this to identify a boosting rule in _boosted_rules in the response

  • boost_rules
    Type: array object[] · Boost Rules

    Define a list of boosting rules that will be applied to the search or recommendation results simultaneously. boost_rules parameter is particularly useful when you want to boost more than one sets of products, and promote each of them to different positions. For example, the query below will promote products whose brand is Nike to the top and second results, and products whose brand is Adidas to the third and fourth results:

    {
        "boost_rules": [
            {
                "boost_fq": "brand:\"Nike\"",
                "boost_positions": [0, 1]
            },
            {
                "boost_fq": "brand:\"Adidas\"",
                "boost_positions": [2, 3]
            }
        ]
    }
    
  • boosting_tags
    Type: array string[] · Boosting Tags

    When boosting_tags is given, and there are pre-defined boost rules have the same tag(s), those boost rules will be matched, regardless if the criteria is met or not.

    Useful when want to force trigger specific boost campaign.

  • custom_context
    Type: object · Custom Context

    Dictionary of custom context variables for the current browsing session. You can specify context variables specific to your websites or apps in a {"KEY":VALUE} format, where KEY must be a string, and VALUE can be:

    • a bool
    • a string or an array of string
    • a number or an array of numbers
    • an array of objects
    • null

    In certain cases, Miso will take these variables into account when generating results.

  • dedupe_product_group_id
    Type: boolean · Dedupe Product Group Id

    Whether to dedupe product based on product_group_id. If dedupe_product_group_id=true, Miso will prevent products with the same product_group_id from showing multiple times in the search or recommendation results.

    This is particular useful when one product has multiple variants (for example, different sizes, colors, or materials), and you only want to show this product only once in the search or recommendation results. Miso will then return the variant that is most likely to be of the user's interest.

  • dithering
    Type: number · Dithering
    min:  
    1

    Dithering is an optional parameter (>= 1.0, and typically <= 5.0) in the recommendation APIs that introduces randomness to the order of recommended items. By adding noise to the original ranking, it shuffles the list, surfacing lower-ranked items to enhance list freshness and potentially boost user engagement. However, excessive dithering may reduce the accuracy of item ordering. See this blog post for more information.

  • diversification
    Type: object · Diversification

    Defines diversification rules to prevent products with the same attributes (e.g. sneakers made by the same brand or books from the same authors) from showing up too close to each other in the results.

    For instance, customers who have purchased many of sneakers from Nike may happen to have recommendations or search results where all top-5 entries are sneakers made by Nike. Purely considering accuracy, these recommendations appear excellent since the user clearly appreciates Nike sneakers. However, such results might be considered too "plain" by the user, owing to its lack of diversity.

    diversification parameter allows you to avoid this problem by enforcing a desired minimum distance between products. For example, consider a list of four products whose brand are Nike, Nike, Adidas, and PUMA respectively. The query below will make sure there are at least one different product between two Nike products, e.g. the diversified ranking may become Nike, Adidas, Nike, and PUMA :

    {
       "diversification": {"brand": {"minimum_distance": 1}}
    }
    

    You can also increase the minimum_distance to place products further apart. For example, the following query will make sure, for the two Nike products, there are at least two other products between them. As a result, the diversified ranking may become Nike, Adidas, PUMA, and Nike.:

    {
       "diversification": {"brand": {"minimum_distance": 2}}
    }
    

    The diversification algorithm reranks the products on a best-effort basis. For example, for the product list described earlier, it is not possible to place two Nike product three places apart from each other. Therefore, the diversified ranking will still remain Nike, Adidas, PUMA, and Nike* even if we set minimum_distance=3.

  • engine_id
    Type: string · Engine Id

    The engine you want to get results from. When you have more than one engine, you can use this parameter to specify the specific engine you want to get results from. If not specified, the default engine will be used.

Responses
  • application/json
  • application/json
Request Example for post/v1/recommendation/user_to_products
curl 'https://api.askmiso.com/v1/recommendation/user_to_products?api_key=YOUR_SECRET_TOKEN' \
  --request POST \
  --header 'Content-Type: application/json' \
  --data '{
  "engine_id": "",
  "user_id": "",
  "anonymous_id": "",
  "user_hash": "",
  "user_cohort": {
    "additionalProperty": true
  },
  "rows": 5,
  "type": "",
  "dedupe_product_group_id": true,
  "additional_interactions": [],
  "fl": [],
  "exclude": [
    ""
  ],
  "custom_context": {
    "session_variable_1": [
      "value_1",
      "value_2"
    ]
  },
  "boosting_tags": [
    "tag-1",
    "quetag-2"
  ],
  "fq": "",
  "boost_fq": "",
  "boost_positions": [
    1
  ],
  "boost_rule_name": "",
  "boost_rules": [],
  "geo": {
    "filter": [],
    "boost": []
  },
  "diversification": {
    "additionalProperty": {
      "minimum_distance": 1,
      "always_together": false
    }
  },
  "dithering": 1,
  "pagination_id": "",
  "start": 0
}'
{
  "message": "success",
  "data": {
    "took": 0,
    "miso_id": "123e4567-e89b-12d3-a456-426614174000",
    "products": [
      {
        "product_id": "123ABC-S-Black"
      }
    ]
  }
}