All Products
Search
Document Center

:Configure filters

Last Updated:Jun 20, 2026

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

Filter configurations

You can configure filters by configuring the FilterConfs parameter in the following sample code. FilterConfs is an array of objects and can be used to 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: The latency of real-time logs makes it impossible to immediately identify which items are exposed. Therefore, the list of items returned by the recommendation engine serves 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 maximum number of recent batches of items. This parameter is equivalent to limit ${MaxItems} in an SQL statement. MaxItems specifies the maximum number of batches, instead of the maximum number of items. One batch of items is returned for a recommendation request.

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 is used to write the item data to the exposure table. If this parameter is left empty, the built-in function of the PAI-Rec engine is used. In this case, only item IDs are returned.

GenerateItemDataExpr

string

No

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

GenerateUserDataExpr

string

No

Use an expression to construct the user identifier in the exposure table. For the expression syntax, see expr-lang/expr. The available variables are uid, context, and sprintf. If left 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 data source that is specified in the HologresConfs parameter. Example: holo_info.

HologresTableName

string

Yes

The name of the exposure table.

You can set time_to_live_in_seconds for the exposure table 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. For Type, select Real-time.

  2. For Feature Entity, select user.

  3. For the Feature Fields, add user_id, item_id, and timestamp with the following data types: string for user_id and item_id, and int64 for timestamp. You must set user_id as the Primary Key and select timestamp as the Event Time.

  4. For Feature Lifecycle, set the desired retention period for user exposure data. The default is 2 days.

  5. In the required Advanced Configuration section, enter {"table_type":"bloom", "expose_count":5000}. The table_type parameter enables the Bloom filter, and expose_count sets the maximum number of exposure items to retain per 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 defines the maximum retention period for pseudo-exposure items written by the engine. This parameter applies only when WriteLog is true. The preceding configuration is for pseudo-exposure. For real exposure, where the PAI-Rec engine does not write data, set WriteLog to false. In this scenario, the TimeInterval parameter is not needed.

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.

See Write Features for instructions on writing real exposure data.

The following table describes the parameters in DaoConf.

Parameter

Type

Required

Description

AdapterType

string

Yes

The type of the data source. The value must be featurestore.

FeatureStoreName

string

Yes

The user-defined name for the PAI-FeatureStore instance, specified in FeatureStoreConfs.

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 data source that is specified in the RedisConfs parameter. Example: redis_info.

RedisPrefix

string

No

The prefix of the key for exposure data. A key consists of the value of RedisPrefix and the unique ID (UID) of a user.

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 data source that is specified in the TableStoreConfs parameter. Example: tablestore_info.

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.

Parameter

Category

Type

Description

Example

user_id

Primary key

string

The UID of the user.

10944750

auto_id

Primary key

integer

The auto-increment column.

item_ids

Property

string

The item IDs. Multiple item IDs are separated with commas (,). When multiple items are exposed simultaneously, the system will insert a single record with the item IDs.

17019277,17019278

Impression de-ranking

When a user's recall pool is small, impression filtering can filter out all available items. To avoid this, tag items that have already been seen rather than filtering them out completely. During reranking, you can then use boosting and demotion to move these tagged items to the end of the list. The following example demonstrates this configuration for a Hologres data source. The process is similar for other data sources.

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

This JSON example defines filter and sort configurations. The FilterConfs section uses the holo_exposure_filter to filter out items a user has already been exposed to, based on data from the exposure_history table in Hologres. The SortConfs section uses boost_score_sort for score boosting: if an item has been exposed (_is_exposure_ is 1), its score is divided by 10, reducing its ranking.

User2ItemCustomFilter

Hologres

To filter data, provide a custom user-to-item filter table. You typically generate this table offline. For example, you can run a daily job that aggregates all items a user was exposed to in the past 15 days. The item IDs are then stored in a field, such as item_ids, as a comma-separated string.

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

DaoConf parameters

Parameter

Type

Required

Description

AdapterType

string

Yes

The data source type. The value is hologres.

HologresName

string

Yes

The custom name for the Hologres data source, as configured in HologresConfs. Example: holo_info.

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

A comma-separated list of unique item IDs.

17019277,17019278

Tablestore (OTS)

To filter data, provide a custom user-to-item filter table.

{
    "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 data source type. The value is tablestore.

TableStoreName

string

Yes

The custom name of the data source that is specified in the TableStoreConfs parameter. Example: tablestore_info.

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 UID of the user.

10944750

item_ids

Property

string

The item IDs. Multiple item IDs are separated with commas (,).

17019277,17019278

PAI-FeatureStore

Warning

This feature supports only FeatureViews that use FeatureDB as the online data source.

Similar to the exposure filtering described earlier, you provide a real-time FeatureView. Write data to this view by using a Java SDK or Flink connector. For details, see Write Features. The PAI-Rec engine reads data from this view for filtering. Configure the FeatureView 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. For Type, select Real-time.

  2. For Feature entity, select user.

  3. The Feature fields must include user_id, item_id, and timestamp. Set user_id as the primary key and select event time for timestamp. You must designate a primary key and an event time. For data types, user_id and item_id are string, and timestamp is int64. The timestamp is in milliseconds.

  4. The default feature TTL is 2 days. Adjust this value as needed. The feature TTL specifies the time-to-live for a data row, calculated based on the timestamp value.

  5. The Advanced settings field is required. Enter {"table_type":"bloom"}. The table_type parameter enables bloom filter support for the created table.

    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 parameters

Parameter

Type

Required

Description

AdapterType

string

Yes

The data source type. The value is featurestore.

FeatureStoreName

string

Yes

The custom name for the PAI-FeatureStore data source, as configured in FeatureStoreConfs.

FeatureStoreViewName

string

Yes

The name of the FeatureView used for 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

PriorityAdjustCountFilter is used to control the number of items that are selected from the returned results of recall links based on scores. Each recall link sorts the recommended items based on their scores.

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

The type of the number adjustment. Valid values: accumulator and fix.

accumulator:

  • For the preceding configuration, if the number of items selected from the returned results of recall_1 is less than 125, more items will be selected from the returned results of recall_2 to reach a total of 250.

fix:

  • The number of items selected from the returned results of each recall link is fixed. If the number of selected items for one recall link is less than the specified value, the system does not select more items for other recall links to compensate for the shortfall.

ItemStateFilter

Filtering retrieved items by state requires fetching their states in real time, as they can change at any moment. These states are typically stored in a dedicated table.

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 data source that is specified in the HologresConfs parameter. Example: holo_info.

HologresTableName

string

Yes

The name of the table that stores item states in the Hologres instance.

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 domain of the feature. Valid values: user and item. Defaults to 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: You can use both WhereClause and FilterParams for filtering. WhereClause filters data at the data source, similar to an SQL WHERE clause. FilterParams filters the retrieved data locally.

For more information about using operators, see the 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. The value must be featurestore.

FeatureStoreName

string

Yes

The custom name of the PAI-FeatureStore instance, which is configured in 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 domain of the feature. Valid values: user and item. Defaults to item.

Operator

string

Yes

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

Type

string

Yes

The feature type.

Value

object

Yes

The condition value.

For more information about using operators, see the 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, if there are three recall channels (A, B, and C) with weights of 1, 2, and 3, respectively, the combination logic works as follows:

  • Select one element from candidate set A.

  • Select two elements from candidate set B.

  • Select 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 retrieved from a candidate set duplicates a previously selected one, the system searches the same candidate set for a unique replacement. For example, if the three elements retrieved from candidate set C duplicate elements already selected from sets A and B, the system searches set C for replacements.

  • SKIP_ON_DUPLICATE: The system skips any duplicate elements and moves on to the next iteration. For example, if the three elements retrieved from candidate set C duplicate elements from sets A and B, candidate set C returns no elements in this round. The process then starts a new iteration, beginning with candidate set 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. The value must be SnakeFilter.

RetainNum

string

Yes

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

SnakeType

string

No

  • REFILL_ON_DUPLICATE: Continues to search within the current recall channel to meet the quota. This is the default value.

  • SKIP_ON_DUPLICATE: Skips duplicate elements without refilling the quota and proceeds to 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

CompletelyFairFilter is used to sort items returned by recall links based on the scores of the items, and then select items from the results of each link in a fair manner.

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

DimensionFieldUniqueFilter

DimensionFieldUniqueFilter works in a different way from UniqueFilter. DimensionFieldUniqueFilter removes items with duplicate field values.

{
    "FilterConfs": [
        {
            "Name": "DimensionFieldUniqueFilter",
            "FilterType": "DimensionFieldUniqueFilter",
            "Dimension": ""
        }
    ]
}

Parameter

Type

Required

Description

Name

string

Yes

The name of the custom filter.

FilterType

string

Yes

The filter type. Must be DimensionFieldUniqueFilter.

Dimension

string

Yes

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

ConditionFilter

This is a composite filter that dynamically executes a specific filter based on request conditions, such as user features or those passed in the context. You can configure one or more combinations, each linking a set of conditions to a specific filter defined in FilterConfs.

The preceding example defines two standalone filters: adjust_count_filter and CompletelyFairFilter. ConditionFilter is a composite filter that routes requests based on conditions. When the user attribute query equals "1", it uses adjust_count_filter. If no condition matches, it falls back to the filter specified by DefaultFilterName (CompletelyFairFilter).

The configuration parameters are as follows:

Parameter

Type

Required

Description

Name

string

Yes

The name of the custom filter.

FilterType

string

Yes

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

ConditionFilterConfs

json map

Yes

The configuration for the conditions.

  • FilterConfs

json array

No

An array of condition matching rules. When a request matches a condition, the service applies the corresponding filter.

  • DefaultFilterName

string

No

If no conditions in FilterConfs match, the service applies the filter specified by this parameter.

FilterConfs configuration:

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.

Configure FilterParamConfig as follows:

Parameter

Type

Required

Description

Name

string

Yes

The feature name for an item or user.

Domain

string

Yes

An enumerated value (item or user) specifying whether the feature is for an item or a user. The Name must exist in the properties of the corresponding item or user.

Operator

string

Yes

The comparison operator. Possible 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 details on the condition settings, see the appendix.

UniqueFilter

UniqueFilter is designed to ensure that each item ID is unique. If the same item ID is returned by two recall links, UniqueFilter prioritizes the item ID that is first returned.

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

Filter usage

Similar to the recall configuration, the filter configuration uses the FilterNames parameter. This parameter is a Map[string]object that maps each scenario to a set of filter policies.

  • ${scene_name}: The name of the scenario. To apply the same configuration to multiple scenarios, 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 the specified value)

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

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

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

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

String

{
    "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 and configure it with 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 of the specified items)

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

The following code uses the not_contains operator to filter for items where the state field does not contain any value from the array [2, 4, 6]. This filter is useful for excluding specific items from a query result. For example, you could use this filter to retrieve all tasks except those with a status of 'archived' (ID 2), 'on-hold' (ID 4), or 'deprecated' (ID 6).

You can also use a string array. For configuration details, see the contains operator.

  1. bool (Combines 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
        }
    ]
}

Using and is similar: set Type to and.

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

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

item.size is an attribute of item; to access an attribute of user, 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 a complete definition of the expression syntax, refer to https://expr-lang.org/docs/language-definition.

Note

Context features provided in the features field of the engine interface are associated with the user. If Value must be a variable instead of a fixed value, set it to "user.xxx" to reference a specific user attribute. For example, to reference the user's age attribute, the setting is "Value":"user.age".