All Products
Search
Document Center

:Configure re-ranking

Last Updated:Apr 01, 2026

The re-ranking stage runs after fine-grained sorting. Use it to adjust item scores, diversify recommendation results, and control how items from different recall channels are mixed.

How it works

Re-ranking is configured in two steps:

  1. Define sort policies in SortConfs. Each policy has a name and a type, and encapsulates the logic for one sorting behavior.

  2. Activate policies per scenario in SortNames. Reference the names you defined in SortConfs to control which policies apply to which scenarios.

{
    "SortConfs": [
        {
            "Name": "my-boost-policy",
            "SortType": "BoostScoreSort",
            ...
        }
    ],
    "SortNames": {
        "${scene_name}": ["my-boost-policy"]
    }
}

PAI-Rec provides the following built-in sort types: BoostScoreSort, BoostScoreByWeight, ItemRankScore, DiversityRuleSort, DPPSort, SSDSort, and MultiRecallMixSort.

Common fields

All sort policies share the following base fields:

FieldTypeRequiredDescription
NamestringYesA custom name for the policy. Reference this name in SortNames.
SortTypestringYesThe sort type. Valid values: ItemRankScore, BoostScoreSort, DiversityRuleSort, DPPSort, MultiRecallMixSort.

Sort policies

ItemRankScore

ItemRankScore sorts all items in descending order by score. It is built into the DPI engine — no separate configuration is needed. Reference it directly in SortNames.

Boost score sort (BoostScoreSort)

Use BoostScoreSort to boost or demote item scores after fine-grained sorting, based on item or user properties. For example, to surface women's apparel higher for female users, multiply the score for items where sex = female. To suppress low-quality items, apply score * 0.5 when a quality flag is below a threshold.

The policy applies a conditional expression to adjust scores:

  • Conditions: match items or users by property (for example, sex = female, category = electronics)

  • Expression: a formula applied to the score when conditions are met (for example, score * 1.5, score * 0.5)

Configuration example:

{
    "SortConfs": [
        {
            "Name": "BoostScoreSort",
            "SortType": "BoostScoreSort",
            "Debug": false,
            "BoostScoreConditions": [
                {
                    "Conditions": [
                        {
                            "Name": "sex",
                            "Domain": "item",
                            "Type": "string",
                            "Value": "gender",
                            "Operator": "equal"
                        }
                    ],
                    "Expression": "score * 2"
                }
            ]
        }
    ]
}

This configuration multiplies the score by 2 for items where the sex feature equals male.

BoostScoreSort fields

FieldTypeRequiredDescription
NamestringYesA custom sort name.
SortTypestringYesSet to BoostScoreSort.
DebugboolNoIf true, the original score before adjustment is stored as org_score in the item's properties. Enable the debug flag in the request to inspect this value. Do not enable in production.
BoostScoreConditionsjson arrayYesOne or more conditional boost/demotion rules.
BoostScoreConditions[].Conditions[]FilterParamConfigYesThe conditions that must be met for the expression to apply.
BoostScoreConditions[].ExpressionstringYesThe score adjustment expression. score refers to the current item score. Can reference item properties — for example, score * item_weight.

FilterParamConfig fields

FieldTypeRequiredDescription
NamestringYesThe feature name on the item or user.
DomainstringYesitem or user. Specifies whether Name is an item feature or a user feature. The name must exist in the item or user properties.
OperatorstringYesComparison operator. Valid values: equal, not_equal, in, not_in, greater, greaterThan, less, lessThan, contains, not_contains.
TypestringYesThe data type of the feature.
ValueobjectYesThe value to compare against.

For more information about conditional settings, see Adjust count filter (AdjustCountFilter).

Boost score by weight (BoostScoreByWeight)

Use BoostScoreByWeight when different items need different score multipliers stored in a Hologres table, rather than a rule-based expression. The score formula is weight × item.score.

Configuration example:

{
    "SortConfs": [
        {
            "Name": "BoostScoreByWeight",
            "SortType": "BoostScoreByWeight",
            "TimeInterval": 172800,
            "BoostScoreByWeightDao": {
                "AdapterType": "hologres",
                "HologresName": "pai_rec",
                "HologresTableName": "test",
                "ItemFieldName": "item_id",
                "WeightFieldName": "weight"
            }
        }
    ]
}

BoostScoreByWeightDao fields

FieldTypeRequiredDescription
AdapterTypestringYesThe data source type. Only hologres is supported.
HologresNamestringYesThe custom name of the Hologres instance as configured in HologresConfs.
HologresTableNamestringYesThe name of the item weight table in Hologres.
ItemFieldNamestringYesThe primary key field of the item weight table.
WeightFieldNamestringYesThe weight field in the item weight table.

Diversity rule sort (DiversityRuleSort)

Use DiversityRuleSort to prevent recommendations from clustering around a single category, author, or tag. The policy enforces spacing rules across one or more item properties.

DiversityRuleSort must be used with the ExcludeRecalls parameter.

Key concepts

  • Diversification dimension: The item property to diversify on, such as category, author, or tag.

  • IntervalSize (k): The maximum number of consecutive items from the same dimension value. For example, IntervalSize: 2 means no more than 2 consecutive items can share the same category.

  • WindowSize (n) and FrequencySize (m): Within a sliding window of n items, an item from the same dimension value cannot appear more than m times. For example, WindowSize: 10, FrequencySize: 2 means the same category can appear at most twice in any 10 consecutive positions.

Diversity rules apply to a single request only — cross-request diversity is not enforced.

Configuration example:

{
    "SortConfs": [
        {
            "Name": "DiversityRuleSort",
            "SortType": "DiversityRuleSort",
            "DiversitySize": 100,
            "DiversityRules": [
                {
                    "Dimensions": ["spfl"],
                    "WindowSize": 10,
                    "FrequencySize": 1
                }
            ],
            "ExcludeRecalls": [
                "ColdStartVideoVectorRecall",
                "LinUcbRecall_default2"
            ],
            "Conditions": [
                {
                    "Name": "spflPick",
                    "Domain": "user",
                    "Type": "string",
                    "Value": "",
                    "Operator": "equal"
                }
            ]
        }
    ]
}

DiversityRuleSort fields

FieldTypeRequiredDescription
NamestringYesA custom sort name.
SortTypestringYesSet to DiversityRuleSort.
DiversitySizeintNoThe number of items to apply diversity rules to. Defaults to the size of the request.
Conditions[]FilterParamConfigNoApply diversity rules only when user properties match these conditions. Set Domain to user. For details, see Operator examples for conditional matching.
ExcludeRecalls[]stringNoRecall channel IDs to exclude from diversity sorting.
DiversityRulesjson arrayYesOne or more diversity rules.
DiversityRules[].Dimensions[]stringYesItem properties to diversify on.
DiversityRules[].IntervalSizeintYesMaximum consecutive items from the same dimension value (k).
DiversityRules[].WindowSizeintNoSliding window size (n).
DiversityRules[].FrequencySizeintNoMaximum occurrences of the same dimension value within the window (m).
DiversityRules[].WeightintNoWeight of this diversity rule. Used when no item satisfies all rules — see selection logic below.
ExclusionRulesjson arrayNoExclude items matching conditions from specific output positions.
ExclusionRules[].Positions[]intYesOutput positions to exclude from (starting from 1).
ExclusionRules[].Conditions[]FilterParamConfigYesConditions for item exclusion. For details, see Operator examples for conditional matching.
ExploreItemSizeintNoThe maximum number of candidates to search when looking for an item that satisfies the diversity rules. Stops searching after this limit.

Selection logic

By default, an item is output only if it satisfies all diversity rules. If no candidate satisfies all rules, the first candidate found is selected.

With weighted rules, if no candidate satisfies all rules, the candidate satisfying the highest-weighted rules is selected. Ties are broken by position in the candidate list.

Example: exclusion rules and search depth

Items with tag = t1 are excluded from positions 1–4. Positions 1–4 still respect diversity rules, but items with tag = t1 cannot fill those positions.

{
    "Name": "DiversityRuleSort",
    "SortType": "DiversityRuleSort",
    "DiversityRules": [
        {
            "Dimensions": ["tag"],
            "WindowSize": 5,
            "FrequencySize": 1
        }
    ],
    "ExclusionRules": [
        {
            "Positions": [1, 2, 3, 4],
            "Conditions": [
                {
                    "Name": "tag",
                    "Domain": "item",
                    "Type": "string",
                    "Value": "t1",
                    "Operator": "equal"
                }
            ]
        }
    ],
    "ExploreItemSize": 200
}

Example: weighted diversity rules

{
    "Name": "DiversityRuleSort",
    "SortType": "DiversityRuleSort",
    "DiversityRules": [
        {
            "Dimensions": ["tag"],
            "WindowSize": 5,
            "FrequencySize": 1,
            "Weight": 1
        },
        {
            "Dimensions": ["category"],
            "WindowSize": 3,
            "FrequencySize": 1,
            "Weight": 3
        }
    ],
    "ExclusionRules": [
        {
            "Positions": [1],
            "Conditions": [
                {
                    "Name": "tag",
                    "Domain": "item",
                    "Type": "string",
                    "Value": "t1",
                    "Operator": "equal"
                }
            ]
        }
    ]
}

DPPSort

DPPSort applies the Determinantal Point Process (DPP) algorithm to balance relevance and diversity. For background on the algorithm, see An intuitive understanding of the DPP-based algorithm for improving recommendation diversity.

Prerequisites

DPPSort requires item embedding vectors that represent item content — not behavioral similarity.

  • Use: image embeddings, text description embeddings, or embeddings from static item attributes (categories, properties)

  • Avoid: embeddings trained from user behavioral data

The dimensions you want to diversify must be captured in the embeddings. For example, to diversify on price, the price feature must be included when training the embedding model.

Configuration example:

{
    "SortConfs": [
        {
            "Name": "DPPSort",
            "SortType": "DPPSort",
            "DPPConf": {
                "Name": "DPPSort",
                "DaoConf": {
                    "AdapterType": "hologres",
                    "HologresName": "geeko_rec"
                },
                "TableName": "item_embedding_metric_learning",
                "TableSuffixParam": "embedding_date",
                "TablePKey": "product_id",
                "EmbeddingColumn": "embedding",
                "Alpha": 4.5,
                "NormalizeEmb": "false",
                "WindowSize": 10
            }
        }
    ]
}

DPPConf fields

FieldTypeRequiredDescription
NamestringYesA custom sort name.
DaoConfDaoConfigYesHologres connection information.
TableNamestringNoThe embedding vector table in Hologres. Required if EmbeddingHookNames is not set.
TableSuffixParamstringNoIf set, the system retrieves the value of this parameter from Parameter Management in the PAI-Rec DPI Engine Service Management page, and appends it as a suffix to TableName. Use this to switch embedding tables daily. The Hologres table typically needs to be a partitioned table in this case.
TablePKeystringNoThe primary key of the embedding vector table.
EmbeddingColumnstringNoThe vector field in the embedding table.
EmbeddingSeparatorstringNoThe separator for embedding values. Default: comma.
AlphafloatYesControls the relevance-diversity tradeoff. A larger value favors relevance.
CacheTimeInMinutesintNoHow long to cache embedding vectors in memory, in minutes. Default: 360.
EmbeddingHookNames[]stringNoNames of functions that generate item embeddings. Functions must be registered in advance.
NormalizeEmbstringNoWhether to apply L2 normalization to embeddings. If normalization was already applied during generation, leave this unset. Otherwise, set to true.
WindowSizeintNoThe sliding window size. Diversity is enforced within the window only. Default: 10.
EmbMissedThresholdfloatNoReports an error if the proportion of items missing embeddings exceeds this value. Default: 0.5.
FilterRetrieveIds[]stringNoItems that bypass DPP processing, such as cold-start items.
EnsurePositiveSimstringNoWhether to ensure computed item similarity is positive. Default: true.
CandidateCountintNoThe candidate set size for diversification. Defaults to all items entering the sort stage. Set a smaller value to limit diversification to the top N items.
AbortRunCountintNoSkip diversification if the number of items entering the sort stage is below this value. Default: 0.
MinScorePercentfloatNoAn item must have a max-normalized score above this threshold to be eligible for output. Default: 0.

SSDSort

SSDSort applies the Structured Self-Distillation (SSD) algorithm as an alternative to DPP. For background, see Improving the diversity of recommendation results: an analysis of MMR/DPP/SSD principles.

SSDSort has the same prerequisites as DPPSort — item embedding vectors must represent content, not behavioral similarity. The key difference is the tuning parameter: Gamma (larger value = more diversity), compared to DPP's Alpha (larger value = more relevance).

Configuration example:

{
    "SortConfs": [
        {
            "Name": "SSDSort",
            "SortType": "SSDSort",
            "SSDConf": {
                "Name": "SSDSort",
                "DaoConf": {
                    "AdapterType": "hologres",
                    "HologresName": "geeko_rec"
                },
                "TableName": "item_embedding_metric_learning",
                "TablePKey": "item_id",
                "EmbeddingColumn": "embedding",
                "Gamma": 0.25,
                "UseSSDStar": true,
                "NormalizeEmb": "false",
                "MinScorePercent": 0.1,
                "CandidateCount": 200,
                "WindowSize": 5
            }
        }
    ]
}

SSDConf fields

FieldTypeRequiredDescription
NamestringYesA custom sort name.
DaoConfDaoConfigYesHologres connection information.
TableNamestringNoThe embedding vector table in Hologres. Required if EmbeddingHookNames is not set.
TableSuffixParamstringNoIf set, the system retrieves the value of this parameter from Parameter Management in the PAI-Rec DPI Engine Service Management page, and appends it as a suffix to TableName. Use this to switch embedding tables daily.
TablePKeystringNoThe primary key of the embedding vector table.
EmbeddingColumnstringNoThe vector field in the embedding table.
EmbeddingSeparatorstringNoThe separator for embedding values. Default: comma.
GammafloatYesControls the relevance-diversity tradeoff. A larger value favors diversity.
UseSSDStarboolNoEnables the optimization from the SSD paper. Default: false. Enabling it is recommended.
CacheTimeInMinutesintNoHow long to cache embedding vectors in memory, in minutes. Default: 360.
EmbeddingHookNames[]stringNoNames of functions that generate item embeddings. Functions must be registered in advance.
NormalizeEmbstringNoWhether to apply L2 normalization to embeddings. If already applied during generation, leave this unset. Otherwise, set to true.
WindowSizeintNoThe sliding window size. Diversity is enforced within the window only. Default: 5.
EmbMissedThresholdfloatNoReports an error if the proportion of items missing embeddings exceeds this value. Default: 0.5.
FilterRetrieveIds[]stringNoItems that bypass SSD processing, such as cold-start items.
EnsurePositiveSimstringNoWhether to ensure computed item similarity is positive. Default: true.
CandidateCountintNoThe candidate set size for diversification. Defaults to all items entering the sort stage.
AbortRunCountintNoSkip diversification if the number of items entering the sort stage is below this value. Default: 0.
MinScorePercentfloatNoAn item must have a max-normalized score above this threshold to be eligible for output. Default: 0.

Multi-channel recall sort (MultiRecallMixSort)

Use MultiRecallMixSort when you have multiple recall channels and need to control how their results are interleaved in the final output. Common use cases:

  • Guarantee minimum exposure for cold-start items

  • Pin items from a specific recall channel to fixed positions

Configuration example (recall-name-based mixing):

{
    "SortConfs": [
        {
            "Name": "MixSort",
            "SortType": "MultiRecallMixSort",
            "RemainItem": false,
            "MixSortRules": [
                {
                    "MixStrategy": "random_position",
                    "NumberRate": 0.1,
                    "RecallNames": ["OTSGlobalHot"]
                },
                {
                    "MixStrategy": "fix_position",
                    "Positions": [1, 3, 5],
                    "RecallNames": ["RecallName1"]
                }
            ]
        }
    ]
}

You can also select items by item property conditions instead of recall names:

{
    "SortConfs": [
        {
            "Name": "MixSortByItemFeature",
            "SortType": "MultiRecallMixSort",
            "RemainItem": false,
            "MixSortRules": [
                {
                    "MixStrategy": "random_position",
                    "NumberRate": 0.1,
                    "Conditions": [
                        {
                            "Name": "gender",
                            "Domain": "item",
                            "Type": "string",
                            "Value": "man",
                            "Operator": "equal"
                        }
                    ]
                }
            ]
        }
    ]
}

MultiRecallMixSort fields

FieldTypeRequiredDescription
NamestringYesA custom sort name.
SortTypestringYesSet to MultiRecallMixSort.
RemainItemboolNoIf false, only the mixed results are output. If true, items not selected by mixing rules are appended after the mixed results, allowing downstream sort stages to process them further.
MixSortRulesjson arrayYesOne or more mixing rules.
MixSortRules[].MixStrategystringYesrandom_position: items are inserted at random positions. fix_position: items are inserted at the positions specified by Positions.
MixSortRules[].Positions[]intNoRequired when MixStrategy is fix_position. Positions start from 1. Mutually exclusive with PositionField.
MixSortRules[].PositionFieldstringNoAn item property field that provides the target position. Only valid with fix_position. Mutually exclusive with Positions.
MixSortRules[].NumberintNoThe absolute number of items to mix in.
MixSortRules[].NumberRatefloatNoThe proportion of items to mix in. Valid range: 0–1. Calculated as request_size × NumberRate. Only valid with random_position.
MixSortRules[].RecallNames[]stringNoRecall channel names to source items from. Multiple names share the rule configuration, but the specific channel used is determined by the order items entered the sort stage.
MixSortRules[].Conditions[]FilterParamConfigNoMix items that match these conditions. For details, see Operator examples for conditional matching.

Activate sort policies

After defining policies in SortConfs, reference them by name in SortNames to activate them for specific scenarios. SortNames is a Map[string]object where each key is a scenario name and the value is a list of policy names to apply.

{
    "SortNames": {
        "${scene_name}": ["ItemRankScore"]
    }
}
  • Use default as the scenario name to apply the same policies across multiple scenarios.

  • The list values must match the Name field of the corresponding entries in SortConfs.