All Products
Search
Document Center

Artificial Intelligence Recommendation:Prefetch user features

Last Updated:Oct 14, 2024

In some scenarios, after the system receives a recommendation request, the system obtains user features before a recommendation process starts. This topic describes how to prefetch user features.

Scenario

You can use one of the following methods to prefetch user features:

  • Prefetch user features before a recommendation process can be executed: User features need to be used in the recall or filtering phase. Therefore, you must obtain user features before the recommendation process starts.

  • Asynchronously prefetch user features while a recommendation process is executed: To improve performance, you need to asynchronously obtain user features. This way, you can use these user features in the coarse ranking or fine ranking phase.

In addition, the parameters of A/B testing are required for prefetching user features. The configurations for prefetching user features are similar to those for obtaining features. For more information, see Configure features.

Prefetch user features before a recommendation process can be executed

You can configure user feature prefetching in the UserFeatureConfs section. You can configure multiple scenarios in the UserFeatureConfs section. In this example, home_feed is the scenario name. The following code block shows the sample configurations. The sample configurations are similar to those in the FeatureConfs section. The actions in the UserFeatureConfs section are executed before a recommendation process starts. The recommendation process starts only after user features are loaded.

{
  "UserFeatureConfs": {
    "home_feed": {
      "AsynLoadFeature": true,
      "FeatureLoadConfs": [
        {
          "FeatureDaoConf": {
            "AdapterType": "hologres",
            "HologresName": "pairec-holo",
            "FeatureKey": "user:uid",
            "UserFeatureKeyName": "client_str",
            "HologresTableName": "dwd_ali_user_all_feature_v2_holo",
            "UserSelectFields": "*",
            "FeatureStore": "user"
          },
          "Features": [
            {
              "FeatureType": "new_feature",
              "FeatureName": "day_h",
              "Normalizer": "hour_in_day",
              "FeatureStore": "user"
            },
            {
              "FeatureType": "new_feature",
              "FeatureName": "week_day",
              "Normalizer": "weekday",
              "FeatureStore": "user"
            }
          ]
        }
      ]
    }
  }
}

The AsynLoadFeature parameter specifies whether to asynchronously load user features. When multiple tasks are configured in the FeatureLoadConfs section, the system can load user features asynchronously and concurrently. For more information about other parameters, see Description of parameters.

Asynchronously prefetch user features while a recommendation process is executed

If you want to obtain user features without blocking the execution of a recommendation process, you can add the FeatureAsyncLoad parameter and set it to true. The following code block shows the sample configurations:

{
  "UserFeatureConfs": {
    "home_feed": {
      "AsynLoadFeature": true,
      "FeatureLoadConfs": [
        {
          "FeatureDaoConf": {
            "AdapterType": "hologres",
            "HologresName": "pairec-holo",
            "FeatureKey": "user:uid",
            "UserFeatureKeyName": "client_str",
            "HologresTableName": "dwd_ali_user_all_feature_v2_holo",
            "UserSelectFields": "*",
            "FeatureStore": "user"
          },
          "Features": [
            {
              "FeatureType": "new_feature",
              "FeatureName": "day_h",
              "Normalizer": "hour_in_day",
              "FeatureStore": "user"
            },
            {
              "FeatureType": "new_feature",
              "FeatureName": "week_day",
              "Normalizer": "weekday",
              "FeatureStore": "user"
            }
          ]
        },
        {
          "FeatureDaoConf": {
              "AdapterType": "hologres",
            "FeatureAsyncLoad": true,
            "HologresName": "pairec-holo",
            "FeatureKey": "user:uid",
            "UserFeatureKeyName": "client_str",
            "HologresTableName": "dwd_ali_user_all_feature_v3_holo",
            "UserSelectFields": "*",
            "FeatureStore": "user"
          },
          "Features": []
        }
      ]
    }
  }
}

The preceding configurations show that two types of features are obtained:

  • All features are obtained from the dwd_ali_user_all_feature_v2_holo table. FeatureAsyncLoad is not configured. This indicates that a recommendation process cannot be executed when you obtain these features.

  • All features are obtained from the dwd_ali_user_all_feature_v3_holo table. The FeatureAsyncLoad parameter is set to true. This indicates that these features are asynchronously obtained while a recommendation process is executed.

For more information about other parameters, see Description of parameters.

Prefetch user features and store them in caches

To improve system performance, we recommend that you asynchronously obtain user features and store them in caches before you execute a recommendation process. When you need to use the features, obtain the cached features from caches and store them in the user feature set for efficient use. The following code block shows the sample configurations:

{
  "UserFeatureConfs": {
    "home_feed": {
      "AsynLoadFeature": true,
      "FeatureLoadConfs": [
        {
          "FeatureDaoConf": {
            "AdapterType": "hologres",
            "HologresName": "pairec-holo",
            "FeatureKey": "user:uid",
            "UserFeatureKeyName": "client_str",
            "FeatureAsyncLoad": true,
            "HologresTableName": "dwd_ali_user_all_feature_v2_holo",
            "UserSelectFields": "*",
            "CacheFeaturesName" :"test",//cache map
            "FeatureStore": "user"
          },
          "Features": [
            
            {
              "FeatureType": "new_feature",
              "FeatureName": "day_h",
              "Normalizer": "hour_in_day",
              "FeatureStore": "user"
            },
            {
              "FeatureType": "new_feature",
              "FeatureName": "week_day",
              "Normalizer": "weekday",
              "FeatureStore": "user"
            }
          ]
        }
      ]
    }
    }
}

The following section describes the key parameters. For more information about other parameters, see Description of parameters.

  • "FeatureAsyncLoad" = true: indicates that the user features are obtained in asynchronous mode.

  • "CacheFeaturesName": "test": indicates that the obtained features are cached in the cache map named test. The features are not stored in the user feature set. You can reference these features when you need to use them. For each set of features, you can specify different values for the CacheFeaturesName parameter.

Reference cached user features

When you reference preloaded user features during coarse ranking or fine ranking, you must configure the features to be referenced in the FeatureConfs section. The following code block shows the sample configurations:

{
    "FeatureConfs":{
        "home_feed_rebuild_v22":{
            "AsynLoadFeature":false,
            "FeatureLoadConfs":[
                {
                    "FeatureDaoConf":{
                        "LoadFromCacheFeaturesName":"test",
                        "FeatureStore":"user"
                    }
                },
                {
                    "FeatureDaoConf":{
                        "LoadFromCacheFeaturesName":"test1",
                        "FeatureStore":"user"
                    }
                }
            ]
        }
    }
}

The following section describes the key parameters. For more information about other parameters, see Description of parameters.

  • You do not need to concurrently obtain the features to be referenced. You can set the AsynLoadFeature parameter to false.

  • LoadFromCacheFeaturesName: indicates the cache map from which the user features are obtained. The value is consistent with that of the CacheFeaturesName parameter.

Description of parameters

The following table describes the parameters in the FeatureDaoConf section of FeatureLoadConfs:

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.

FeatureKey

string

Yes

Specifies the feature based on which you query a feature table.

The FeatureKey parameter indicates the field in a user feature table or an item feature table that is used to query features. For example, user:uid indicates that user IDs are queried from a user feature table. item:pair_id indicates that pair-id values of items are queried from an item feature table.

UserFeatureKeyName

string

No

The primary key field in the user feature table.

ItemFeatureKeyName

string

No

The primary key field in the item feature table.

HologresTableName

string

Yes

The name of the feature table in Hologres.

UserSelectFields

string

No

The user features to be obtained. You can specify this parameter as the wildcard (*) to obtain all user features. You can also specify multiple user features and separate them with commas (,). Example: "feature1,feature2".

CacheFeaturesName

string

Yes

The name of the cache map where the prefetched user features are cached.

FeatureStore

string

Yes

Specifies the location where the obtained features are stored. Valid values: user and item.

FeatureAsyncLoad

boolean

No

Specifies whether to asynchronously obtain features. Valid values: true and false. The value true specifies that features are asynchronously obtained.

FeatureType

string

Yes

The feature type.

LoadFromCacheFeaturesName

string

Yes

The name of the cache map from which the prefetched user features are obtained.