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:
Define sort policies in
SortConfs. Each policy has a name and a type, and encapsulates the logic for one sorting behavior.Activate policies per scenario in
SortNames. Reference the names you defined inSortConfsto 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:
| Field | Type | Required | Description |
|---|---|---|---|
Name | string | Yes | A custom name for the policy. Reference this name in SortNames. |
SortType | string | Yes | The 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
| Field | Type | Required | Description |
|---|---|---|---|
Name | string | Yes | A custom sort name. |
SortType | string | Yes | Set to BoostScoreSort. |
Debug | bool | No | If 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. |
BoostScoreConditions | json array | Yes | One or more conditional boost/demotion rules. |
BoostScoreConditions[].Conditions | []FilterParamConfig | Yes | The conditions that must be met for the expression to apply. |
BoostScoreConditions[].Expression | string | Yes | The score adjustment expression. score refers to the current item score. Can reference item properties — for example, score * item_weight. |
FilterParamConfig fields
| Field | Type | Required | Description |
|---|---|---|---|
Name | string | Yes | The feature name on the item or user. |
Domain | string | Yes | item or user. Specifies whether Name is an item feature or a user feature. The name must exist in the item or user properties. |
Operator | string | Yes | Comparison operator. Valid values: equal, not_equal, in, not_in, greater, greaterThan, less, lessThan, contains, not_contains. |
Type | string | Yes | The data type of the feature. |
Value | object | Yes | The 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
| Field | Type | Required | Description |
|---|---|---|---|
AdapterType | string | Yes | The data source type. Only hologres is supported. |
HologresName | string | Yes | The custom name of the Hologres instance as configured in HologresConfs. |
HologresTableName | string | Yes | The name of the item weight table in Hologres. |
ItemFieldName | string | Yes | The primary key field of the item weight table. |
WeightFieldName | string | Yes | The 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.
DiversityRuleSortmust be used with theExcludeRecallsparameter.
Key concepts
Diversification dimension: The item property to diversify on, such as
category,author, ortag.IntervalSize (k): The maximum number of consecutive items from the same dimension value. For example,
IntervalSize: 2means 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: 2means 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
| Field | Type | Required | Description |
|---|---|---|---|
Name | string | Yes | A custom sort name. |
SortType | string | Yes | Set to DiversityRuleSort. |
DiversitySize | int | No | The number of items to apply diversity rules to. Defaults to the size of the request. |
Conditions | []FilterParamConfig | No | Apply diversity rules only when user properties match these conditions. Set Domain to user. For details, see Operator examples for conditional matching. |
ExcludeRecalls | []string | No | Recall channel IDs to exclude from diversity sorting. |
DiversityRules | json array | Yes | One or more diversity rules. |
DiversityRules[].Dimensions | []string | Yes | Item properties to diversify on. |
DiversityRules[].IntervalSize | int | Yes | Maximum consecutive items from the same dimension value (k). |
DiversityRules[].WindowSize | int | No | Sliding window size (n). |
DiversityRules[].FrequencySize | int | No | Maximum occurrences of the same dimension value within the window (m). |
DiversityRules[].Weight | int | No | Weight of this diversity rule. Used when no item satisfies all rules — see selection logic below. |
ExclusionRules | json array | No | Exclude items matching conditions from specific output positions. |
ExclusionRules[].Positions | []int | Yes | Output positions to exclude from (starting from 1). |
ExclusionRules[].Conditions | []FilterParamConfig | Yes | Conditions for item exclusion. For details, see Operator examples for conditional matching. |
ExploreItemSize | int | No | The 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
| Field | Type | Required | Description |
|---|---|---|---|
Name | string | Yes | A custom sort name. |
DaoConf | DaoConfig | Yes | Hologres connection information. |
TableName | string | No | The embedding vector table in Hologres. Required if EmbeddingHookNames is not set. |
TableSuffixParam | string | No | If 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. |
TablePKey | string | No | The primary key of the embedding vector table. |
EmbeddingColumn | string | No | The vector field in the embedding table. |
EmbeddingSeparator | string | No | The separator for embedding values. Default: comma. |
Alpha | float | Yes | Controls the relevance-diversity tradeoff. A larger value favors relevance. |
CacheTimeInMinutes | int | No | How long to cache embedding vectors in memory, in minutes. Default: 360. |
EmbeddingHookNames | []string | No | Names of functions that generate item embeddings. Functions must be registered in advance. |
NormalizeEmb | string | No | Whether to apply L2 normalization to embeddings. If normalization was already applied during generation, leave this unset. Otherwise, set to true. |
WindowSize | int | No | The sliding window size. Diversity is enforced within the window only. Default: 10. |
EmbMissedThreshold | float | No | Reports an error if the proportion of items missing embeddings exceeds this value. Default: 0.5. |
FilterRetrieveIds | []string | No | Items that bypass DPP processing, such as cold-start items. |
EnsurePositiveSim | string | No | Whether to ensure computed item similarity is positive. Default: true. |
CandidateCount | int | No | The 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. |
AbortRunCount | int | No | Skip diversification if the number of items entering the sort stage is below this value. Default: 0. |
MinScorePercent | float | No | An 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
| Field | Type | Required | Description |
|---|---|---|---|
Name | string | Yes | A custom sort name. |
DaoConf | DaoConfig | Yes | Hologres connection information. |
TableName | string | No | The embedding vector table in Hologres. Required if EmbeddingHookNames is not set. |
TableSuffixParam | string | No | If 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. |
TablePKey | string | No | The primary key of the embedding vector table. |
EmbeddingColumn | string | No | The vector field in the embedding table. |
EmbeddingSeparator | string | No | The separator for embedding values. Default: comma. |
Gamma | float | Yes | Controls the relevance-diversity tradeoff. A larger value favors diversity. |
UseSSDStar | bool | No | Enables the optimization from the SSD paper. Default: false. Enabling it is recommended. |
CacheTimeInMinutes | int | No | How long to cache embedding vectors in memory, in minutes. Default: 360. |
EmbeddingHookNames | []string | No | Names of functions that generate item embeddings. Functions must be registered in advance. |
NormalizeEmb | string | No | Whether to apply L2 normalization to embeddings. If already applied during generation, leave this unset. Otherwise, set to true. |
WindowSize | int | No | The sliding window size. Diversity is enforced within the window only. Default: 5. |
EmbMissedThreshold | float | No | Reports an error if the proportion of items missing embeddings exceeds this value. Default: 0.5. |
FilterRetrieveIds | []string | No | Items that bypass SSD processing, such as cold-start items. |
EnsurePositiveSim | string | No | Whether to ensure computed item similarity is positive. Default: true. |
CandidateCount | int | No | The candidate set size for diversification. Defaults to all items entering the sort stage. |
AbortRunCount | int | No | Skip diversification if the number of items entering the sort stage is below this value. Default: 0. |
MinScorePercent | float | No | An 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
| Field | Type | Required | Description |
|---|---|---|---|
Name | string | Yes | A custom sort name. |
SortType | string | Yes | Set to MultiRecallMixSort. |
RemainItem | bool | No | If 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. |
MixSortRules | json array | Yes | One or more mixing rules. |
MixSortRules[].MixStrategy | string | Yes | random_position: items are inserted at random positions. fix_position: items are inserted at the positions specified by Positions. |
MixSortRules[].Positions | []int | No | Required when MixStrategy is fix_position. Positions start from 1. Mutually exclusive with PositionField. |
MixSortRules[].PositionField | string | No | An item property field that provides the target position. Only valid with fix_position. Mutually exclusive with Positions. |
MixSortRules[].Number | int | No | The absolute number of items to mix in. |
MixSortRules[].NumberRate | float | No | The proportion of items to mix in. Valid range: 0–1. Calculated as request_size × NumberRate. Only valid with random_position. |
MixSortRules[].RecallNames | []string | No | Recall 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 | []FilterParamConfig | No | Mix 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
defaultas the scenario name to apply the same policies across multiple scenarios.The list values must match the
Namefield of the corresponding entries inSortConfs.