Detailed configurations and descriptions of each filter

Updated at:

The PAI-Rec engine provides multiple built-in filter templates, including the templates for the User2ItemExposureFilter, ItemStateFilter, and AdjustCountFilter filters.

Filter configurations

Filters are configured through FilterConfs in the configuration overview. FilterConfs is an array of objects and can define multiple filter policies.

Overview of common filter configurations

The following section describes the common configurations that are referenced by different filters. The configurations are not repeated in the detailed descriptions of each filter in this topic.

Sample configuration:

{
    "FilterConfs": [
        {
            "Name": "",
            "FilterType": "",
            "Dimension": "",
            "DaoConf": {},
            "AdjustCountConfs": [],
            "ItemStateDaoConf": {},
            "FilterParams": [],
            "DiversityDaoConf": {},
            "FilterVal": {}
        }
    ]
}

Parameter

Type

Required

Description

Name

string

Yes

The custom name of the filter. You can use the name when you configure the FilterNames parameter.

FilterType

string

Yes

The type of the built-in filter for the engine. Valid values:

  • User2ItemExposureFilter

  • User2ItemCustomFilter

  • AdjustCountFilter

  • PriorityAdjustCountFilter

  • ItemStateFilter

  • ItemCustomFilter

  • CompletelyFairFilter

  • GroupWeightCountFilter

  • DimensionFieldUniqueFilter

Dimension

string

No

The dimension of the item.

DaoConf

DaoConfig

No

The information about the source table.

AdjustCountConfs

No

The configurations of the PriorityAdjustCountFilter filter.

ItemStateDaoConf

No

The configurations of the ItemStateFilter filter.

FilterParams

No

The configurations of contextual conditions.

User2ItemExposureFilter

In many business scenarios, exposure filtering is used to prevent repeated recommendations, typically by combining pseudo-exposure and real exposure.

Pseudo exposure: because real-time logs are delayed, the engine cannot immediately know which items were exposed, so the list of items returned by the recommendation engine is used as the pseudo exposure list.

A real-time computing engine such as Flink writes real-time logs to a database, where they are then consumed by the PAI-Rec engine.

The following common parameters apply to exposure filtering for various data sources.

Parameter

Type

Required

Description

Name

string

Yes

The custom name of the filter.

FilterType

string

Yes

The type of the filter. Set the value to User2ItemExposureFilter.

MaxItems

int

Yes

The number of recent entry batches to retrieve, equivalent to limit ${MaxItems}. MaxItems does not refer to the number of individual items but to the number of batches: one recommendation request counts as one batch, regardless of how many items the request contains.

TimeInterval

int

Yes

The time period for retrieving items based on timestamps. Unit: seconds.

WriteLog

bool

Yes

Specifies whether to write exposure logs.

ClearLogIfNotEnoughScene

string

No

Specifies the scenario in which data of the exposure table is to be deleted.

OnlyLogUserExposeFlag

bool

No

The data is not actually filtered. If an item has already been exposed, only the _is_exposure_ attribute is added to the item. In some scenarios, the item pool is too small and can be completely filtered out by exposure filtering. During the reranking stage, you can perform boosting and demotion based on the _is_exposure_ attribute to avoid returning an empty result.

GenerateItemDataFuncName

string

No

The function that builds the item data written to the exposure table. If it is empty, the built-in PAI-Rec function is used, which returns only item_id.

GenerateItemDataExpr

string

No

Builds the item data written to the exposure table by using an expression. For the expression syntax, see expr-lang/expr. Available variables: uid, item_id, item (item attributes), sprintf, and context. If it is empty, the function registered by GenerateItemDataFuncName is used, which returns only item_id by default. Supported data sources: Hologres, TableStore, FeatureStore, and RecallEngine

GenerateUserDataExpr

string

No

Builds the user identifier data in the exposure table by using an expression. For the expression syntax, see expr-lang/expr. Available variables: uid, context, and sprintf. If it is empty, uid is used by default. Supported data sources: Hologres, FeatureStore, and RecallEngine

WriteLogExcludeScenes

[]string

No

Specifies the scenarios in which exposure logs are not written.

Hologres

{
    "FilterConfs": [
        {
            "Name": "holo_exposure_filter",
            "FilterType": "User2ItemExposureFilter",
            "MaxItems": 100,
            "TimeInterval": 172800,
            "WriteLog": true,
            "DaoConf": {
                "AdapterType": "hologres",
                "HologresName": "holo_info",
                "HologresTableName": "exposure_history"
            }
        }
    ]
}

Parameters of DaoConf

Parameter

Type

Required

Description

AdapterType

string

Yes

The type of the data source. Set the value to hologres.

HologresName

string

Yes

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

HologresTableName

string

Yes

The name of the exposure table.

The definition of the exposure table. You can set time_to_live_in_seconds based on your business requirements.

BEGIN;
CREATE TABLE "exposure_history" (
 "uid" text NOT NULL,
 "item" text NOT NULL,
 "create_time" int4 NOT NULL
);
CALL SET_TABLE_PROPERTY('"exposure_history"', 'orientation', 'column');
CALL set_table_property('"exposure_history"', 'distribution_key', 'uid');
CALL SET_TABLE_PROPERTY('"exposure_history"', 'clustering_key', '"uid","create_time"');
CALL SET_TABLE_PROPERTY('"exposure_history"', 'segment_key', '"create_time"');
CALL SET_TABLE_PROPERTY('"exposure_history"', 'bitmap_columns', '"uid","item"');
CALL SET_TABLE_PROPERTY('"exposure_history"', 'dictionary_encoding_columns', '"uid","item"');
CALL SET_TABLE_PROPERTY('"exposure_history"', 'time_to_live_in_seconds', '172800');
comment on table "exposure_history" is 'Exposure history table';
COMMIT;

PAI-FeatureStore

The built-in online data source of PAI-FeatureStore, FeatureDB, uses a Bloom filter algorithm to support exposure filtering in PAI-Rec.

To use PAI-FeatureStore for exposure tables, create a real-time FeatureView with the following settings:

For View Name, enter user_expose. For Write Mode, select Custom Table Structure. Set Number of Shards to 5 and Number of Replicas to 1.

Configure the following key parameters:

  1. Set Type to Real-time.

  2. Set Feature Entity to user.

  3. The feature fields must include user_id, item_id, and timestamp. user_id is the primary key, and timestamp must have Event Time selected. The primary key and the event time are required. For data types, user_id and item_id are both string, and timestamp is int64.

  4. The feature lifecycle. The default value is 2 days. Adjust it based on your business requirements. It indicates how long the exposed entries of a user are retained.

  5. The advanced configuration is required. Enter {"table_type":"bloom", "expose_count":5000}. table_type indicates that the table created supports a bloom filter. expose_count is the maximum number of exposure entries retained for a single user.

    The following is a sample configuration for exposure filtering in the PAI-Rec engine:

{
    "FilterConfs": [
        {
            "Name": "fs_exposure_filter",
            "FilterType": "User2ItemExposureFilter",
            "TimeInterval": 300,
            "WriteLog": true,
            "DaoConf": {
                "AdapterType": "featurestore",
                "FeatureStoreName": "fs_pairec",
                "FeatureStoreViewName": "user_expose"
            }
        }
    ]
}

TimeInterval is measured in seconds. It is the maximum retention period for the pseudo exposure entries written by the engine, and it takes effect when WriteLog is set to true. The preceding configuration is for pseudo exposure. For real exposure, the PAI-Rec engine does not write the data: set WriteLog to false, and TimeInterval can be left unset.

The following is a sample configuration for real exposure:

"FilterConfs": [
        {
            "Name": "fs_exposure_filter2",
            "FilterType": "User2ItemExposureFilter",
            "WriteLog": false,
            "DaoConf": {
                "AdapterType": "featurestore",
                "FeatureStoreName": "fs_pairec",
                "FeatureStoreViewName": "user_expose"
            }
        }
    ]

Because the lifecycles for pseudo-exposure and real exposure are typically different, you should use a separate FeatureView table for each.

For information about how to write real exposure data, see Write features.

DaoConf configuration

Parameter

Type

Required

Description

AdapterType

string

Yes

The type of the data source. Set the value to featurestore.

FeatureStoreName

string

Yes

The custom name of the FeatureStore that is configured in the data source configuration (FeatureStoreConfs), such as fs_pairec in the data source configuration

FeatureStoreViewName

string

Yes

The name of the FeatureView for the exposure table.

Redis

{
    "FilterConfs": [
        {
            "Name": "redis_exposure_filter",
            "FilterType": "User2ItemExposureFilter",
            "MaxItems": 100,
            "TimeInterval": 172800,
            "WriteLog": true,
            "DaoConf": {
                "AdapterType": "redis",
                "RedisName": "redis_info",
                "RedisPrefix": "exposure_"
            }
        }
    ]
}

Parameters of DaoConf

Parameter

Type

Required

Description

AdapterType

string

Yes

The type of the data source. Set the value to redis.

RedisName

string

Yes

The custom name of the Redis instance that is configured in the data source configuration (RedisConfs), such as redis_info in the data source configuration

RedisPrefix

string

No

The key prefix of the exposure data. key = RedisPrefix + uid

TableStore

{
    "FilterConfs": [
        {
            "Name": "ots_exposure_filter",
            "FilterType": "User2ItemExposureFilter",
            "MaxItems": 100,
            "TimeInterval": 172800,
            "WriteLog": true,
            "DaoConf": {
                "AdapterType": "tablestore",
                "TableStoreName": "tablestore_info",
                "TableStoreTableName": "exposure_history"
            }
        }
    ]
}

Parameters of DaoConf

Parameter

Type

Required

Description

AdapterType

string

Yes

The type of the data source. Valid values: hologres, mysql, and tablestore.

TableStoreName

string

Yes

The custom name of the Tablestore instance that is configured in the data source configuration (TableStoreConfs), such as tablestore_info in the data source configuration

TableStoreTableName

string

Yes

The name of the exposure table.

time_to_live_in_seconds: the lifecycle of the data. You must specify a custom value for the parameter.

maxVersion: 1. 

Parameter

Category

Type

Description

Example

user_id

Primary key

string

The unique ID of the user

10944750

auto_id

Primary key

integer

The auto-increment column.

item_ids

Property

string

The list of unique item IDs, separated by commas (','). If one exposure can contain multiple item_id values, you can insert a single row

17019277,17019278

Impression de-ranking

In some scenarios, the recall pool of a user is small, and configuring exposure filtering can easily filter out all items in the pool. In this case, instead of filtering items out, you can tag the exposed items and then use weight adjustment to move them to the end. The following example uses a Hologres data source. Other data sources work in a similar way. The filtering and re-ranking configurations are as follows:

{
    "FilterConfs": [
        {
            "Name": "holo_exposure_filter",
            "FilterType": "User2ItemExposureFilter",
            "MaxItems": 20,
            "TimeInterval": 172800,
            "WriteLog": true,
            "OnlyLogUserExposeFlag": true,
            "DaoConf": {
                "AdapterType": "hologres",
                "HologresName": "holo_info",
                "HologresTableName": "exposure_history"
            }
        }
    ],
    "SortConfs": [
        {
            "Name": "boost_score_sort",
            "SortType": "BoostScoreSort",
            "BoostScoreConditions": [
                {
                    "Conditions": [
                        {
                            "Name": "_is_exposure_",
                            "Domain": "item",
                            "Type": "int",
                            "Value": 1,
                            "Operator": "equal"
                        }
                    ],
                    "Expression": "score / 10"
                }
            ]
        }
    ]
}

User2Item custom filter (User2ItemCustomFilter)

Hologres

You must provide a custom user2item filter table for data filtering. The filter table is usually produced offline. For example, every early morning it aggregates the items that each user viewed in the past 15 days, that is, the items with exposure behavior, and stores them in the item_ids field separated by commas.

{
    "FilterConfs": [
        {
            "Name": "u2i_custom_filter",
            "FilterType": "User2ItemCustomFilter",
            "DaoConf": {
                "AdapterType": "hologres",
                "HologresName": "holo_info",
                "HologresTableName": "u2i_custom_filter"
            },
            "ItemStateCacheSize": 10000,
            "ItemStateCacheTime": 3600
        }
    ]
}

DaoConf configuration

Parameter

Type

Required

Description

AdapterType

string

Yes

The type of the data source. Set the value to hologres.

HologresName

string

Yes

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

HologresTableName

string

Yes

The name of the custom exposure table.

ItemStateCacheSize

int

No

The maximum number of entries in the cache. A value greater than 0 enables the cache.

ItemStateCacheTime

int

No

The time-to-live (TTL) for cache entries, in seconds. Default: 3600.

The table schema is as follows:

Parameter

Category

Type

Description

Example

user_id

primary key

string

The unique ID of the user

10944750

item_ids

attribute

string

The list of unique item IDs, separated by commas (',')

17019277,17019278

TableStore(OTS)

You must provide a custom user2item filter table for data filtering.

{
    "FilterConfs": [
        {
            "Name": "u2i_custom_filter",
            "FilterType": "User2ItemCustomFilter",
            "DaoConf": {
                "AdapterType": "tablestore",
                "TableStoreName": "tablestore_info",
                "TableStoreTableName": "u2i_table"
            }
        }
    ]
}

Parameters of DaoConf

Parameter

Type

Required

Description

AdapterType

string

Yes

The type of the data source. Set the value to tablestore.

TableStoreName

string

Yes

The custom name of the Tablestore instance that is configured in the data source configuration (TableStoreConfs), such as tablestore_info in the data source configuration

TableStoreTableName

string

Yes

The name of the custom exposure table.

The exposure table is defined by using the following parameters.

Parameter

Category

Type

Description

Example

user_id

Primary key

string

The unique ID of the user

10944750

item_ids

Property

string

The list of unique item IDs, separated by commas (',')

17019277,17019278

PAI-FeatureStore

Warning

Only FeatureViews whose online data source is FeatureDB are supported.

Similar to the exposure filtering described above, you provide a real-time FeatureView and write data through the Java SDK or a Flink connector. For information about how to write data, see Write features. The PAI-Rec engine filters items by reading this data. The FeatureView is configured as follows:

Set the view name to user2item_custom_filter, select Custom Table Structure as the write method, and select Less than 10 million for the estimated data scale.

Key parameters:

  1. Set Type to Real-time.

  2. Set Feature Entity to user.

  3. The feature fields must include user_id, item_id, and timestamp. user_id is the primary key, and timestamp must have Event Time selected. The primary key and the event time are required. For data types, user_id and item_id are both string, and timestamp is int64. Here timestamp represents a timestamp in milliseconds.

  4. The feature lifecycle. The default value is 2 days. Adjust it based on your business requirements. It can be understood as the TTL of a row of data: the lifecycle is calculated from the value passed in the timestamp field.

  5. The advanced configuration is required. Enter {"table_type":"bloom"}. table_type indicates that the table created supports a bloom filter.

    See the following sample configuration for the PAI-Rec engine:

  {
    "FilterConfs": [
        {
            "Name": "u2i_custom_filter",
            "FilterType": "User2ItemCustomFilter",
            "DaoConf": {
                "AdapterType": "featurestore",
                "FeatureStoreName": "fs_pairec",
                "FeatureStoreViewName": "u2icustom_filter"
            }
        }
    ]
}

DaoConf configuration

Parameter

Type

Required

Description

AdapterType

string

Yes

The type of the data source. Set the value to featurestore.

FeatureStoreName

string

Yes

The custom name of the FeatureStore that is configured in the data source configuration (FeatureStoreConfs).

FeatureStoreViewName

string

Yes

The name of the FeatureView of the custom filter table.

AdjustCountFilter

AdjustCountFilter is used to randomly shuffle the items returned by recall links and then retain a specified number of items.

Sample configuration:

{
    "FilterConfs": [
        {
            "Name": "adjust_count_filter",
            "FilterType": "AdjustCountFilter",
            "ShuffleItem": true,
            "RetainNum": 500
        }
    ]
}

Parameter

Type

Required

Description

ShuffleItem

string

Yes

Specifies whether to shuffle the items returned by the recall link.

RetainNum

string

Yes

The number of items that you want to retain.

PriorityAdjustCountFilter

Priority filtering controls the number of items from each recall channel. Each recall channel is sorted by its recall score.

Sample configuration:

{
    "FilterConfs": [
        {
            "Name": "priority_adjust_count_filter",
            "FilterType": "PriorityAdjustCountFilter",
            "AdjustCountConfs": [
                {
                    "RecallName": "recall_1",
                    "Count": 125,
                    "Type": "accumulator"
                },
                {
                    "RecallName": "recall_2",
                    "Count": 250,
                    "Type": "accumulator"
                },
                {
                    "RecallName": "recall_3",
                    "Count": 400,
                    "Type": "accumulator"
                }
            ]
        }
    ]
}

Parameter

Type

Required

Description

Name

string

Yes

The custom name of the filter.

FilterType

string

Yes

The type of the filter. Set the value to PriorityAdjustCountFilter.

RecallName

string

Yes

The name of the recall link.

AdjustCountConfs

json array

Yes

The configurations of the PriorityAdjustCountFilter filter.

  • Count

int

Yes

The maximum number of items that are selected from the returned results of the recall link.

  • Type

string

No

Type: the limit type. Valid values: accumulator and fix.

accumulator:

  • In the preceding example, recall_1 is limited to a maximum of 125 items. When recall_1 has fewer than 125 items, recall_2 also tries to make up the total to 250, and so on.

fix:

  • Each recall channel retrieves items based on its own count. When one channel returns fewer items, the other channels do not make up the difference.

ItemStateFilter

Recalled data often needs state filtering. The state of an item can change in real time, and a dedicated table usually stores item states. This filtering process obtains the item state information in real time and then filters items.

Hologres

{
    "FilterConfs": [
        {
            "Name": "ItemStateFilter",
            "FilterType": "ItemStateFilter",
            "ItemStateDaoConf": {
                "AdapterType": "hologres",
                "HologresName": "",
                "HologresTableName": "",
                "ItemFieldName": "",
                "WhereClause": "",
                "SelectFields": ""
            },
            "ItemStateCacheSize": 50000,
            "ItemStateCacheTime": 3600,
            "FilterParams": [

            ]
        }
    ]
}

If the item state does not change frequently, you can configure cache options.

Parameter

Type

Required

Description

ItemStateCacheSize

int

No

The number of items to cache.

ItemStateCacheTime

int

No

The cache time-to-live (TTL). Unit: seconds.

Parameters of ItemStateDaoConfig

Parameter

Type

Required

Description

AdapterType

string

Yes

The type of the data source. Valid values: hologres, mysql, and tablestore.

HologresName

string

Yes

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

HologresTableName

string

Yes

The name of the item state table in Hologres

ItemFieldName

string

Yes

The primary key of the table that stores item states.

WhereClause

string

No

The conditional statement that is used for filtering.

SelectFields

string

Yes

The fields that you want to query.

Parameters of FilterParams

{
    "FilterParams": [
        {
            "Name": "publicStatus",
            "Type": "int",
            "Operator": "equal",
            "Value": 0
        },
        {
            "Name": "state",
            "Type": "int",
            "Operator": "equal",
            "Value": 1
        },
        {
            "Name": "checkStatus",
            "Type": "int",
            "Operator": "not_equal",
            "Value": 2
        },
        {
            "Name": "norec",
            "Type": "int",
            "Operator": "not_equal",
            "Value": 1
        }
    ]
}

Parameter

Type

Required

Description

Name

string

Yes

The name of the feature.

Domain

string

No

The owner of the feature. Valid values: user and item. Default value: item.

Operator

string

Yes

The operator. Valid values: equal, not_equal, in, greater, greaterThan, less, and lessThan.

Type

string

Yes

The type of the feature.

Value

object

Yes

The condition value.

Important

Note:Both WhereClause and FilterParams can filter data. WhereClause filters during the query and is equivalent to the WHERE condition in SQL, whereas FilterParams filters locally. When FilterParams is used, items that meet the condition are delivered and items that do not are filtered out.

For information about how to use each Operator, see Appendix.

PAI-FeatureStore

{
    "FilterConfs": [
        {
            "Name": "ItemStateFilter",
            "FilterType": "ItemStateFilter",
            "ItemStateDaoConf": {
                "AdapterType": "featurestore",
                "FeatureStoreName": "",
                "FeatureStoreViewName": "",
                "ItemFieldName": "",
                "SelectFields": ""
            },
            "ItemStateCacheSize": 50000,
            "ItemStateCacheTime": 3600,
            "FilterParams": [

            ]
        }
    ]
}

If the item state does not change frequently, you can configure cache options.

Parameter

Type

Required

Description

ItemStateCacheSize

int

No

The number of items to cache.

ItemStateCacheTime

int

No

The cache time-to-live (TTL). Unit: seconds.

ItemStateDaoConfig is defined as follows:

Parameter

Type

Required

Description

AdapterType

string

Yes

The type of the data source. Set the value to featurestore

FeatureStoreName

string

Yes

The custom name of the FeatureStore that is configured in the data source configuration (FeatureStoreConfs)

FeatureStoreViewName

string

Yes

The name of the feature view that stores the item state.

ItemFieldName

string

Yes

The primary key of the item state table.

SelectFields

string

Yes

The fields to retrieve.

FilterParams is defined as follows:

{
    "FilterParams": [
        {
            "Name": "publicStatus",
            "Type": "int",
            "Operator": "equal",
            "Value": 0
        },
        {
            "Name": "state",
            "Type": "int",
            "Operator": "equal",
            "Value": 1
        },
        {
            "Name": "checkStatus",
            "Type": "int",
            "Operator": "not_equal",
            "Value": 2
        },
        {
            "Name": "norec",
            "Type": "int",
            "Operator": "not_equal",
            "Value": 1
        }
    ]
}

Parameter

Type

Required

Description

Name

string

Yes

The name of the feature to filter.

Domain

string

No

The owner of the feature. Valid values: user and item

Operator

string

Yes

The operator. Supported values: equal, not_equal, in, greater, greaterThan, less, and lessThan

Type

string

Yes

The feature type.

Value

object

Yes

The condition value.

For information about how to use each Operator, see Appendix.

SnakeFilter

The recall stage retrieves a candidate set from multiple recall channels. SnakeFilter combines data from these channels in round-robin order based on specified weight ratios.

For example, recall has three channels A, B, and C, and the configured weight ratio is 1:2:3. The assembly logic is as follows:

  • Take one element from candidate set A

  • Take two elements from candidate set B

  • Take three elements from candidate set C

  • Repeat this process until you have the required number of elements.

There are two policies for handling duplicate elements:

  • REFILL_ON_DUPLICATE: if an element taken from the current candidate set duplicates one taken earlier, the engine keeps searching in the current candidate set until it finds a unique element. For example, if all three elements taken from candidate set C duplicate those in A and B, the search continues in candidate set C.

  • SKIP_ON_DUPLICATE: duplicate elements are skipped without replacement, and the next iteration starts. For example, if all three elements taken from candidate set C duplicate those in A and B, candidate set C returns no elements in this round, and a new iteration starts from A.

{
    "FilterConfs": [
        {
            "Name": "SnakeFilter",
            "FilterType": "SnakeFilter",
            "RetainNum": 20,
            "SnakeType": "REFILL_ON_DUPLICATE",
            "AdjustCountConfs": [
                 {
                     "RecallName": "GroupHotRecall",
                     "Weight": 1
                 },
                 {
                     "RecallName": "U2IRecall",
                     "Weight": 2
                 },
                 {
                     "RecallName": "GlobalHotRecall",
                     "Weight": 3
                 }
             ]
        }
    ]
}

Parameter

Type

Required

Description

Name

string

Yes

A custom filter name.

FilterType

string

Yes

The filter type. Set the value to SnakeFilter.

RetainNum

string

Yes

The number of elements to retain in the final candidate set.

SnakeType

string

No

  • REFILL_ON_DUPLICATE: keeps searching in the current recall channel until the quota is met. Default value

  • SKIP_ON_DUPLICATE: skips duplicate elements without filling the quota and continues with the next iteration.

AdjustCountConfs

json array

Yes

Defines the configuration for each recall channel.

  • RecallName

string

Yes

The name of the recall channel.

  • Weight

int

Yes

The relative weight used to determine the number of entries to retrieve from this recall channel in each round.

Note

Applying this filter adds the snake_filter attribute to an item. This attribute specifies the item's recall path, its 0-indexed position, and its score. For example, snake_filter:GroupHotRecall:0:0.144200 means the item is from the GroupHotRecall recall path at position 0, making it the first item.

CompletelyFairFilter

Sorts items by the score of each recalled entry and then fairly retrieves data from each recall channel

{
    "FilterConfs": [
        {
            "Name": "CompletelyFairFilter",
            "FilterType": "CompletelyFairFilter",
            "RetainNum": 500
        }
    ]
}

DimensionFieldUniqueFilter

Unlike UniqueFilter, DimensionFieldUniqueFilter deduplicates items by a dimension field (Dimension) of the item. By default, it keeps the item that appears first for the same dimension value. When the engine version is 2.2.4 or later and UniqueKeepConf is configured, the engine keeps the best item within each group of duplicates that share the same dimension value, based on the specified property, which is the item with the minimum or maximum value.

{
  "FilterConfs": [
    {
      "Name": "brand_unique_filter",
      "FilterType": "DimensionFieldUniqueFilter",
      "Dimension": "brand_id",
      "UniqueKeepConf": {
        "Property": "distance",
        "Strategy": "min"
      }
    }
  ]
}

Parameter

Type

Required

Description

Name

string

Yes

The name of the custom filter.

FilterType

string

Yes

The filter type. Set the value to DimensionFieldUniqueFilter.

Dimension

string

Yes

The attribute field used to deduplicate items. If this field is empty for an item, the item is retained.

UniqueKeepConf

object

No

The preferred-retention configuration. If it is not configured, only the item that appears first is kept for the same Dimension value, which is the default behavior.

UniqueKeepConf.Property

string

No

The name of the item property used for comparison within a group, such as distance). The value is read through FloatProperty and only keys in item.Properties are supported. It must be configured together with Strategy. Otherwise, an error is reported when the engine starts or the configuration is hot reloaded.

UniqueKeepConf.Strategy

string

No

The preferred-retention strategy. Valid values: min (keeps the item with the smallest Property value) and max (keeps the item with the largest value). It must be configured together with Property.

Description

  • Preferred retention happens in the filtering phase. The property that Property points to must already exist in item. Properties at that time, either returned directly by recall or loaded by an ItemStateFilter that runs earlier. Otherwise, the property has no value.

  • Comparison rules within a group: when both values are readable, the item is selected by the min or max strategy; when only one value is readable, the readable one is kept; when neither is readable because the property is missing or the value is NaN, the item that appears first is kept and one event=KeepPropertyUnreadable WARN log entry is printed, at most one per request. This helps you identify a wrong property name or a property that was not loaded.

ConditionFilter

This is a composite filter that decides which filter to use based on the request conditions, such as user features and the features passed in the context. You can configure one or more combinations of a condition and a specific filter that is already defined in FilterConfs.

{
"FilterConfs":[
  {
      "Name": "adjust_count_filter",
      "FilterType": "AdjustCountFilter",
      "ShuffleItem": true,
      "RetainNum": 500
  },
  {
    "Name": "CompletelyFairFilter",
    "FilterType": "CompletelyFairFilter",
    "RetainNum": 500
  },
  {
    "Name": "ConditionFilter",
    "FilterType": "ConditionFilter",
    "ConditionFilterConfs":{
      "FilterConfs":[
        {
          "Conditions":[
            {
		"Name":     "query",
		"Type":     "string",
		"Domain":   "user",
		"Operator": "equal",
		"Value":    "1"
            }
          ],
          "FilterName":"adjust_count_filter"
        }
      ],
      "DefaultFilterName": "CompletelyFairFilter"
    }
  }
]
}

The preceding example defines two independent filters: adjust_count_filter and CompletelyFairFilter. ConditionFilter is a filter that combines conditions. When the user property query == "1", the logic of adjust_count_filter is used. If no condition matches, the filter specified by DefaultFilterName is used, which is CompletelyFairFilter in this scenario.

The configuration parameters are as follows:

Parameter

Type

Required

Description

Name

string

Yes

The name of the custom filter.

FilterType

string

Yes

The filter type. Set the value to ConditionFilter

ConditionFilterConfs

json map

Yes

The configuration for the conditions.

  • FilterConfs

json array

No

You can configure multiple condition matching rules. As soon as one matches, the corresponding FilterName is used

  • DefaultFilterName

string

No

When none of the conditions in FilterConfs matches, the filter specified here is used.

The FilterConfs parameters are described as follows:

Parameter

Type

Required

Description

Conditions

[]FilterParamConfig

No

Matching conditions for the rule.

FilterName

string

No

The name of the filter to apply when the conditions are met. This filter must be defined in FilterConfs.

FilterParamConfig is configured as follows:

Parameter

Type

Required

Description

Name

string

Yes

The feature name for an item or user.

Domain

string

Yes

Valid values: item and user. It indicates whether the Name option is an item feature or a user feature. Name must be found in the properties of the item or user.

Operator

string

Yes

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

Type

string

Yes

The type of the feature.

Value

object

Yes

The value of the feature.

For information about the specific condition settings, see the following Appendix.

GroupWeightCountFilter (controls the number of items by group weight)

GroupWeightCountFilter is a filter that controls the number of candidates by group weight. It groups candidate items by a specified dimension field, such as the category, recall source, or tag, calculates the quota of each group in proportion to the accumulated score of the items in that group, and makes sure that the total number of output items equals RetainNum.

Unlike CompletelyFairFilter, which allocates an equal share to each group, and AdjustCountFilter, which truncates randomly, the key characteristic of GroupWeightCountFilter is that groups with higher scores automatically receive more slots, while each group is still guaranteed a minimum number of retained items.

Scenarios

Multi-channel recall fusion: different recall sources, such as hot, U2I, and vector recall, serve as the grouping dimension, and recall channels with higher scores receive more display slots.

Category diversity control: items are grouped by category to prevent the recommendation results from being dominated by a single category

Tag-based diversification: items are grouped by content tag to improve the diversity of the recommendation list

Secondary dimension throttling: combined with GroupWeightDimensionLimit to set an upper limit for secondary dimensions such as brand and author

Complete configuration example:

{
    "Name": "group_weight_count_filter",
    "FilterType": "GroupWeightCountFilter",
    "RetainNum": 500,
    "Dimension": "category",
    "ScoreWeight": 1.0,
    "GroupMinNum": 2,
    "GroupMaxNum": 100,
    "GroupWeightStrategy": "softmax",
    "GroupWeightDimensionLimit": {
        "brand": 50,
        "author": 30
    }
}

Parameter description:

Parameter

Type

Required

Default value

Description

Name

string

Yes

-

The unique name of the filter, which is referenced by FilterNames or ActionConfs

FilterType

string

Yes

-

Set the value to "GroupWeightCountFilter"

RetainNum

int

Yes

-

The total number of items retained after filtering

Dimension

string

Yes

-

The name of the grouping dimension field. Items without this property are placed in the "DEFAULT" group

ScoreWeight

float

No

1.0

The score weight coefficient, which controls how much the score difference between groups is amplified into a quota difference

GroupMinNum

int

No

0

The minimum number of items retained for each group

GroupMaxNum

int

No

0

The maximum number of items retained for each group. A value of 0 indicates no upper limit

GroupWeightStrategy

string

No

softmax

The weight calculation strategy. Valid values: "softmax" and "avg"

GroupWeightDimensionLimit

map[string]int

No

NULL

The secondary dimension pre-filter. The key is the dimension field name and the value is the maximum number of items for each value of that dimension

UniqueFilter

Uniqueness filtering, which ensures that item IDs are unique. If two recall channels contain the same item ID, the item ID from the channel that returns first is used.

You can use UniqueFilter when you configure the FilterNames parameter without the need to configure UniqueFilter.

Filter usage

Filter configuration is similar to recall configuration. After the configuration, you provide FilterNames for use by scenario. FilterNames is a Map[string]object structure in which the key is the scenario and each scenario maps to a set of filter policies

"FilterNames": {
  "${scene_name}": [
    "UniqueFilter"
  ]
}
  • ${scene_name} is the scenario name. If multiple scenarios use the same configuration, you can use "default".

  • UniqueFilter: A custom name for a filter defined in FilterConfigs.

Appendix

Operator examples

  1. equal (equal to the specified value)

{
    "Name": "publicStatus",
    "Type": "int",
    "Operator": "equal",
    "Value": 0
}
  1. not_equal (not equal to the specified value)

{
    "Name": "checkStatus",
    "Type": "int",
    "Operator": "not_equal",
    "Value": 2
}
  1. greater (greater than >)

{
    "Name": "checkStatus",
    "Type": "int",
    "Operator": "greater",
    "Value": 2
}
  1. greaterThan (greater than or equal to >=)

{
    "Name": "checkStatus",
    "Type": "int",
    "Operator": "greaterThan",
    "Value": 2
}
  1. less (less than <)

{
    "Name": "checkStatus",
    "Type": "int",
    "Operator": "less",
    "Value": 2
}
  1. lessThan (less than or equal to <=)

{
    "Name": "checkStatus",
    "Type": "int",
    "Operator": "lessThan",
    "Value": 2
}
  1. in (matches any value in an array)

{
    "Name": "state",
    "Type": "int",
    "Operator": "in",
    "Value": [2,4,6]
}

string type

{
    "Name": "state",
    "Type": "string",
    "Operator": "in",
    "Value": ["success","ok"]
}
  1. not_in (does not match any item in the array)

{
    "Name": "state",
    "Type": "int",
    "Operator": "not_in",
    "Value": [2,4,6]
}

You can also use the string type. For the configuration, see the in Operator.

  1. contains (matches any item in an array)

{
    "Name": "state",
    "Type": "[]int",
    "Operator": "contains",
    "Value": [2,4,6]
}

string type

{
    "Name": "state",
    "Type": "[]string",
    "Operator": "contains",
    "Value": ["success","ok"]
}
  1. not_contains (does not contain any entry in the array)

{
    "Name": "state",
    "Type": "[]int",
    "Operator": "not_contains",
    "Value": [2,4,6]
}

You can also use the string array type. For the configuration, see the contains Operator.

  1. bool (connects multiple condition matching Operators)

Combine conditions with or.

{
    "Operator": "bool",
    "Type": "or",
    "Configs":
    [
        {
            "Name": "publicStatus",
            "Type": "int",
            "Operator": "equal",
            "Value": 0
        },
        {
            "Name": "checkStatus",
            "Type": "int",
            "Operator": "greater",
            "Value": 2
        }
    ]
}

Connecting conditions with and works in the same way: set Type to and.

  1. expression (Matches when the expression evaluates to true)

{
    "Operator": "expression",
    "Value": "item.size == 43"
}

item.size refers to a property from the item. If you need a user property, use user.xxx.

Expressions support arithmetic, comparison, logical, and ternary operators. The following is a more complex example:

{
    "Operator": "expression",
    "Value": "!item.sold_out and user.list != nil ? item.size in user.list : true"
}

For the complete expression syntax, see https://expr-lang.org/docs/language-definition.

Note

The context features passed in through the features field of the engine API are stored on the user side. If the Value in the preceding configuration must be a variable instead of a fixed value, you can pass it in through the API or use an existing user feature, and set Value to "Value":"user.xxx", which means that the comparison is made against a property value on the user side. For example, to compare with the age property of the user, set it to "Value":"user.age"