Ranking service configuration

更新时间:
复制 MD 格式

The ranking service accepts requests and returns ranked candidate arms in JSON format. This page describes the request parameters, response fields, configuration items, and feature types you need to set up the service.

Request parameters

All request parameters are passed as a JSON body.

ParameterTypeRequiredDescription
request_idstringYesA unique identifier for the request.
scenestringNoThe scenario name.
algostringYesThe algorithm name.
user_idstringYesThe user ID.
itemsstring arrayYesThe set of candidate arms to rank.
user_featuredictYesUser features used for ranking.
item_featuresdict arrayNoThe arm features. This parameter is optional.
limitYesThe maximum number of arms to return.

Response

The service returns a JSON object with an output array. Each element represents a ranked arm.

FieldTypeDescription
output[].idstringThe arm ID, corresponding to an entry in the input items array.
output[].scorestringThe predicted score for the arm. Arms are ordered by descending score.

Example response:

{
  "output": [
    {
      "id": "123",
      "score": "0.8"
    },
    {
      "id": "223",
      "score": "0.7"
    },
    {
      "id": "323",
      "score": "0.6"
    }
  ]
}

Configuration items

The configuration file is a JSON object with two top-level keys: HologresDSN and AlgoConf.

Configuration itemTypeDescription
HologresDSNdictConnection strings for Hologres databases. Each key is a database alias referenced elsewhere in the configuration.
AlgoConfdictAlgorithm configurations keyed by scenario name. Each value is the algorithm configuration for that scenario.
AlgoConf.${algo}.AlgoTypestringThe algorithm type. Valid values: random, disjoint, hybrid. See Algorithm types.
AlgoConf.${algo}.CompressFeaturebooleanSpecifies whether to compress features before storing them.
AlgoConf.${algo}.ArmFeatureDaoarrayConfiguration for loading arm features from Hologres at startup. See ArmFeatureDao fields.
AlgoConf.${algo}.LinUCBConfdictLinUCB algorithm parameters.
AlgoConf.${algo}.LinUCBConf.AlphanumberControls the exploration-exploitation tradeoff. A larger value favors exploration.
AlgoConf.${algo}.LinUCBConf.GlobalModelParamIdstringThe primary key of shared feature parameters of the hybrid algorithm in the model parameter table.
AlgoConf.${algo}.LinUCBConf.HologresNamestringThe database alias from HologresDSN to use for this algorithm.
AlgoConf.${algo}.LinUCBConf.ModelTablestringThe Hologres table that stores model parameters.
AlgoConf.${algo}.LinUCBConf.FeatureTablestringThe Hologres table that stores feature vectors after feature transformation.
AlgoConf.${algo}.LinUCBConf.FeatureTablePKeystringThe primary key of the feature vector table.
AlgoConf.${algo}.LinUCBConf.ArmIdKeystringThe column name for arm IDs in the Hologres table.
AlgoConf.${algo}.LinUCBConf.CacheMaxSizeintegerThe maximum number of model parameters to cache in local memory.
AlgoConf.${algo}.LinUCBConf.CacheTimeInSecondsintegerHow long to keep model parameters in local memory cache, in seconds.
AlgoConf.${algo}.LinUCBConf.RequestArmNumPerTimeintegerThe maximum number of model parameters to sync per request.
AlgoConf.${algo}.LinUCBConf.RequestArmIntervalintegerThe time interval for synchronizing model parameters.
AlgoConf.${algo}.LinUCBConf.ParallelismintegerThe parallelism of model prediction.
AlgoConf.${algo}.FeatureConfarrayFeature configuration for the feature generator. Each element defines how one feature is extracted and transformed. See FeatureConf fields.

Algorithm types

AlgoTypeDescription
randomReturns a random subset of the input candidate arms up to the limit. No model training or inference is performed.
disjointLinUCB variant where each arm has independent weight parameters. Use for standard contextual bandit scenarios.
hybridLinUCB variant where arms share some weight parameters, controlled by GlobalModelParamId. Use for cold-start scenarios where shared representations such as embeddings are available across arms.

ArmFeatureDao fields

Each element in ArmFeatureDao defines one feature table to load from Hologres.

FieldDescription
HologresNameThe database alias from HologresDSN.
HologresTableNameThe fully qualified Hologres table name in schema.table format.
FeatureKeyThe primary key column of the feature table.
SelectFieldsColumns to load. Use * to load all columns.

FeatureConf fields

Each element in FeatureConf defines one feature. The feature_type field determines which additional fields apply.

feature_typeAdditional fieldsDescription
raw_featureexpression, value_dimension (optional), separator (optional), share_weight (optional)A numeric or multi-value feature loaded as-is. Use value_dimension for vector features. Set share_weight: true to mark the feature as a shared weight in hybrid LinUCB.
binary_featureexpression, vocab_listA binary feature. The value is 1 if it matches any item in vocab_list, otherwise 0.
id_featureexpression, and one of: hash_bucket_size, vocab_list, boundaries, or num_buckets + offsetA categorical or bucketed feature. Use boundaries for numeric bucketing, vocab_list for fixed vocabularies, or hash_bucket_size for hashing.
geohash_featureexpression (array of two fields: latitude, longitude), geohash_precision, hash_bucket_sizeEncodes a geographic location as a geohash and hashes it into a bucket.
combo_featureexpression (array), hash_bucket_sizeCombines multiple fields into a single hashed feature.

Complete configuration example

The following example shows a configuration file with three scenarios: default (random), cold_start (hybrid LinUCB), and linucb (disjoint LinUCB). Both LinUCB scenarios connect to the same Hologres database aliased as vv_rec.

{
  "HologresDSN": {
    "vv_rec": "postgres://${asscessId}:${asscessKey}@hgpostcn-cn-xxxx-cn-beijing-vpc.hologres.aliyuncs.com:80/${db_name}?sslmode=disable&connect_timeout=10"
  },
  "AlgoConf": {
    "default": {
      "AlgoType": "random"
    },
    "cold_start": {
      "ArmFeatureDao": [
        {
          "HologresName": "vv_rec",
          "HologresTableName": "sv_rec.sv_dropoutnet_embedding",
          "FeatureKey": "svid",
          "SelectFields": "svid,embedding"
        }
      ],
      "AlgoType": "hybrid",
      "CompressFeature": false,
      "LinUCBConf": {
        "Alpha": 1.0,
        "ArmIdKey": "arm_id",
        "HologresName": "vv_rec",
        "ModelTable": "sv_rec.contextual_bandit_models_v2",
        "FeatureTable": "sv_rec.contextual_bandit_features_v2",
        "FeatureTablePKey": "user_id,arm_id",
        "CacheTimeInSeconds": 86400,
        "CacheMaxSize": 100000,
        "RequestArmNumPerTime": 100,
        "RequestArmInterval": 5,
        "Parallelism": 8
      },
      "FeatureConf": [
        {
          "feature_type": "raw_feature",
          "expression": "user:ColdStartVideoVectorRecall_embedding",
          "value_dimension": 64,
          "separator": ","
        },
        {
          "feature_type": "raw_feature",
          "expression": "arm:embedding",
          "value_dimension": 64,
          "share_weight": true
        },
        {
          "feature_type": "raw_feature",
          "expression": "arm:recall_score",
          "share_weight": true
        }
      ]
    },
    "linucb": {
      "ArmFeatureDao": [
        {
          "HologresName": "vv_rec",
          "HologresTableName": "vvarticle.smart_video",
          "FeatureKey": "smartVideoId",
          "SelectFields": "*"
        }
      ],
      "AlgoType": "disjoint",
      "CompressFeature": true,
      "LinUCBConf": {
        "Alpha": 1.0,
        "ArmIdKey": "arm_id",
        "HologresName": "vv_rec",
        "ModelTable": "sv_rec.contextual_bandit_models",
        "FeatureTable": "sv_rec.contextual_bandit_features",
        "FeatureTablePKey": "user_id,arm_id",
        "CacheTimeInSeconds": 86400,
        "CacheMaxSize": 100000,
        "RequestArmNumPerTime": 100,
        "RequestArmInterval": 5,
        "Parallelism": 8
      },
      "FeatureConf": [
        {
          "feature_type": "binary_feature",
          "expression": "gender",
          "vocab_list": ["M"]
        },
        {
          "feature_type": "raw_feature",
          "expression": "is_member"
        },
        {
          "feature_type": "raw_feature",
          "expression": "is_new_userid"
        },
        {
          "feature_type": "id_feature",
          "expression": "province",
          "hash_bucket_size": 36
        },
        {
          "feature_type": "id_feature",
          "expression": "constellation",
          "vocab_list": ["Cancer", "Taurus", "Capricorn", "Leo", "Gemini", "Aries", "Scorpio", "Pisces", "Sagittarius", "Aquarius", "Virgo", "Libra"]
        },
        {
          "feature_type": "id_feature",
          "expression": "birthyear",
          "boundaries": [1967, 1971, 1974, 1977, 1980, 1982, 1985, 1988, 1992, 2001]
        },
        {
          "feature_type": "id_feature",
          "expression": "fans_num",
          "boundaries": [2, 7, 16, 29, 54, 104, 210, 455, 1022]
        },
        {
          "feature_type": "id_feature",
          "expression": "follow_num",
          "boundaries": [1, 4, 9, 17, 30, 53, 99, 214, 544]
        },
        {
          "feature_type": "id_feature",
          "expression": "visitor_num",
          "boundaries": [0, 58, 157, 349, 795, 1865, 4796, 12664, 35753]
        },
        {
          "feature_type": "id_feature",
          "expression": "level",
          "num_buckets": 50,
          "offset": 1
        },
        {
          "feature_type": "geohash_feature",
          "expression": ["latitude", "longitude"],
          "geohash_precision": 4,
          "hash_bucket_size": 128
        },
        {
          "feature_type": "id_feature",
          "expression": "familyid",
          "hash_bucket_size": 50
        },
        {
          "feature_type": "id_feature",
          "expression": "userid_exposure_cnt_distinct_svid_15",
          "boundaries": [63, 159, 252, 348, 439, 508, 580, 679, 878]
        },
        {
          "feature_type": "id_feature",
          "expression": "userid_click_cnt_15",
          "boundaries": [0, 3, 7, 13, 19, 27, 42, 72, 151]
        },
        {
          "feature_type": "binary_feature",
          "expression": "os",
          "vocab_list": ["ios"]
        },
        {
          "feature_type": "combo_feature",
          "expression": ["os", "os_version"],
          "hash_bucket_size": 100
        },
        {
          "feature_type": "id_feature",
          "expression": "userid_likes_comment_collect_share_cnt_15",
          "boundaries": [0, 1, 2, 3, 6, 11, 27]
        },
        {
          "feature_type": "id_feature",
          "expression": "userid_max_duration_15",
          "boundaries": [13.3, 44, 80.8, 137, 200.8, 240.4, 276.9, 317.9, 443.9]
        },
        {
          "feature_type": "id_feature",
          "expression": "userid_min_duration_15",
          "boundaries": [0, 0.1, 5.1, 6.2, 7, 8, 9.7, 12.7]
        },
        {
          "feature_type": "id_feature",
          "expression": "userid_avg_duration_15",
          "boundaries": [11, 20.15, 25.2857, 29.3875, 32.8862, 36.2385, 39.915, 44.7783, 54.0227]
        },
        {
          "feature_type": "id_feature",
          "expression": "author_play_ct",
          "boundaries": [0, 50, 356, 2130]
        },
        {
          "feature_type": "id_feature",
          "expression": "user_auth_type",
          "vocab_list": ["0", "1", "13", "24", "14", "20", "30", "11", "5", "15", "3", "16", "12", "2", "10", "29", "19", "4", "17", "21", "31", "25", "7", "8", "9"]
        },
        {
          "feature_type": "id_feature",
          "expression": "author_av_ct",
          "boundaries": [0, 1, 2, 5, 14, 34, 90]
        },
        {
          "feature_type": "id_feature",
          "expression": "flower_ct",
          "boundaries": [0, 72, 347, 1070, 2610, 6463, 16157]
        },
        {
          "feature_type": "id_feature",
          "expression": "userid_avg_hot_15",
          "boundaries": [0, 0.018, 0.0741, 0.25, 8.53, 46.37, 94.11, 159.86]
        },
        {
          "feature_type": "id_feature",
          "expression": "diamond_ct",
          "boundaries": [0, 10, 50, 160, 460, 1332, 4910]
        },
        {
          "feature_type": "id_feature",
          "expression": "userid_exposure_cnt_distinct_svid_7",
          "boundaries": [36, 93, 146, 201, 248, 285, 332, 399, 521]
        },
        {
          "feature_type": "id_feature",
          "expression": "family_member_ct",
          "boundaries": [0, 82, 159, 234, 322, 438, 642, 1113]
        },
        {
          "feature_type": "id_feature",
          "expression": "author_sv_ct",
          "boundaries": [0, 2, 8, 34]
        },
        {
          "feature_type": "id_feature",
          "expression": "userid_exposure_cnt_15",
          "boundaries": [63, 162, 257, 354, 446, 514, 587, 687, 890]
        }
      ]
    }
  }
}