全部產品
Search
文件中心

Platform For AI:FeatureStore最佳實務

更新時間:Aug 01, 2024

本文為您介紹在不使用阿里雲其他產品的情境下,如何在推薦系統中應用特徵平台FeatureStore SDK管理特徵。

背景資訊

推薦系統是一種能夠根據使用者的興趣和偏好,向使用者推薦個人化的內容或產品的系統。在推薦系統中,提取和配置使用者或物品的特徵資訊非常重要。通過本文提供的解決方案,您可以瞭解到如何使用FeatureStore搭建推薦系統,以及FeatureStore在推薦系統中如何通過各個版本的SDK管理特徵資料。

更多關於FeatureStore的資訊,請參見FeatureStore概述

如果您在配置或使用過程中有任何問題,可以搜尋DingTalk群號:34415007523,進入答疑群聯絡技術人員進行諮詢。

前提條件

在開始執行操作前,請確認您已完成以下準備工作。

依賴產品

具體操作

人工智慧平台 PAI

雲原生MaxCompute MaxCompute

即時數倉 Hologres

巨量資料開發治理平台 DataWorks

一、準備資料

同步資料表

一般對於推薦情境,需要準備三張資料表:user側的特徵表item側的特徵表以及Label表

為方便實踐操作,我們在MaxCompute的pai_online_project專案中提前準備了類比產生的使用者表、物料表和Label表進行樣本說明。其中,使用者表、物料表每個分區大約有10萬條資料,在MaxCompute中分別佔用約70 MB;Label表每個分區約45萬條資料,在MaxCompute中佔用約5 MB。

您需要在DataWorks中執行SQL命令,將使用者表、物料表、Label表從pai_online_project專案同步到自己的MaxCompute中。具體操作步驟如下:

  1. 登入DataWorks控制台

  2. 在左側導覽列單擊資料建模與開發 > 資料開發

  3. 選擇已建立的DataWorks工作空間後,單擊進入資料開發

  4. 滑鼠移至上方至建立,選擇建立節點 > MaxCompute > ODPS SQL,在彈出的頁面中配置節點參數。

    參數

    取值建議

    引擎執行個體

    選擇已建立的MaxCompute引擎。

    節點類型

    ODPS SQL

    路徑

    商務程序/Workflow/MaxCompute

    名稱

    可自訂名稱。

  5. 單擊確認

  6. 在建立節點地區運行以下SQL命令,將使用者表、物料表、Label表從pai_online_project專案同步到自己的MaxCompute中。資源群組選擇已建立的獨享資源群組。

    同步處理的使用者表:rec_sln_demo_user_table_preprocess_all_feature_v1(單擊查看詳情)

    CREATE TABLE IF NOT EXISTS rec_sln_demo_user_table_preprocess_all_feature_v1
    like pai_online_project.rec_sln_demo_user_table_preprocess_all_feature_v1
    STORED AS ALIORC  
    LIFECYCLE 90;
    
    INSERT OVERWRITE TABLE rec_sln_demo_user_table_preprocess_all_feature_v1 PARTITION (ds)
    SELECT *
    FROM pai_online_project.rec_sln_demo_user_table_preprocess_all_feature_v1
    WHERE ds >= '20231022' and ds <='20231024'

    運行後可以擷取以下三個分區的資料:

    • ds=20231022

    • ds=20231023

    • ds=20231024

    同步物料表:rec_sln_demo_item_table_preprocess_all_feature_v1(單擊查看詳情)

    CREATE TABLE IF NOT EXISTS rec_sln_demo_item_table_preprocess_all_feature_v1
    like pai_online_project.rec_sln_demo_item_table_preprocess_all_feature_v1
    STORED AS ALIORC  
    LIFECYCLE 90;
    
    INSERT OVERWRITE TABLE rec_sln_demo_item_table_preprocess_all_feature_v1 PARTITION(ds)
    SELECT *
    FROM pai_online_project.rec_sln_demo_item_table_preprocess_all_feature_v1
    WHERE ds >= '20231022' and ds <='20231024'

    運行後可以擷取以下三個分區的資料:

    • ds=20231022

    • ds=20231023

    • ds=20231024

    同步Label表:rec_sln_demo_label_table(單擊查看詳情)

    CREATE TABLE IF NOT EXISTS rec_sln_demo_label_table
    like pai_online_project.rec_sln_demo_label_table
    STORED AS ALIORC  
    LIFECYCLE 90;
    
    INSERT OVERWRITE TABLE rec_sln_demo_label_table PARTITION (ds)
    SELECT *
    FROM pai_online_project.rec_sln_demo_label_table
    WHERE ds >= '20231022' and ds <='20231024'

    運行後可以擷取以下三個分區的資料:

    • ds=20231022

    • ds=20231023

    • ds=20231024

完成上述操作後,您可以在自己的工作空間內查看使用者表rec_sln_demo_user_table_preprocess_all_feature_v1、物料表rec_sln_demo_item_table_preprocess_all_feature_v1和Label表rec_sln_demo_label_table,後續的實踐操作將以這三張表為例進行說明。

配置資料來源

FeatureStore一般需要配置兩個資料來源:離線資料來源(MaxCompute)和線上資料來源(Hologres/GraphCompute/TableStore)。本文以MaxComputeHologres為例進行說明。

  1. 登入PAI控制台,在左側導覽列單擊資料準備>特徵平台(FeatureStore)

  2. 選擇工作空間後,單擊進入FeatureStore

  3. 配置MaxCompute資料來源。

    1. 單擊管理資料來源,進入管理資料來源頁面後單擊建立資料來源,在彈出的頁面中配置MaxCompute資料來源具體參數。

      參數

      取值建議

      類型

      MaxCompute

      名稱

      可自訂名稱。

      MaxCompute專案名

      選擇已建立的MaxCompute專案。

    2. 請複製語句並單擊立即前往,同步資料至Hologres,在DataWorks執行該語句後,即可完成授權。

      說明

      授權操作需要您的帳號擁有admin許可權,具體操作詳情請參見通過命令系統管理使用者許可權通過控制台(新版)系統管理使用者許可權

    3. 完成後單擊提交

  4. 配置Hologres資料來源。

    1. 單擊管理資料來源。進入管理資料來源頁面後單擊建立資料來源,在彈出的頁面中配置Hologres資料來源具體參數。

      參數

      取值建議

      類型

      Hologres

      名稱

      可自訂名稱。

      執行個體ID

      選擇已建立的Hologres執行個體名稱。

      資料庫名稱

      選擇已建立的執行個體資料庫。

    2. 完成後單擊提交

    3. 對Hologres進行授權,具體操作詳情請參見配置資料來源

二、建立並註冊FeatureStore

您可以根據實際需求選擇通過控制台或者SDK兩種方式建立並註冊FeatureStore。由於後續匯出Training Set和同步資料都需要使用SDK,所以如果選擇控制台操作的方式,完成控制台配置後,仍需要安裝FeatureStore Python SDK。

方式一:控制台操作

  1. 建立FeatureStore專案

    1. 登入PAI控制台,在左側導覽列單擊資料準備>特徵平台(FeatureStore)

    2. 選擇工作空間後,單擊進入FeatureStore

    3. 單擊建立專案,在彈出的頁面中設定項目參數。

      參數

      取值建議

      名稱

      可自訂名稱。本文以fs_demo為例進行說明。

      描述

      可自訂描述。

      離線資料來源(Offline Store)

      選擇已建立的MaxCompute資料來源。

      線上資料來源(Online Store)

      選擇已建立的Hologres資料來源。

    4. 單擊提交,完成FeatureStore專案建立。

  2. 建立特徵實體(Feature Entity)

    1. 在FeatureStore專案列表頁面,單擊專案名稱,進入專案詳情頁面。

    2. 特徵實體頁簽中單擊建立特徵實體,在彈出的頁面中配置user特徵實體參數。

      參數

      取值建議

      特徵實體名稱

      可自訂名稱。本文以user為例進行說明。

      Join Id

      user_id

    3. 單擊提交

    4. 單擊建立特徵實體,在彈出的頁面中配置item特徵實體參數。

      參數

      取值建議

      特徵實體名稱

      可自訂名稱。本文以item為例進行說明。

      Join Id

      item_id

    5. 單擊提交,完成特徵實體建立。

  3. 建立特徵視圖(Feature View)

    1. 在特徵專案詳情頁面的特徵視圖頁簽,單擊建立特徵視圖,在彈出的頁面中配置user特徵視圖參數。

      參數

      取值建議

      視圖名稱

      可自訂名稱。本文以user_table_preprocess_all_feature_v1為例進行說明。

      類型

      離線

      寫入方式

      使用離線表

      資料來源

      選擇已建立的MaxCompute資料來源。

      特徵表

      選擇已準備的使用者表rec_sln_demo_user_table_preprocess_all_feature_v1

      特徵欄位

      勾選user_id主鍵。

      同步線上特徵表

      特徵實體

      user

      特徵生命週期(秒)

      保持預設。

    2. 單擊提交

    3. 單擊建立特徵視圖,在彈出的頁面中配置item特徵視圖。

      參數

      取值建議

      視圖名稱

      可自訂名稱。本文以item_table_preprocess_all_feature_v1為例進行說明。

      類型

      離線

      寫入方式

      使用離線表

      資料來源

      選擇已建立的MaxCompute資料來源。

      特徵表

      選擇已準備的物料表rec_sln_demo_item_table_preprocess_all_feature_v1

      特徵欄位

      勾選item_id主鍵。

      同步線上特徵表

      特徵實體

      item

      特徵生命週期(秒)

      保持預設。

    4. 完成後單擊提交,完成特徵視圖建立。

  4. 建立Label表

    1. 在特徵專案詳情頁面的Label表頁簽,單擊建立Label表,在彈出的頁面中配置Label表資訊。

      參數

      取值建議

      資料來源

      選擇已建立的MaxCompute資料來源。

      表名

      選擇已準備的Label表rec_sln_demo_label_table

    2. 單擊提交

  5. 建立模型特徵

    1. 在特徵專案詳情頁面的模型特徵頁簽,單擊建立模型特徵,在彈出的頁面中配置模型特徵參數

      參數

      取值建議

      模型特徵名

      自訂。本文以fs_rank_v1為例進行說明。

      選擇特徵

      選擇已建立的user特徵視圖和item特徵視圖。

      Label表名稱

      選擇已建立的Label表rec_sln_demo_label_table

    2. 單擊提交,完成模型特徵建立。

    3. 在模型特徵列表頁面,單擊已建立模型右側的詳情

    4. 在彈出的模型特徵詳情頁面的基本資料頁簽中,可查看匯出表名fs_demo_fs_rank_v1_trainning_set,後續基於該表進行特徵生產以及模型訓練。

  6. 安裝FeatureStore Python SDK,具體操作詳情請參見方式二:FeatureStore Python SDK操作

方式二:FeatureStore Python SDK操作

  1. 登入DataWorks控制台介面。

  2. 在左側導覽列單擊資源群組列表

  3. 獨享資源群組頁簽中,單擊相應調度資源後的image.png表徵圖,選擇營運助手

  4. 單擊建立命令,在彈出的頁面中配置命令參數。

    參數

    取值建議

    命令名稱

    可自訂名稱。本文以install為例進行說明。

    命令類型

    手動輸入(無法使用pip命令安裝第三方包)

    命令內容

    /home/tops/bin/pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple https://feature-store-py.oss-cn-beijing.aliyuncs.com/package/feature_store_py-1.3.1-py3-none-any.whl

    逾時時間

    可自訂時間。

  5. 單擊建立,完成命令建立。

  6. 單擊運行命令,在彈出的頁面中單擊運行

  7. 可單擊重新整理查看最新執行狀態,待狀態為成功時,即表示完成安裝。

使用SDK的具體操作步驟請參見DSW Gallery

三、同步資料節點運行

上線前需要例行將資料同步節點,即例行將資料從離線資料來源同步到線上資料來源中,線上會即時地從線上資料來源中讀取。本樣本需要將user特徵表和item特徵表提交例行,具體操作如下。

  1. 登入DataWorks控制台

  2. 在左側導覽列單擊資料建模與開發 > 資料開發

  3. 選擇已建立的DataWorks工作空間後,單擊進入資料開發

  4. 例行同步user表。

    1. 滑鼠移至上方至建立,選擇建立節點 > MaxCompute > PyODPS 3

    2. 複製以下內容到指令碼中,完成user_table_preprocess_all_feature_v1例行同步。

      from feature_store_py.fs_client import FeatureStoreClient
      import datetime
      from feature_store_py.fs_datasource import MaxComputeDataSource
      import sys
      
      cur_day = args['dt']
      print('cur_day = ', cur_day)
      
      access_key_id = o.account.access_id
      access_key_secret = o.account.secret_access_key
      fs = FeatureStoreClient(access_key_id=access_key_id, access_key_secret=access_key_secret, region='cn-beijing')
      cur_project_name = 'fs_demo'
      project = fs.get_project(cur_project_name)
      
      feature_view_name = 'user_table_preprocess_all_feature_v1'
      batch_feature_view = project.get_feature_view(feature_view_name)
      task = batch_feature_view.publish_table(partitions={'ds':cur_day}, mode='Overwrite')
      task.wait()
      task.print_summary()
    3. 單擊右側調度配置,在彈出的頁面中配置調度參數。

      參數

      取值建議

      調度參數

      參數名

      dt

      參數值

      $[yyyymmdd-1]

      資源屬性

      調度資源群組

      選擇已建立的獨享資源群組。

      調度依賴

      選擇已建立的user表。

    4. 節點配置並測試完成後,儲存並提交節點配置。

    5. 執行補資料操作。操作詳情請參見同步資料表

  5. 同步例行item表。

    1. 滑鼠移至上方至新增,選擇建立節點 > MaxCompute > PyODPS 3,在彈出的頁面中配置節點參數。

    2. 單擊確認

    3. 複製以下內容到指令碼中。

      item_table_preprocess_all_feature_v1 同步例行(單擊查看詳情)

      from feature_store_py.fs_client import FeatureStoreClient
      import datetime
      from feature_store_py.fs_datasource import MaxComputeDataSource
      import sys
      
      cur_day = args['dt']
      print('cur_day = ', cur_day)
      
      access_key_id = o.account.access_id
      access_key_secret = o.account.secret_access_key
      fs = FeatureStoreClient(access_key_id=access_key_id, access_key_secret=access_key_secret, region='cn-beijing')
      cur_project_name = 'fs_demo'
      project = fs.get_project(cur_project_name)
      
      feature_view_name = 'item_table_preprocess_all_feature_v1'
      batch_feature_view = project.get_feature_view(feature_view_name)
      task = batch_feature_view.publish_table(partitions={'ds':cur_day}, mode='Overwrite')
      task.wait()
      task.print_summary()
    4. 單擊右側調度配置,在彈出的頁面中配置調度參數。

      參數

      取值建議

      調度參數

      參數名

      dt

      參數值

      $[yyyymmdd-1]

      資源屬性

      調度資源群組

      選擇已建立的獨享資源群組。

      調度依賴

      選擇已建立的item表。

    5. 節點配置並測試完成後,儲存並提交節點配置。

    6. 執行補資料操作。操作詳情請參見同步資料表

  6. 同步完成後,可以在Hologres中查看最新同步的特徵。

四、匯出Training Set指令碼

  1. 登入DataWorks控制台

  2. 在左側導覽列單擊資料建模與開發>資料開發

  3. 選擇已建立的DataWorks工作空間後,單擊進入資料開發

  4. 滑鼠移至上方至建立,選擇建立節點 > MaxCompute>PyODPS 3,在彈出的頁面中配置節點參數。

    參數

    取值建議

    引擎執行個體

    選擇已建立的MaxCompute引擎。

    節點類型

    PyODPS 3

    路徑

    商務程序/Workflow/MaxCompute

    名稱

    可自訂名稱。

  5. 單擊確認

  6. 複製以下內容到指令碼中。

    from feature_store_py.fs_client import FeatureStoreClient
    from feature_store_py.fs_project import FeatureStoreProject
    from feature_store_py.fs_datasource import LabelInput, MaxComputeDataSource, TrainingSetOutput
    from feature_store_py.fs_features import FeatureSelector
    from feature_store_py.fs_config import LabelInputConfig, PartitionConfig, FeatureViewConfig
    from feature_store_py.fs_config import TrainSetOutputConfig, EASDeployConfig
    import datetime
    import sys
    
    cur_day = args['dt']
    print('cur_day = ', cur_day)
    offset = datetime.timedelta(days=-1)
    pre_day = (datetime.datetime.strptime(cur_day, "%Y%m%d") + offset).strftime('%Y%m%d')
    print('pre_day = ', pre_day)
    
    
    access_key_id = o.account.access_id
    access_key_secret = o.account.secret_access_key
    fs = FeatureStoreClient(access_key_id=access_key_id, access_key_secret=access_key_secret, region='cn-beijing')
    cur_project_name = 'fs_demo'
    project = fs.get_project(cur_project_name)
    
    label_partitions = PartitionConfig(name = 'ds', value = cur_day)
    label_input_config = LabelInputConfig(partition_config=label_partitions)
    
    user_partitions = PartitionConfig(name = 'ds', value = pre_day)
    feature_view_user_config = FeatureViewConfig(name = 'user_table_preprocess_all_feature_v1',
    partition_config=user_partitions)
    
    item_partitions = PartitionConfig(name = 'ds', value = pre_day)
    feature_view_item_config = FeatureViewConfig(name = 'item_table_preprocess_all_feature_v1',
    partition_config=item_partitions)
    feature_view_config_list = [feature_view_user_config, feature_view_item_config]
    train_set_partitions = PartitionConfig(name = 'ds', value = cur_day)
    train_set_output_config = TrainSetOutputConfig(partition_config=train_set_partitions)
    
    
    model_name = 'fs_rank_v1'
    cur_model = project.get_model(model_name)
    task = cur_model.export_train_set(label_input_config, feature_view_config_list, train_set_output_config)
    task.wait()
    print("task_summary = ", task.task_summary)
  7. 單擊右側的調度配置,在彈出的頁面中配置調度參數。

    參數

    取值建議

    調度參數

    參數名

    dt

    參數值

    $[yyyymmdd-1]

    資源屬性

    調度資源群組

    選擇已建立的獨享資源群組。

    調度依賴

    選擇已建立的user表和item表。

  8. 節點配置並測試完成後,儲存並提交節點配置。

  9. 執行補資料操作。操作詳情請參見同步資料表

五、安裝並使用SDK

Go SDK

FeatureStore Go SDK已開源,具體請參見aliyun-pai-featurestore-go-sdk

  1. 安裝

    執行如下代碼安裝FeatureStore Go SDK。

    go get github.com/aliyun/aliyun-pai-featurestore-go-sdk/v2
  2. 使用方式

    1. 執行如下命令,初始化Client。

      accessId := os.Getenv("AccessId") 
      accessKey := os.Getenv("AccessKey") 
      regionId := "cn-hangzhou" projectName := "fs_test_ots" 
      
      client, err := NewFeatureStoreClient(regionId, accessId, accessKey, projectName)
      說明

      由於SDK是直連線上資料來源,用戶端需要在VPC環境運行。例如Hologres和GraphCompute需要在指定的VPC才能串連。

    2. 擷取FeatureView的特徵資料。

      // get project by name project, err := client.GetProject("fs_test_ots") 
      if err != nil {     
      	// t.Fatal(err) 
      } 
      // get featureview by name 
      user_feature_view := project.GetFeatureView("user_fea") 
      if user_feature_view == nil {     
      	// t.Fatal("feature view not exist") 
      } 
      
      // get online features 
      features, err := user_feature_view.GetOnlineFeatures([]interface{}{"100043186", "100060369"}, []string{"*"}, nil)

      其中,[]string{"*"} 代表擷取FeatureView下的所有特徵, 也可以指定部分特徵名稱。

      返回資料樣本如下:

      [     
      {         
      "city":"合肥市",    "follow_cnt":1,         "gender":"male",         "user_id":"100043186"    
       },     {                     
       "city":"",         "follow_cnt":5,         "gender":"male",         "user_id":"100060369"     
      } 
      ]
    3. 擷取ModelFeature裡的特徵資料。

      ModelFeature可以關聯多個FeatureEntity,可以設定多個join_id,然後特徵統一返回。

      樣本中有兩個join_iduser_iditem_id。擷取特徵的時候需要設定相同的ID數量。

      // get project by name project, err := client.GetProject("fs_test_ots") 
      if err != nil {     
      	// t.Fatal(err) 
      }
      
      // get ModelFeature by name 
      model_feature := project.GetModelFeature("rank") 
      if model_feature == nil {     
      	// t.Fatal("model feature not exist") 
      } 
      
      // get online features 
      features, err := model_feature.GetOnlineFeatures(map[string][]interface{}{"user_id": {"100000676", "100004208"}, "item_id":{"238038872", "264025480"}} )

      返回資料樣本如下:

      [     
      {         
      "age":26,         "author":100015828,         "category":"14",         "city":"瀋陽市",         "duration":63,         "gender":"male",         "item_id":"238038872",         "user_id":"100000676"    
       },     {         
      "age":23,         "author":100015828,         "category":"15",         "city":"西安市",         "duration":22,         "gender":"male",         "item_id":"264025480",         "user_id":"100004208"    
       }
       ]
      
      

      也可以指定某個FeatureEntity,將FeatureEntity對應的特徵一起返回。

      返回資料樣本如下:

      [    
       {         
      "age":26,         "city":"瀋陽市",         "gender":"male",         "user_id":"100000676"    
       },     {        
       "age":23,         "city":"西安市",         "gender":"male",         "user_id":"100004208"    
       } 
      ]

Java SDK

FeatureStore Java SDK已開源,具體請參見aliyun-pai-featurestore-java-sdk

本文以Hologres資料來源為例進行說明。

  1. 執行如下代碼,載入環境變數並初始化服務。

    public static String accessId = "";
    public static String accessKey = "";
    #host具體根據所在地區配置
    public static String host = "";
    #擷取本地配置的環境變數中配置好的accessId、accessKey
    static {
        accessId = System.getenv("ACCESS_KEY_ID");
        accessKey = System.getenv("ACCESS_KEY_SECRET");
    }
  2. 準備配置類(配置regionIdaccessIdaccessKey以及專案名稱)。

    Configuration cf = new Configuration("cn-hangzhou",Constants.accessId,Constants.accessKey,"ele28");
    cf.setDomain(Constants.host);//注意:預設vpc環境
  3. 初始化用戶端。

    ApiClient apiClient = new ApiClient(cf);
    #FS用戶端
    FeatureStoreClient featureStoreClient = new FeatureStoreClient(apiClient);
  4. 擷取專案(此處以專案名稱為ele28為例進行說明)。

    Project project=featureStoreClient.getProject("ele28");
    if(project==null){
        throw new RuntimeException("Project not found");
    }
  5. 擷取專案的特徵視圖(此處以特徵視圖名稱為mc_test為例進行說明)。

    FeatureView featureView=project.getFeatureView("mc_test");
    if (featureView == null) {
        throw  new RuntimeException("FeatureView not found");
    }
  6. 根據特徵視圖擷取線上特徵資料。

    Map<String,String> m1=new HashMap<>();
    m1.put("gender","gender1"); //起別名                                                                                                                                                                                                 user_id='100027781'(FS_INT64) age='28'(FS_INT64) city='null'(FS_STRING) item_cnt='0'(FS_INT64) follow_cnt='0'(FS_INT64) follower_cnt='2'(FS_INT64) register_time='1697641608'(FS_INT64) tags='0'(FS_STRING) gender1='female'(FS_STRING) ---------------

    擷取線上特徵(String[]{"*"}擷取所有屬性資訊,也可以傳入部分屬性,輸出僅見部分資訊的資料)。

    FeatureResult featureResult1=featureView.getOnlineFeatures(new String[]{"100017768","100027781","100072534"},new String[]{"*"},m1);

    輸出特徵資訊。

    while(featureResult1.next()){
        System.out.println("---------------");
        #特徵名
        for(String m:featureResult1.getFeatureFields()){
            System.out.print(String.format("%s=%s(%s) ",m,featureResult1.getObject(m),featureResult1.getType(m)));
        }
        System.out.println("---------------");
    }   

    返回資料如下。

    ---------------
    user_id='100017768'(FS_INT64)  age='28'(FS_INT64)  city='東莞市'(FS_STRING) item_cnt='1'(FS_INT64)  follow_cnt='1'(FS_INT64)  follower_cnt='0'(FS_INT64) register_time='1697202320'(FS_INT64)  tags='1,2'(FS_STRING)  gender1='female'(FS_STRING) 
    ---------------
  7. 擷取模型。

    Model model=project.getModelFeature("model_t1");
    if(model==null){
        throw new RuntimeException("Model not found");
    }
    1. 擷取模型特徵裡的資料。

      兩個join_id執行個體(user_id,item_id),傳入的值個數需對應(此處只傳入了一個值)。

      Map<String, List<String>> m2=new HashMap<>(); 
      m2.put("user_id",Arrays.asList("101683057"));
      m2.put("item_id",Arrays.asList("203665415"));
    2. 擷取模型特徵有關於user特徵實體的所有特徵資料。

      FeatureResult featureResult2 = model.getOnlineFeaturesWithEntity(m2,"user");

      返回資料如下。

      ---------------
      user_id='101683057' age='28' city='深圳市' follower_cnt='234' follow_cnt='0' gender='male' item_cnt='0' register_time='1696407642' tags='2' item_id='203665415' author='132920407' category='14' click_count='0' duration='18.0' praise_count='10' pub_time='1698218997' title='#成語故事' 
      ---------------

Cpp SDK

目前FeatureStore Cpp SDK整合在EasyRec Processor(推薦打分服務) 中,針對特徵提取、緩衝管理及讀取操作進行了專項最佳化,為大規模推薦情境提供高效能、低延遲的解決方案。

  • 記憶體佔用:在面臨複雜且規模龐大的特徵資料時,記憶體資源消耗得到大幅削減,尤其在高特徵負載情況下,節省效果更為明顯。

  • 拉取特徵時間:通過將線上儲存(如Hologres、GraphCompute等)的拉取流程改為直接從 MaxCompute拉取至EAS緩衝,特徵載入時間顯著縮短。同時,MaxCompute穩定性和擴充性更好,有效減輕了擴容對線上儲存的壓力。

  • 模型打分耗時:使用該SDK後,模型打分效能指標tp100得到進一步改善,回應時間更穩定,逾時請求顯著減少,整體提升了建議服務的可靠性和使用者體驗。

相關文檔