Re-ranking configuration

Updated at:

The re-ranking (Sort) stage runs after the ranking stage. In this stage, you can reorder items, diversify results, and add rules such as window rules.

How to configure

Re-ranking is configured through SortConfs in the configuration overview. SortConfs is a []object structure that supports multiple re-ranking strategies. PAI-Rec provides the following built-in strategies: BoostScoreSort, BoostScoreByWeight, ItemRankScore, DiversityRuleSort, DPPSort, and MultiRecallMixSort.

Common re-ranking configurations

Each re-ranking configuration uses some of these common parameters. They are described here only and are not repeated in the individual re-ranking sections.

Configuration example:

{
    "SortConfs": [
        {
            "Name": "",
            "SortType": ""
        }
    ]
}

Field

Type

Required

Description

Name

string

Yes

Custom re-ranking name, referenced in SortNames.

SortType

string

Yes

Re-ranking type. Valid values:

  • ItemRankScore

  • BoostScoreSort

  • DiversityRuleSort

  • DPPSort

  • MultiRecallMixSort

  • TrafficControlSort

Boost score re-ranking (BoostScoreSort)

After the ranking model runs, each item has a score returned by the model. Business requirements sometimes call for adjusting this score, which is the boost operation.

A boost has two configuration parts:

  • Set the condition rules. These rules use item or user attributes, such as category or gender, to determine whether an item matches the condition.

  • Set the boost expression. Currently, expressions apply only to score. For example: score * 1.2, score * 0.5, and so on.

Configuration example

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

The preceding configuration doubles the score of each item whose sex feature equals male.

Field

Type

Required

Description

Name

string

Yes

Custom re-ranking name.

SortType

string

Yes

Re-ranking type. Fixed value: BoostScoreSort.

Debug

bool

No

Test flag. When this flag is set to true, the original score before boosting is recorded in the item properties as org_score. Enable the debug flag in the request to view the item attribute values. This flag is for debugging only. Do not enable it in production.

BoostScoreConditions

json array

Yes

Boost condition configurations. Configure multiple entries to apply different boosts based on different conditions.

  • Conditions

[]FilterParamConfig

Yes

The condition rules for the boost.

  • Expression

string

Yes

The expression used to boost the score. score indicates the current item score. The expression can reference item attributes. For example, item_weight is an item attribute, so the expression can be set to score * item_weight.

The following table describes FilterParamConfig:

Field

Type

Required

Description

Name

string

Yes

The name of the item or user feature

Domain

string

Yes

Valid values: item/user. Indicates whether the Name field is an item feature or a user feature. Name must exist in the properties of the item or user.

Operator

string

Yes

Valid values: equal/not_equal/in/not_in/greater/greaterThan/less/lessThan/contains/not_contains

Type

string

Yes

The type of the feature

Value

object

Yes

The value of the feature

For details about condition settings, see AdjustCountFilter .

Weight-based boost re-ranking (BoostScoreByWeight)

When you boost items, each item may have a different weight. This weight is a field in the item table. Use the weight field to boost the score.

The score is calculated as 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

Field

Type

Required

Description

AdapterType

string

Yes

The data source type. Currently, only hologres is supported.

HologresName

string

Yes

The custom name of the Hologres data source configured in the data source configuration (HologresConfs), such as holo_info.

HologresTableName

string

Yes

The name of the item weight table in Hologres.

ItemFieldName

string

Yes

The primary key of the item weight table.

WeightFieldName

string

Yes

The weight field in the item weight table.

Item score re-ranking (ItemRankScore)

ItemRankScore sorts items in descending order by item score. This strategy is built into the engine and can be used directly in SortNames.

Diversity re-ranking (DiversityRuleSort)

When recommendation results are returned, they must match user interests and also be diverse. Items from different categories or with different attributes can be mixed in the output.

The rules are configured as follows:

Recommendation diversity and diversification rules

Key terms:

  1. Diversification dimension: an item attribute used for diversification, such as category, author, or tag.

  2. Diversification policy:

    • Minimum interval k: a diversification dimension can appear at most k times in a row.

    • Maximum occurrences m: within a window of size n, items that share the same diversification dimension cannot appear more than m times.

Diversification logic:

  • Diversification rules apply only within the results of a single request. Cross-request diversity is not considered.

  • Multiple diversification dimensions are supported.

  • Each diversification dimension supports multiple diversification policies, and each policy takes its own parameters (k, m, n).

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"
                }
            ]
        }
    ]
}

This re-ranking type must be used together with the ExcludeRecalls parameter.

DiversityRules

Field

Type

Required

Description

Name

string

Yes

Custom re-ranking name

SortType

string

Yes

Re-ranking type. Fixed value: DiversityRuleSort

DiversitySize

int

No

Number of items to diversify. Default value: the size of the request

Conditions

[]FilterParamConfig

No

Diversification rule conditions. The diversification rules apply only when the user attributes meet the specified conditions. For information about how to configure conditions, see Operator examples. Configure these conditions based on user attributes by setting Domain = user

ExcludeRecalls

[]string

No

List of recall IDs to exclude from diversity re-ranking

DiversityRules

json array

Yes

Diversification rules. Multiple rules are supported

  • Dimensions

[]string

Yes

Item attributes to use for diversification

  • IntervalSize

int

Yes

Number of times that items sharing the same dimension can appear consecutively. This is the k value described above

  • WindowSize

int

No

Window size. This is the n value described above

  • FrequencySize

int

No

Number of repetitions allowed within the window. This is the m value described above

  • Weight

int

No

Weight of the diversity rule

ExclusionRules

json array

No

Exclusion rules. Exclude specific items that meet the conditions from the specified positions

  • Positions

[]int

Yes

Output position of the item, starting from 1. If the request specifies size=10, the positions are 1,2,3...10

  • Conditions

[]FilterParamConfig

Yes

Rule conditions. For information about how to configure conditions, see Operator examples. Configure these conditions based on item attributes.

ExploreItemSize

int

No

By default, if the first item in the candidate set does not meet the diversification rules, the engine keeps searching until the entire candidate set is searched. This parameter limits the number of candidates to search. The search stops when this value is exceeded

The following example shows exclusion rules and the search depth:

Items that match tag=t1 must not appear in output positions 1, 2, 3, and 4. The items in positions 1, 2, 3, and 4 must still meet the diversification rules, but none of them can have tag=t1.

{
    "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
}

When the engine searches for items that meet the diversity rules, an item is returned by default only if it meets all rules. If an item fails any diversity rule, the engine searches for the next item until it finds one that meets all rules. If no item in the candidate set meets all rules, the first item searched is returned.

An alternative policy assigns a weight to each diversity rule. If no item in the candidate set meets all rules, the engine returns the item with the highest total weight of the rules it meets. If multiple items tie, the engine returns the one in the earliest position.

The following configuration includes weights:

{
    "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"
                }
            ]
        }
    ]
}

Multi-value dimension diversification (MultiValueDimensionConf)

By default, each item attribute in Dimensions is treated as a single-value attribute. The engine compares the string values exactly to determine whether two items belong to the same dimension. In some cases, however, an item attribute is multi-value. For example, a product can belong to multiple categories or carry multiple tags, such as tag = "sports,news,tech". Use MultiValueDimensionConf to declare such a dimension as a multi-value dimension. The engine then splits the attribute value by the delimiter before it evaluates the diversification rules.

Diversification logic: for a multi-value dimension, two items are considered "identical" in that dimension if they share any single value, so the diversification rules apply to them. For a regular (single-value) dimension, two items are considered identical only when their values are exactly equal. When a diversification rule specifies multiple Dimensions, two items are treated as being in the same dimension only if they are considered identical in all of the dimensions.

Configuration example

{
  "SortConfs": [
    {
      "Name": "DiversityRuleSort",
      "SortType": "DiversityRuleSort",
      "DiversityRules": [
        {
          "Dimensions": ["tag"],
          "WindowSize": 5,
          "FrequencySize": 1
        }
      ],
      "MultiValueDimensionConf": [
        {
          "DimensionName": "tag",
          "Delimiter": ","
        }
      ]
    }
  ]
}

The preceding configuration declares the tag attribute of an item as a multi-value field separated by commas, such as "sports,news,tech". The engine splits the value by comma before it diversifies. Within a window of size 5, two items are considered duplicates if their tag values share any single tag, and such an item can appear at most once.

Field

Type

Required

Description

DimensionName

string

Yes

Name of the multi-value dimension. The name must match one of the dimension names in DiversityRules.Dimensions and must be an item attribute name

Delimiter

string

Yes

Delimiter of the multi-value attribute. The engine splits the attribute value into multiple values by this delimiter, for example a comma ","

Usage notes

  • MultiValueDimensionConf supplements the dimensions already defined in DiversityRules. A dimension name configured here takes effect only if it also appears in Dimensions.

  • Configure only the multi-value attributes. Dimensions that are not listed here are still matched exactly as single-value attributes.

  • Multiple multi-value dimensions are supported.

Diversity re-ranking V2 (DiversityRuleSortV2)

DiversityRuleSortV2 is an enhanced version of DiversityRuleSort (V1). It inherits all diversification capabilities of V1 and adds the cross-page diversification (Cross-Page Diversity) feature, which resolves the issue that diversification rules stop working between adjacent pages in pagination scenarios.

Relationship with DiversityRuleSort (V1)

DiversityRuleSortV2 fully inherits all V1 capabilities:

  • Multi-dimension diversification rules (Dimensions)

  • Minimum interval policy (IntervalSize) and window frequency policy (WindowSize / FrequencySize)

  • Rule weight fallback (Weight)

  • Position exclusion rules (ExclusionRules)

  • Recall exclusion (ExcludeRecalls)

  • Conditional triggering (Conditions)

  • Search depth control (ExploreItemSize)

  • Multi-value dimension diversification (MultiValueDimensionConf)

  • A/B experiment parameter cloning (CloneWithConfig)

If CrossPageDiversity is not configured, V2 behaves exactly the same as V1.

Cross-page diversification (V2 only)

Background

V1 diversification rules take effect only within the results returned by a single request. In pagination scenarios such as scroll-to-load, each request is diversified independently. As a result, the tail of the previous page and the head of the next page may show the same category or attribute back to back, which degrades the user experience.

For example, the last three items on page 1 all belong to the "Electronics" category, and page 2 opens with the "Electronics" category again. To users, diversification looks broken.

How it works
  1. Client parameters: In each pagination request, the client passes the item IDs from the tail of the previous page to the engine through a request parameter (default: last_page_item_ids).

  2. Dimension value loading: The engine queries the diversification dimension values of these items, such as category or author, from the data source specified in DiversityDaoConf.

  3. History warm-up: The engine injects the dimension values from the tail of the previous page into the matching window of the diversification rules as a "history prefix".

  4. Constraint enforcement: Diversification matching for the current page takes the history prefix into account, so items at the head of the current page also satisfy the diversification rules relative to the tail of the previous page.

Note: The history prefix affects only the Match evaluation of the diversification rules. It never enters the final result list , and it does not consume DiversitySize slots.
Seed policy optimization

V1 places the first item of the candidate set into the result unconditionally, without any Match check. When cross-page warm-up succeeds (warmed=true), V2 skips the unconditional seed logic, so every item, including the first one, must pass diversification rule matching. This keeps the items at the head of the page within the cross-page window constraints. When warm-up does not occur, V2 behaves exactly the same as V1.

Automatic fallback
  • Data source (DAO) construction fails → cross-page diversification turns off automatically and behavior falls back to V1

  • The request does not carry the last_page_item_ids parameter → warm-up is skipped and behavior falls back to V1

  • Dimension value query fails → warm-up is skipped and behavior falls back to V1

  • A diversification dimension is not covered by DistinctFields → a Warning log is printed at startup, and cross-page warm-up does not take effect for that dimension

Configuration example

Basic configuration (same as V1)
{
  "SortConfs": [
    {
      "Name": "DiversityRuleSortV2",
      "SortType": "DiversityRuleSortV2",
      "DiversitySize": 100,
      "DiversityRules": [
        {
          "Dimensions": ["category"],
          "WindowSize": 10,
          "FrequencySize": 1
        }
      ],
      "ExcludeRecalls": ["ColdStartRecall"],
      "Conditions": [
        {
          "Name": "user_level",
          "Domain": "user",
          "Type": "string",
          "Value": "vip",
          "Operator": "equal"
        }
      ]
    }
  ]
}
Enable cross-page diversification (V2 only)
{
  "SortConfs": [
    {
      "Name": "DiversityRuleSortV2",
      "SortType": "DiversityRuleSortV2",
      "DiversitySize": 100,
      "DiversityRules": [
        {
          "Dimensions": ["category"],
          "WindowSize": 6,
          "FrequencySize": 1
        },
        {
          "Dimensions": ["author"],
          "IntervalSize": 2
        }
      ],
      "CrossPageDiversity": {
        "Enable": true,
        "LastItemIdsParam": "last_page_item_ids",
        "DiversityDaoConf": {
          "AdapterType": "featurestore",
          "FeatureStoreName": "my_fs",
          "FeatureStoreViewName": "item_feature_view",
          "DistinctFields": ["category", "author"],
          "CacheTimeInMinutes": 60,
          "CacheSize": 100000
        }
      }
    }
  ]
}

Configuration field reference

Common fields (same as V1)

Field

Type

Required

Description

Name

string

Yes

Custom re-ranking name

SortType

string

Yes

Re-ranking type. Fixed value: DiversityRuleSortV2

DiversitySize

int

No

Number of items to diversify. Default value: the size of the request

Conditions

[]FilterParamConfig

No

Trigger conditions for the diversification rules. Diversification runs only when the user attributes match the conditions. Set Domain to user

ExcludeRecalls

[]string

No

Names of the recalls to exclude from diversity re-ranking. Items from the excluded recalls are appended to the end of the result

ExploreItemSize

int

No

Search depth control. By default, the engine searches the entire candidate set. After you set this value, the search stops once the number of candidate items searched exceeds this value

DiversityRules (same as V1)

Field

Type

Required

Description

Dimensions

[]string

Yes

Item attributes used for diversification, such as category, author, and tag

IntervalSize

int

No

Minimum interval k. The same diversification dimension can appear at most k consecutive times

WindowSize

int

No

Window size n

FrequencySize

int

No

Maximum number of repetitions m allowed within a window. The same dimension cannot appear more than m times in a window of size n

Weight

int

No

Rule weight. After you set this value, if no candidate item satisfies all the rules, the engine outputs the item with the highest sum of satisfied rule weights

ExclusionRules (same as V1)

Field

Type

Required

Description

Positions

[]int

Yes

List of excluded positions, starting from 1. Items that match the conditions do not appear in these positions

Conditions

[]FilterParamConfig

Yes

Exclusion conditions, typically based on item attributes. Set Domain to item

MultiValueDimensionConf (same as V1)

Field

Type

Required

Description

DimensionName

string

Yes

Name of the multi-value dimension. The value must correspond to a Dimensions entry in DiversityRules

Delimiter

string

Yes

Multi-value delimiter, used to split an item attribute value into multiple values for diversification evaluation

CrossPageDiversity (V2 only)

Field

Type

Required

Description

Enable

bool

Yes

Specifies whether to enable cross-page diversification. Default value: false

LastItemIdsParam

string

No

Name of the request parameter used to get the item IDs at the tail of the previous page. Default value: last_page_item_ids

DiversityDaoConf

object

Yes

Data source configuration for cross-page dimension values

DiversityDaoConf

Field

Type

Required

Description

AdapterType

string

Yes

Data source type. Valid values: hologres / featurestore

HologresName

string

Conditionally required

Required when AdapterType is hologres. The custom Hologres name in the data source configuration

HologresTableName

string

Conditionally required

Required when AdapterType is hologres. The name of the item attribute table in Hologres

ItemKeyField

string

Conditionally required

Required when AdapterType is hologres. The primary key field name of the item attribute table

FeatureStoreName

string

Conditionally required

Required when AdapterType is featurestore. The name of the FeatureStore data source

FeatureStoreViewName

string

Conditionally required

Required when AdapterType is featurestore. The name of the FeatureStore feature view

DistinctFields

[]string

Yes

List of diversification dimension fields to query. The list must cover all Dimensions in DiversityRules. Otherwise, cross-page warm-up does not take effect for the uncovered dimensions

CacheTimeInMinutes

int

No

Period of time, in minutes, for which dimension values are cached in memory

CacheSize

int

No

Cache capacity. Default value: 10000000

Client integration

After you enable cross-page diversification, the client must include the item IDs at the tail of the previous page in each pagination request:

  • Parameter name: Configured through LastItemIdsParam. Default: last_page_item_ids

  • How to pass the parameter: Through the features field of the recommendation API

  • Supported formats:

    • JSON array string: "[\"id1\",\"id2\",\"id3\"]"

    • Comma-separated string: "id1,id2,id3"

    • Array: ["id1", "id2", "id3"]

Note
Recommendation : Pass the IDs of the last 5 to 10 items on the previous page. The engine truncates the list to the maximum number required based on the window size of the diversification rules and ignores extra IDs.

Diversification logic

The core diversification logic remains the same as in V1:

  1. Search the candidate set in order and check whether each item satisfies all diversification rules and exclusion rules

  2. Output the item that satisfies all the rules, and then continue the search for the next item

  3. If no item in the candidate set satisfies all the rules:

    • With weights (Weight): Output the item with the highest sum of satisfied rule weights. If multiple items have the same weight, output the one in the earliest position

    • Without weights: Output the first item in the search range

  4. After diversification is complete, append the remaining items that did not take part in diversification to the end of the result

  5. Append the recall items excluded by ExcludeRecalls to the end of the final result

Additional behavior for cross-page diversification: Before step 1, the engine loads the dimension values of the items at the tail of the previous page and injects them into the diversification window as a history prefix. During Match evaluation, the window scan range = history prefix + items already selected on the current page, which guarantees diversification across page boundaries.

Traffic control re-ranking (TrafficControlSort)

Traffic control builds a traffic distribution system that balances platform interests with long-term value. It does so by designing and optimizing algorithms, strategies, and systems.

Benefits of traffic control:

  • Effective boosting: traffic control is a traffic intervention feature built on the PAI-Rec recommendation system architecture. It precisely adjusts traffic for the item pools that you select without disrupting the overall recommendation logic.

  • Measurable results: unlike traditional weighting, traffic control uses measurable metrics such as the impressions and impression share of an item pool as its control targets, which makes quantitative boosting easier to achieve.

  • Easy to manage: traffic control implements business goals as tasks. You can create a separate traffic control task for each type of traffic intervention requirement, which makes management flexible. You can start or end a task at any time.

  • Simple to operate: create a task and configure information such as the task goal. The system then adjusts traffic distribution automatically based on your configuration, so continuous observation and monitoring is not required.

For the traffic control algorithm tuning guide, see Tuning guide. For detailed traffic control settings, see Traffic control workflow.

Configuration example:

{
    "Name": "TrafficControlSort",
    "SortType": "TrafficControlSort",
    "PIDConf": {
        "DefaultKp": 5,
        "DefaultKi": 1,
        "DefaultKd": 1
    }
}

Main PID calculation logic:

Note

output = Kp × error + Ki × integralSum + Kd × derivative

dt = current measurement time - previous measurement time, in seconds

integralSum += integral coefficient × error × dt

derivative = (current error - previous error) / dt

PIDConf

Note

The Kp, Ki, and Kd parameters take part in the PID formula and determine the resulting alpha value. If you have only one traffic control task, only the ratios among these three parameters matter. If you have multiple traffic control tasks, their alpha values are summed, so the tasks effectively compete to decide which one has the stronger control. In that case, keep Kp, Ki, and Kd in the same order of magnitude. To strengthen the control of a specific task, increase the values of its three parameters as needed. Use A/B experiments to tune the parameter values of a specific task or target.

Field

Type

Required

Description

DefaultKp

Int

No

The proportional gain. It is multiplied by the current error, so a larger error produces stronger control. This is the main driver of the response. Default value: 1000.

DefaultKi

Int

No

The integral gain. It is multiplied by the accumulated error and eliminates steady-state offset (it keeps increasing when the target is missed over a long period). Default value: 10.

DefaultKd

Int

No

The derivative gain. It is multiplied by the rate of error change to suppress overshoot and speed up convergence. Default value: 10.

AllocateExperimentWise

Bool

No

Specifies whether to track target attainment for each experiment separately. true: each experiment maintains an independent PID state. false: the entire pipeline maintains a single PID state.

IntegralMin

Float64

No

Default value: -100. The lower bound of the integral, which limits the minimum value of integralSum. This is mainly used to limit negative integration and prevent reverse control from accumulating over a long period. The default value is overridden only when the configured value is < 0.

IntegralMax

Float64

No

Default value: 100. The upper bound of the integral, which limits the maximum value of integralSum. This prevents the integral from growing continuously and becoming saturated when the target is not met over a long period. The default value is overridden only when the configured value is > 0.

IntegralThreshold

Float64

No

The integral separation threshold. Default value: 0, which disables integral separation. When |error| > IntegralThreshold, the integral term pauses. While it is paused:

  • The integral does not continue to accumulate in the current round;

  • The PID output does not include the existing Ki × integralSum;

  • The existing integral is not automatically reset to zero;

  • After the error returns within the threshold, the existing integral takes part in the output again.

ErrThreshold

Float64

No

The variable-rate integration threshold, which is used to calculate the current integral increment coefficient. A value of 0 disables variable-rate integration. A value greater than 0 applies an additional coefficient when the total integral is calculated.

ErrDiscount

Float64

No

The decay coefficient for historical integration. 0 < ErrDiscount <= 1.

  • 1.0: no decay. The historical integral is fully retained.

  • 0.9: 90% of the historical integral is retained in each round.

  • 0.7: 70% is retained in each round. The decay is relatively fast.

  • 0.3: only 30% is retained in each round. The integral is easily suppressed.

  • >1: amplifies the historical integral, which can cause rapid saturation. Not recommended.

  • <=0: does not apply decay to the integral when the target is missed.

MinExpTraffic

Float64

No

The low-traffic protection threshold used when control is applied per experiment. It takes effect only when all of the following conditions are met:

  1. The task is ratio-based;

  2. AllocateExperimentWise=true;

  3. The target traffic of the current experiment is lower than the threshold, or no experiment traffic record exists.

When these conditions are met, the controller does not use the traffic data of that experiment and falls back to the global traffic data.

FreezeMinutes

Int

No

The duration, in minutes, for which the PID output is frozen in the early morning each day.

The current code calculates this based on the Asia/Shanghai time zone.

During the freeze period, the PID output is not recalculated and the previous result is returned. Right after the day rolls over, the sample size of the daily accumulated traffic is very small, so the share and the accumulated target are unstable. Using the early data of the new day directly can cause a sudden change in the output, so the previous output can be reused for a short period.

DPPSort

For more information about the DPP (Determinantal Point Process) diversification algorithm, see An intuitive understanding of the recommendation diversity algorithm based on determinantal point processes.

Prerequisites: The DPP algorithm requires embedding vectors for items. The embedding vectors must represent the content of the items themselves, and the similarity between embeddings must reflect content-level similarity rather than similarity on other levels, such as behavior. For example:

  • Recommended: embeddings derived from item images, from text descriptions, or from a combination of static item content such as categories and attributes

  • Not recommended: embeddings produced by training a model on user behavior data

The dimension that you want to diversify must be reflected in the embedding. For example, to make the recommendation list diverse in item price, the price feature must be included when the model is trained to generate the embedding vectors. Otherwise, the expected result cannot be achieved.

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

Field

Type

Required

Description

Name

string

Yes

The custom re-ranking name

DaoConf

DaoConfig

Yes

The Hologres configuration

TableName

string

No

The name of the item embedding vector table in Hologres; required when EmbeddingHookNames is not configured

TableSuffixParam

string

No

When this parameter is not empty, PAI-Rec retrieves the value of this configuration item for the current scenario from the Engine Service Management-Parameter Management module and uses the retrieved value as the suffix of TableName; used to switch the vector table name daily so that the embeddings stay up to date; in this case, the Hologres table generally needs to be a partitioned table

TablePKey

string

No

The primary key of the embedding vector table

EmbeddingColumn

string

No

The name of the vector field in the embedding vector table

EmbeddingSeparator

string

No

The delimiter of the embedding vector. Default value: a comma (,)

Alpha

float

Yes

The parameter that the DPP algorithm uses to balance relevance and diversity; a larger value favors relevance

CacheTimeInMinutes

int

No

The duration for which embedding vectors are cached in memory. Default value: 360

EmbeddingHookNames

[]string

No

The names of the functions that generate item embeddings. Register these functions in advance

NormalizeEmb

string

No

Specifies whether to L2-normalize the embedding vectors; if L2 normalization is already applied when the embeddings are generated, this is not needed. Otherwise, set it to true

WindowSize

int

No

The size of the tumbling window for the diversity algorithm; diversity is guaranteed only for the item list within the window. Default value: 10

EmbMissedThreshold

float

No

An error is reported when the proportion of items with missing embeddings is higher than this value. Default value: 0.5

FilterRetrieveIds

[]string

No

The list of items that do not need to call the DPP module, such as cold-start items

EnsurePositiveSim

string

No

Specifies whether the item similarity calculated from embeddings must be a positive value. Default value: true

CandidateCount

int

No

The size of the diversification candidate set. By default, this is the number of all items that enter the re-ranking stage. You can set a smaller value to limit the candidate set to the top N items

AbortRunCount

int

No

If the number of items that enter the re-ranking stage is less than this value, diversification is skipped for the current request. Default value: 0

MinScorePercent

float

No

An item is eligible to be output by the diversification module only when its ranking score, normalized by the maximum item score, is greater than this value. Default value: 0

SSDSort

For more information about the SSD diversification algorithm, see Improving the diversity of recommendation results: an analysis of MMR/DPP/SSD principles.

Prerequisites: The SSD algorithm requires embedding vectors for items. The embedding vectors must represent the content of the items themselves, and the similarity between embeddings must reflect content-level similarity rather than similarity on other levels, such as behavior. For example:

Recommended: embeddings derived from item images, from text descriptions, or from a combination of static item content such as categories and attributes

Not recommended: embeddings produced by training a model on user behavior data

The dimension that you want to diversify must be reflected in the embedding. For example, to make the recommendation list diverse in item price, the price feature must be included when the model is trained to generate the embedding vectors. Otherwise, the expected result cannot be achieved.

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

Field

Type

Required

Description

Name

string

Yes

The custom re-ranking name

DaoConf

DaoConfig

Yes

The Hologres configuration

TableName

string

No

The name of the item embedding vector table in Hologres; required when EmbeddingHookNames is not configured

TableSuffixParam

string

No

When this parameter is not empty, PAI-Rec retrieves the value of this configuration item for the current scenario from the Engine Service Management-Parameter Management module and uses the retrieved value as the suffix of TableName; used to switch the vector table name daily so that the embeddings stay up to date; in this case, the Hologres table generally needs to be a partitioned table

TablePKey

string

No

The primary key of the embedding vector table

EmbeddingColumn

string

No

The name of the vector field in the embedding vector table

EmbeddingSeparator

string

No

The delimiter of the embedding vector. Default value: a comma (,)

Gamma

float

Yes

The parameter that the SSD algorithm uses to balance relevance and diversity; a larger value favors diversity

UseSSDStar

bool

No

Specifies whether to enable the optimization algorithm described in the SSD paper. Default value: false. Enable this algorithm for better results

CacheTimeInMinutes

int

No

The duration for which embedding vectors are cached in memory. Default value: 360

EmbeddingHookNames

[]string

No

The names of the functions that generate item embeddings. Register these functions in advance

NormalizeEmb

string

No

Specifies whether to L2-normalize the embedding vectors; if L2 normalization is already applied when the embeddings are generated, this is not needed. Otherwise, set it to true

WindowSize

int

No

The size of the sliding window for the diversity algorithm; diversity is guaranteed only for the item list within the window. Default value: 5

EmbMissedThreshold

float

No

An error is reported when the proportion of items with missing embeddings is higher than this value. Default value: 0.5

FilterRetrieveIds

[]string

No

The list of items that do not need to call the SSD module, such as cold-start items

EnsurePositiveSim

string

No

Specifies whether the item similarity calculated from embeddings must be a positive value. Default value: true

CandidateCount

int

No

The size of the diversification candidate set. By default, this is the number of all items that enter the re-ranking stage. You can set a smaller value to limit the candidate set to the top N items

AbortRunCount

int

No

If the number of items that enter the re-ranking stage is less than this value, diversification is skipped for the current request. Default value: 0

MinScorePercent

float

No

An item is eligible to be output by the diversification module only when its ranking score, normalized by the maximum item score, is greater than this value. Default value: 0

Multi-channel recall re-ranking (MultiRecallMixSort)

In most cases, a recommendation system uses multiple recall channels. Based on business operation requirements, you may need to mix the output by recall channel type. For example:

  • The cold-start recall channel requires a specific number of exposures

  • A specific recall channel requires specific positions

  • You can also use an item feature as a condition to control the output position or quantity.

To output a recall channel by proportion, use the following configuration: the number of ColdStartRecall items accounts for 10% of the total.

{
    "SortConfs": [
        {
            "Name": "MixSort",
            "SortType": "MultiRecallMixSort",
            "RemainItem": false,
            "MixSortRules": [
                {
                    "MixStrategy": "random_position",
                    "NumberRate": 0.1,
                    "RecallNames": [
                        "ColdStartRecall"
                    ]
                }
            ]
        }
    ]
}

To output a recall channel at fixed positions, use the following configuration: the items with the highest scores in GlobalHotRecall are selected first to fill the fixed positions, and the remaining items are sorted by score and fill the remaining positions.

{
    "SortConfs": [
        {
            "Name": "MixSort",
            "SortType": "MultiRecallMixSort",
            "RemainItem": false,
            "MixSortRules": [
                {
                    "MixStrategy": "fix_position",
                    "Positions": [1,3,5],
                    "RecallNames": [
                        "GlobalHotRecall"
                    ]
                }
            ]
        }
    ]
}

Use condition filters to select items, and then control the quantity by proportion.

{
    "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"
                        }
                    ]
                }
            ]
        }
    ]
}

Use condition filters to select items, and then fill the fixed positions.

{
    "SortConfs": [
        {
            "Name": "MixSortByItemFeature",
            "SortType": "MultiRecallMixSort",
            "RemainItem": false,
            "MixSortRules": [
                {
                    "MixStrategy": "fix_position",
                    "Positions": [3,5,7],
                    "Conditions": [
                        {
                            "Name": "gender",
                            "Domain": "item",
                            "Type": "string",
                            "Value": "man",
                            "Operator": "equal"
                        }
                    ]
                }
            ]
        }
    ]
}
Note

The preceding configuration inserts the highest-scoring items with gender=man into positions 3, 5, and 7 first. The remaining items are then sorted by score and fill the other positions. If there are many items with gender=man, these items also appear in positions other than 3, 5, and 7.

Field

Type

Required

Description

Name

string

Yes

Custom re-ranking name

SortType

string

Yes

Re-ranking type. Fixed value: MultiRecallMixSort

RemainItem

bool

No

Specifies whether to keep all items. For example, assume that 500 items need to be processed but each request returns only 30 items. If this parameter is set to false, only the items in the mixed ranking result are kept. If this parameter is set to true, the remaining items are also kept, but are placed after the 30 items in the mixed ranking result. A subsequent sort can then further process these items.

MixSortRules

json array

Yes

Diversification rules. You can configure multiple rules.

  • MixStrategy

string

Yes

The mixed ranking strategy. Valid values: random_position/fix_position

  • random_position: positions are assigned randomly.

  • fix_position: positions are fixed. You must specify Positions.

  • Positions

[]int

No

If the strategy is fix_position, you must specify Positions. The position values in Positions start from 1.

  • PositionField

string

No

If the strategy is fix_position, the position is obtained from an item property field. Positions and PositionField conflict with each other, so you can specify only one of them.

  • Number

int

No

The absolute number of items.

  • NumberRate

float

No

The proportion of items in the mixed ranking result. Set this parameter only when MixStrategy=random_position. Valid values: 0 to 1. The exact number of items is calculated from the request as Size * NumberRate.

  • RecallNames

[]string

No

The names of the recall channels. You can specify multiple names, in which case the channels share this configuration. The specific recall channel is not fixed, and the order is determined by the position at which items enter this Sort.

  • Conditions

[]FilterParamConfig

No

Only the items that match the conditions are included in the mixed ranking. For more information about how to configure the conditions, see Operator examples .

Condition routing re-ranking (ConditionSort)

ConditionSort routes requests to different re-ranking strategies based on user attribute conditions. When different user groups require different re-ranking logic, you can configure condition rules to route requests to the corresponding re-ranking strategy. If no condition matches, the default re-ranking strategy is used.

Condition routing rules are evaluated in the configured order. The engine runs the first re-ranking strategy whose condition is met and skips the remaining conditions.

Configuration example:

{
  "SortConfs": [
    {
      "Name": "ConditionSort",
      "SortType": "ConditionSort",
      "ConditionSortConfs": {
        "SortConfs": [
          {
            "Conditions": [
              {
                "Name": "user_level",
                "Domain": "user",
                "Type": "string",
                "Value": "vip",
                "Operator": "equal"
              }
            ],
            "SortName": "VipDiversitySort"
          },
          {
            "Conditions": [
              {
                "Name": "is_new_user",
                "Domain": "user",
                "Type": "int",
                "Value": 1,
                "Operator": "equal"
              }
            ],
            "SortName": "NewUserBoostSort"
          }
        ],
        "DefaultSortName": "DefaultDiversitySort"
      }
    }
  ]
}

The preceding configuration works as follows: when the user attribute user_level equals vip, the VipDiversitySort re-ranking strategy is used; when the user attribute is_new_user equals 1, the NewUserBoostSort re-ranking strategy is used; if none of the preceding conditions match, DefaultDiversitySort is used as the default re-ranking strategy.

Field

Type

Required

Description

Name

string

Yes

Custom re-ranking name

SortType

string

Yes

Re-ranking type. Fixed value: ConditionSort

ConditionSortConfs

object

Yes

Condition routing configuration

ConditionSortConfs.SortConfs

json array

Yes

The list of condition-to-strategy mappings. Entries are evaluated in the configured order, and evaluation stops after the first re-ranking strategy whose condition is met.

ConditionSortConfs.SortConfs[].Conditions

[]FilterParamConfig

No

The routing condition rules. If this parameter is left empty, the entry never matches and is skipped, and the subsequent entries are evaluated. The request may ultimately fall back to DefaultSortName.

ConditionSortConfs.SortConfs[].SortName

string

Yes

The name of the re-ranking strategy to execute when the condition matches. This value corresponds to the Name that is configured in another SortConfs entry.

ConditionSortConfs.DefaultSortName

string

No

The name of the default re-ranking strategy, which is used when no condition matches. If this parameter is not configured and no condition matches, no re-ranking is performed.

FilterParamConfig is configured as follows:

Field

Type

Required

Description

Name

string

Yes

The name of the item or user feature

Domain

string

Yes

Valid values: item/user. Indicates whether the Name field is an item feature or a user feature. Name must exist in the properties of the item or user. In ConditionSort, this parameter is usually set to user so that requests are routed by user attribute.

Operator

string

Yes

Valid values: equal/not_equal/in/not_in/greater/greaterThan/less/lessThan/contains/not_contains/is_null/is_not_null/bool/expression

Type

string

Yes

The type of the feature

Value

object

Yes

The value of the feature

Important
  1. SortName references: The re-ranking strategies referenced by ConditionSortConfs.SortConfs[].SortName and DefaultSortName must be the names of other re-ranking strategies that are already configured in SortConfs, such as DiversityRuleSort and BoostScoreSort.

  2. Matching order: Conditions are evaluated in the configured order. The first strategy that matches is executed, and the remaining conditions are not evaluated.

  3. Default strategy: We recommend that you configure DefaultSortName to ensure that all requests are routed to an appropriate re-ranking strategy.

How to use

The re-ranking configuration is similar to the recall configuration. After the configuration is complete, provide a SortNames parameter that is used by scenario. SortNames is a Map[string]object structure in which each key is a scenario and each scenario corresponds to a group of re-ranking strategies.

{
    "SortNames": {
        "${scene_name}": [
            "ItemRankScore"
        ]
    }
}
  • ${scene_name} is the scenario name. If multiple scenarios use the same configuration, set this parameter to "default".

  • ItemRankScore: the custom name of the re-ranking strategy that is defined in SortConfs.