PAI-Rec Engine Re-ranking and Discretization Configuration Examples
The re-ranking stage balances two competing goals: relevance (surfacing items the user is most likely to want) and diversity (preventing the list from being dominated by a single category or brand). These examples show how to configure two common re-ranking rule types and are for illustration only—they may not suit every business scenario.
Available rule types
SortType | What it does |
|---|---|
DiversityRuleSort | Spreads items across dimensions (category, brand, etc.) using a sliding window to prevent clustering |
BoostScoreSort | Multiplies the score of items that match a conditional expression, promoting them up the ranked list |
Prevent category and brand clustering in the top results
When too many consecutive items share the same category or brand, users experience visual fatigue. A sliding window constraint controls how often items from the same dimension can appear within a moving window of positions.
How the sliding window works
The window moves one position at a time through the list. Within each window, the frequency of any one dimension value cannot exceed FrequencySize. For example, with WindowSize: 5 and FrequencySize: 1 on category_id:
| Positions | Constraint |
|---|---|
| 1–5 | At most 1 item from any single category |
| 2–6 | At most 1 item from any single category |
| 3–7 | At most 1 item from any single category |
This configuration applies two rules simultaneously: one for leaf categories and one for brands.
{
"Name": "CategoryDiversityRuleSort",
"SortType": "DiversityRuleSort",
"DiversitySize": 20,
"DiversityRules": [
{
"Dimensions": [
"category_id"
],
"WindowSize": 5,
"FrequencySize": 1
},
{
"Dimensions": [
"brand_id"
],
"WindowSize": 4,
"FrequencySize": 1
}
]
}Parameter reference
| Parameter | Value | Effect |
|---|---|---|
DiversitySize | 20 | Apply discretization to the first 20 items only. Positions beyond 20 are unaffected. |
Rule A Dimensions | category_id | Enforce the constraint on the item's leaf category. |
Rule A WindowSize | 5 | Evaluate a window of 5 consecutive positions. |
Rule A FrequencySize | 1 | At most 1 item from the same category per window. |
Rule B Dimensions | brand_id | Enforce the constraint on the item's brand. |
Rule B WindowSize | 4 | Evaluate a window of 4 consecutive positions. |
Rule B FrequencySize | 1 | At most 1 item from the same brand per window. |
Note: If your item catalog is small or certain categories have very high weights, strict constraints can reduce overall click-through rate (CTR). TuneWindowSizeandFrequencySizebased on catalog size and observed CTR impact. For details on all re-ranking plug-ins, see the PAI-Rec documentation.
Boost scores when user and item gender match
When a user's gender attribute matches an item's gender attribute, the item receives a score multiplier, moving it higher in the ranked list. Items that do not match keep their original score (an implicit multiplier of 1).
{
"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"
}
]
}Parameter reference
| Parameter | Value | Effect |
|---|---|---|
Debug | false | Debug mode off. |
Conditions[].Value | item.gender != nil and user.gender != nil and item.gender == user.gender | Three-part guard: both gender attributes must be present, and they must match. |
Expression | score * 1.5 | Matched items receive a 50% score boost. Non-matching items keep their original score (score * 1). |
Note: The nil checks are required. Ensure both sides of a matching condition have non-null values before the condition is evaluated.