In the re-ranking stage of a recommendation system, the main goal is to balance recommendation quality (relevance) and user experience (diversity). The following sections explain the configuration items you provided. These examples are for illustration only and may not be suitable for real business scenarios.
1. Rerank and discretize leaf categories and brands
To avoid showing too many items from the same category or brand—which can cause visual fatigue—use a sliding window mechanism to discretize recommendations.
Core logic: Within a specified window size (
WindowSize), limit how often items from a specific dimension appear (FrequencySize).Parameter details:
DiversitySize (20): Apply discretization only to the first 20 items in the recommendation list. This ensures a better experience for top traffic.
Rule A (Discretize by leaf category):
Dimension:
category_id(backend first-level or leaf category).Constraint: In any sequence of 5 consecutive items, items from the same category appear at most 1 time.
Rule B (Discretize by brand):
Dimension:
brand_id(brand ID).Constraint: In any sequence of 4 consecutive items, items from the same brand appear at most 1 time.
Configuration tip: If your item catalog is small or certain categories have very high weights, overly strict discretization—such as a large WindowSize—may reduce overall click-through rate (CTR). For more details about re-ranking plug-ins, see the PAI-Rec official documentation.
{
"Name": "CategoryDiversityRuleSort",
"SortType": "DiversityRuleSort",
"DiversitySize": 20,
"DiversityRules": [
{
"Dimensions": [
"category_id"
],
"WindowSize": 5,
"FrequencySize": 1
},
{
"Dimensions": [
"brand_id"
],
"WindowSize": 4,
"FrequencySize": 1
}
]
}2. Boost scores when user gender matches item gender
Configure rules to boost scores for items that meet specific conditions. This improves user-product matching accuracy.
Core logic: When a user’s gender label matches an item’s gender property, increase the item’s final sort score dynamically.
Parameter details:
Judgment conditions (
Conditions):item.gender != nilanduser.gender != nil: Ensure both user and item gender data exist.item.gender == user.gender: Match user gender with item gender.
Boost formula (
Expression):score * 1.5.Effect: Items that match get a 50% score boost. This significantly increases their chance of appearing near the top of the recommendation list.
{
"Name": "BoostScoreSort",
"SortType": "BoostScoreSort",
"Debug": false,
"BoostScoreConditions": [
{
"Conditions": [
{
"Operator": "expression",
"Value": "item.gender!= nil and user.gender != nil and item.gender==user.gender"
}
],
"Expression": "score * 1.5"
}
]
}