PAI-Rec Engine Re-ranking and Discretization Configuration Examples

Updated at:

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

SortTypeWhat it does
DiversityRuleSortSpreads items across dimensions (category, brand, etc.) using a sliding window to prevent clustering
BoostScoreSortMultiplies 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:

PositionsConstraint
1–5At most 1 item from any single category
2–6At most 1 item from any single category
3–7At 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

ParameterValueEffect
DiversitySize20Apply discretization to the first 20 items only. Positions beyond 20 are unaffected.
Rule A Dimensionscategory_idEnforce the constraint on the item's leaf category.
Rule A WindowSize5Evaluate a window of 5 consecutive positions.
Rule A FrequencySize1At most 1 item from the same category per window.
Rule B Dimensionsbrand_idEnforce the constraint on the item's brand.
Rule B WindowSize4Evaluate a window of 4 consecutive positions.
Rule B FrequencySize1At 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). Tune WindowSize and FrequencySize based 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

ParameterValueEffect
DebugfalseDebug mode off.
Conditions[].Valueitem.gender != nil and user.gender != nil and item.gender == user.genderThree-part guard: both gender attributes must be present, and they must match.
Expressionscore * 1.5Matched 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.