User to Categories API
The User to Categories API returns the product categories that will drive the conversion for the current user, along with the recommended products for each returned category.
Application scenarios
This API is usually used in homepage recommendations, or category recommendations where recommendations are organized by categories, such as Netflix's "Action / Sci-Fi / Drama movies for you" or Amazon's "Recommendations for you in Grocery & Gourmet Food". The goal of such recommendations is to help users discover attractive products under the categories they have a high chance to be interested in.
Basic usage
For basic usage of this API, you just need to let Miso knows the user_id or
anonymous_id of the current users. Miso will return a list of top categories along with the recommended
Products under each of the categories.
POST https://api.askmiso.com/v1/recommendation/user_to_categories
{
"user_id": "user-123",
"rows": 2,
"products_per_category": 3,
"fl": ["title"]
}
- rows: the number of categories to return
- products_per_category: the number of Products to return per each category
- fl: like in other Miso API, you can use
flto control which fields to return for each Product
The response of this request will be like:
{
"message": "success",
"data": {
"took": 85,
"miso_id": "7cd6059c-dd54-11eb-8050-a62d401473b5",
"categories": [
{
"category": [
"Drama"
],
"total": 61510,
"recommended_products": [
{
"product_id": "tmdb-286217",
"title": "The Martian (2015)"
},
{
"product_id": "tmdb-281957",
"title": "The Revenant (2015)"
},
{
"product_id": "tmdb-68718",
"title": "Django Unchained (2012)"
}
]
},
{
"category": [
"Thriller"
],
"total": 21870,
"recommended_products": [
{
"product_id": "tmdb-11324",
"title": "Shutter Island (2010)"
},
{
"product_id": "tmdb-1949",
"title": "Zodiac (2007)"
},
{
"product_id": "tmdb-1422",
"title": "The Departed (2006)"
}
]
}
]
}
}
- categories: a list of categories recommended to the users.
-
categories[].category: the recommended category in the format of category hierarchy.
["Sci-Fi"]is a top level category,["Sci-Fi", "Space Travel"]is a second-level category underSci-Fi(a.k.a subcategory). - categories[].total: the total number of Products belonging to the category
- categories[].recommended_products: a list of Products (in that category) recommended to the users
Root Category
By default, User To Categories API recommends top level categories, but you can change this behavior
via root_category parameter. Miso will recommend the immediate sub-categories of the given root_category
For example, the following request will recommend sub-categories under
Science Fiction, for example ["Science Fiction", "Space Travel"] or ["Science Fiction", "Steampunk"]:
POST https://api.askmiso.com/v1/recommendation/user_to_categories
{
"user_id": "test",
"root_category": ["Science Fiction"]
}
In some cases you can get recommendations from any subcategory, whatever its parent category.
In such case, you can use wildcard * to achieve such results. For example, the following request will recommend
any sub-categories regardless their parent category:
POST https://api.askmiso.com/v1/recommendation/user_to_categories
{
"user_id": "test",
"root_category": ["*"]
}
Filter and boost query
Like every Miso API, User To Categories supports fq for filtering, and boost_fq for boosting. You can use
these parameters to make the recommendation results meet your exact business needs. For example, the following
request will recommend categories
that contain sufficient number of Products that meet the fq criteria, that is, films after 2010, and each Product
returned in the recommended_products list will also meet the fq criteria:
POST https://api.askmiso.com/v1/recommendation/user_to_categories
{
"user_id": "user-123",
"rows": 2,
"products_per_category": 3,
"fq": "custom_attributes.year: [2010 TO *]"
}
Similarly, you can use boost_fq to promote Products that meet your business criteria in each category. For example,
the following request will prioritize Products that are promoted (indicated by custom_attributes.promoted):
POST https://api.askmiso.com/v1/recommendation/user_to_categories
{
"user_id": "user-123",
"rows": 2,
"products_per_category": 3,
"boost_fq": "custom_attributes.promoted: true"
}
Latency considerations
User To Categories API is one of more complex API because it needs to first identify categories the user will be
interested in, and then find the top Products in that categories. We make this process real-time by pre-computing a
large number of top Products for each category, therefore the end-to-end latency is
usually under 100ms. To further reduce the latency, you can:
- Use a smaller
products_per_categoryto reduce number of products to return, or set it to zero if you do not need any. - Request only the necessary fields using
flparameters - Use a smaller
rowsto reduce number of categories to return
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: 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: string · Engine Idengine
_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.
- Type: array string[] · Excludeexclude
An array of
product_idsof products you want to exclude from search results. - Type: array string[] · Flfl
List of fields to retrieve. For example, the following request retrieves only the
titlefield of each product along with theproduct_id, which is always returned.{"fl": ["title"]}You can also match field names by using
*as a wildcard. For example, the query below retrieves thetitleand any custom attributes under theattributesdictionary.{"fl": ["title", "attributes.*"]}The following retrieves all the available fields:
{"fl": ["*"]}For the lowest latency, use an empty array to retrieve just the
product_idfield (which is the default).{"fl": []}
- application/json
- application/json
curl 'https://api.askmiso.com/v1/recommendation/user_to_categories?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"
],
"products_per_category": 5,
"root_category": [],
"fq": "",
"boost_fq": "",
"boost_positions": [
1
],
"boost_rule_name": "",
"boost_rules": [],
"geo": {
"filter": [],
"boost": []
}
}'
{
"message": "success",
"data": {
"took": 0,
"miso_id": "123e4567-e89b-12d3-a456-426614174000",
"categories": [
{
"category": [
"Miso T-Shirt Shop"
],
"total": 1000,
"recommended_products": 1000
}
]
}
}