Prefetch user features

Updated at:

PAI-Rec supports three prefetch patterns—blocking, async, and cache—that control when and how user features are loaded, so you can reduce end-to-end latency without sacrificing feature availability.

A/B testing parameters are required for user feature prefetching. The configuration structure mirrors that of Configure features.

Choose a prefetch pattern

Pattern When to use Blocks recommendation pipeline?
Blocking prefetch Features needed in the recall or filtering phase Yes — pipeline waits until features are loaded
Async prefetch Features needed only in coarse ranking or fine ranking No — features load in parallel with the pipeline
Cache prefetch High-traffic scenarios where latency matters No — features are loaded before the request and served from cache

Blocking prefetch

Use this pattern when user features must be available before the recommendation pipeline starts — for example, when recall or filtering logic depends on them.

Configure the prefetch in the UserFeatureConfs section. The pipeline starts only after all features in FeatureLoadConfs finish loading.

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

AsynLoadFeature: true enables concurrent loading when multiple entries are listed in FeatureLoadConfs. The pipeline still waits for all of them to complete before proceeding.

Async prefetch

Use this pattern when some features are only needed in coarse ranking or fine ranking. Loading them asynchronously — without blocking the earlier pipeline stages — reduces end-to-end latency.

Set FeatureAsyncLoad: true on any FeatureDaoConf entry to load it in parallel with the running pipeline.

The following example loads two feature sets. The first blocks (no FeatureAsyncLoad), and the second loads asynchronously:

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

In this configuration:

  • Features from dwd_ali_user_all_feature_v2_holo block the pipeline — FeatureAsyncLoad is not set.

  • Features from dwd_ali_user_all_feature_v3_holo load asynchronously — FeatureAsyncLoad: true.

Cache prefetch

In latency-sensitive scenarios, you can load user features into a cache before the recommendation request arrives. The pipeline then reads from the cache instead of querying the data source at request time.

This pattern requires two configuration steps: first, prefetch into a cache; then, reference that cache during ranking.

Step 1: Prefetch into a cache

Set both FeatureAsyncLoad: true and CacheFeaturesName on the FeatureDaoConf. Features are stored in the named cache map, not directly in the user feature set.

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

Assign a unique CacheFeaturesName value for each feature set you want to cache separately.

Step 2: Reference cached features during ranking

In the FeatureConfs section for your ranking scenario, load features from the cache using LoadFromCacheFeaturesName. Set AsynLoadFeature: false — no concurrency is needed when reading from cache.

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

The value of LoadFromCacheFeaturesName must match the CacheFeaturesName value used in Step 1.

Parameter reference

The following table lists parameters in the FeatureDaoConf section of FeatureLoadConfs.

Parameter Type Required Description
AdapterType string Yes Data source type. Set to hologres.
HologresName string Yes Custom name of the Hologres data source, as defined in HologresConfs. Example: holo_info.
FeatureKey string Yes Field used to query the feature table. user:uid queries user IDs from a user feature table; item:pair_id queries pair-id values from an item feature table.
UserFeatureKeyName string No Primary key field in the user feature table.
ItemFeatureKeyName string No Primary key field in the item feature table.
HologresTableName string Yes Name of the feature table in Hologres.
UserSelectFields string No User features to fetch. Use the wildcard * to fetch all fields, or specify a comma-separated list. Example: "feature1,feature2".
CacheFeaturesName string Yes Name of the cache map where prefetched features are stored. Assign a unique value for each feature set you want to cache separately.
FeatureStore string Yes Where to store the fetched features. Valid values: user and item.
FeatureAsyncLoad boolean No Whether to fetch this feature set asynchronously during the pipeline. Set to true to enable async loading.
FeatureType string Yes The feature type.
LoadFromCacheFeaturesName string Yes Name of the cache map to read from. Must match the CacheFeaturesName value used when prefetching.

What's next