Product to Products API
The Product to Products API returns the products that are related to an anchor product (often the product the user is currently engaging with) and are also likely to drive conversions by connecting with the user’s interests. It is different from the User to Products API as it not only considers the user’s interests but also considers the recommended products' relevancy to the anchor product.
Applicable scenarios
This API is frequently used in product detail page to show related products that users can consume further, such as "Related products" or "Up next". It is one of Miso's best performing APIs. Our customers usually see more than 30% and some times 110% relative lift in click-through rate after deploying this a feature using this API.
Basic usage
To use this API, you just need to let Miso knows the user_id (or anonymous_id) and the product_id you
want to get related recommendations for. For example, the following request will return the products that are
related to the movie Toy Story.
POST https://api.askmiso.com/v1/recommendation/product_to_products
{
"user_id": "user_123",
"product_id": ["toy-story-1995"],
"rows": 3,
"fl": ["title"]
}
- product_id: the id of the anchor product
- rows: the number of related products to return
- fl: like in other Miso API, you can use
flto control which fields to return for each Product
The response will be like:
{
"message": "success",
"data": {
"took": 56,
"miso_id": "f98b1904-ddce-11eb-be53-fa1729b23183",
"products": [
{
"product_id": "toy-story-2-1999",
"title": "Toy Story 2 (1999)"
},
{
"product_id": "toy-story-3-2010",
"title": "Toy Story 3 (2010)"
},
{
"product_id": "the-lion-king-1994",
"title": "The Lion King (1994)"
}
]
}
}
- products: a list of products related to the anchor product
- products[ ].product_id: the id of the recommended product
- products[ ].title: the title of the recommended product. You can use
flparameter to make Miso return more fields
Boosting and filtering
Like every Miso API, you can use fq and boost_fq to fine-tune the recommendations returned by Miso, and
Miso will guarantee to return the required number of recommendations that meet the given criteria.
For example, the following request still recommends movies related to "Toy Story" but limits the recommendations to only the movies released after year 2010.
POST https://api.askmiso.com/v1/recommendation/product_to_products
{
"user_id": "user_123",
"product_id": ["toy-story-1995"],
"rows": 3,
"fl": ["title"],
"fq": "custom_attributes.year: [2010 TO *]"
}
For another example, the following request will boost the movies that are acted by Tom Hanks. The boosting is
different from filtering as it only prioritizes those products that match the boosting criteria and are relevant to
the anchor products, but it will not limit the results to only such products.
POST https://api.askmiso.com/v1/recommendation/product_to_products
{
"user_id": "user_123",
"product_id": ["toy-story-1995"],
"rows": 3,
"fl": ["title"],
"boost_fq": "custom_attributes.actors:\"Tom Hanks\""
}
Multiple anchor products
In the scenarios where you want to recommend products related to multiple anchor products, for example,
for shopping cart cross-sell or up-sell, you can use product_ids
parameter and have multiple product ids in it.
For instance, the following request recommends products related to movies "Toy Story" and "Monsters, Inc." that will be of interest to the the current user.
POST https://api.askmiso.com/v1/recommendation/product_to_products
{
"user_id": "user_123",
"product_ids": ["toy-story-1995", "monsters-inc-2001"],
"rows": 3,
"fl": ["title"]
}
Attributes for recommendation boosting
- Type: array · Additional Interactionsadditional
_interactions A list of additional interaction records. You can use this fields to simulate user interactions without actually writing them to the interaction dataset.
- Type: string · Anonymous Idanonymous
_id The anonymous visitor who made the query and for whom Miso will personalize the results. Either
user_idoranonymous_idneeds to be specified for personalization to work. - Type: string · Boost Fqboost
_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_positionsparameter below.) For example, the query below will promote all the relevant products whose brand isNiketo 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 SALEto 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_positionsto 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.diversificationparameter, 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} } } - Type: array integer[] · Boost Positionsboost
_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
Nikeas the top and second recommendations:{ "boost_fq": "brand:\"Nike\"", "boost_positions": [0, 1] }If
boost_positionsis not specified (which is the default behavior), all the boosted products will be ranked higher than the rest of the products. - Type: string · Boost Rule Nameboost
_rule _name Name of the boosting rule. Use this to identify a boosting rule in _boosted_rules in the response
- Type: array object[] · Boost Rulesboost
_rules Define a list of boosting rules that will be applied to the search or recommendation results simultaneously.
boost_rulesparameter 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 isNiketo the top and second results, and products whose brand isAdidasto the third and fourth results:{ "boost_rules": [ { "boost_fq": "brand:\"Nike\"", "boost_positions": [0, 1] }, { "boost_fq": "brand:\"Adidas\"", "boost_positions": [2, 3] } ] } - Type: array string[] · Boosting Tags
When
boosting_tagsis 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.
- Type: boolean · Buy Togetherbuy
_together Whether to focus on the Products that are frequently bought together.
buy_togetherparameter is by defaultfalse, which make the Product To Products API focus on Products that are related to the anchor products, e.g. the products with similar contents or frequently attract the interests of the same group of users.When
buy_together=true, the ProductToProducts API will focus on the type of Products that are more frequently bought together along with the anchor product(s) in the same transactions or session. - Type: object · Custom Contextcustom
_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, whereKEYmust be a string, andVALUEcan be:- a
bool - a
stringor anarray of string - a
numberor anarray of numbers - an
array of objects null
In certain cases, Miso will take these variables into account when generating results.
- a
- Type: boolean · Dedupe Product Group Iddedupe
_product _group _id Whether to dedupe product based on
product_group_id. Ifdedupe_product_group_id=true, Miso will prevent products with the sameproduct_group_idfrom 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.
- Type: number · Ditheringditheringmin: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.
- Type: object · Diversificationdiversification
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.
diversificationparameter allows you to avoid this problem by enforcing a desired minimum distance between products. For example, consider a list of four products whosebrandare 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.
- application/json
- application/json
curl 'https://api.askmiso.com/v1/recommendation/product_to_products?api_key=YOUR_SECRET_TOKEN' \
--request POST \
--header 'Content-Type: application/json' \
--data '{
"product_id": "",
"product_ids": [
""
],
"product_group_id": "",
"product_group_ids": [
""
],
"buy_together": false,
"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"
}
]
}
}