全部產品
Search
文件中心

Artificial Intelligence Recommendation:Recommendation Engine介面調用

更新時間:Jan 29, 2026

服務發布之後的介面調用詳情

介面說明

POST /api/rec/feed

請求參數

參數名稱

參數說明

類型

是否必須

用例

uid

使用者ID。

string

"1000079"

size

推薦返回的物品數量。

integer

10

scene_id

推薦情境ID,用於區分不同推薦情境的請求。

String

home_feed

features

上下文特徵。

json map

{"age":20, "sex":"male"}

complex_type_features

複雜類型的上下文特徵,如果需要有類型的資訊請求模型服務,需要設定此值。

json array

[{"name":"age", "type":"int", "values":20}, {"name":"sex", "values":"male", "type":"string"}]

item_id

相似性推薦傳入的物品ID。

string

248791390

item_list

自訂的召回傳入列表。

json array

[{"item_id":"1111", "score":1},{"item_id":"222", "score":0.95}]

debug

debug 時使用,可以列印更多的日誌。例如會在控制台列印user和item的詳情;如果啟用了流量調控,會在返回的結果中列印流量調控的過程以及一些計算參數的變化

bool

true

request_id

請求唯一標識ID,此參數為空白時,PAI-Rec 引擎會自動產生,如果使用者傳入,使用參數值當成請求的ID。

string

"c46c3f5e-6b32-4b5c-8aac-59a319941248"

item_list

當有一批召回的資料,希望通過介面傳遞進來,可以賦值給 item_list。 item_list 是一個數組,每個 item 是 map object ,item 中必須有 item_id 欄位,表示物品的ID。其餘都是可選的。 item 中如果包含 score 欄位,會當成召回得分處理。其餘欄位當成 item 屬性進行處理。

complex_type_features

複雜類型的上下文特徵需要數組傳遞過來,每個元素包含的內容如下:

名稱

說明

用例

name

上下文特徵名稱

age

type

上下文特徵類型

int

values

上下文特徵值,這裡可以設定多種類型,支援具體值,數組, map 等

20

使用樣本:

  1. 傳遞單個值,[{"name":"age", "type":"int", "values":20}, {"name":"sex", "values":"male", "type":"string"}]

  2. 傳遞數組[{"name":"list_features", "type":"list<int>", "values":[1,2,3]}]

  3. 傳遞map[{"name":"map_features", "type":"map<int,int>", "values":{"1":10,"2":20,"3":30}}], 或者[{"name":"map_features", "type":"map<int,int>", "values":{"1":"10","2":"20","3":"30"}}],

type 支援的類型包括int,int64,float,double,string,list<int>,list<int64>,list<float>,list<double>,list<string>,map<int,int>,map<int,int64>,map<int,float>,map<int,double>,map<int,string>,map<string,int>,map<string,int64>,map<string,float>,map<string,double>,map<string,string>,map<int64,int>,map<int64,int64>,map<int64,float>,map<int64,double>,map<int64,string>

註:傳遞上下文中, complex_type_features 和 features 可以同時使用。

介面返回

名稱

說明

類型

樣本

code

介面返回業務碼

int

200

msg

商務資訊

string

success

request_id

請求的唯一標識

string

e332fe9c-7d99-45a8-a047-bc7ec33d07f6

size

返回的推薦條目數量

int

10

experiment_id

實驗ID 標識, 沒有對接 AB 實驗,返回為空白

string

ER2_L1#EG1#E2

items

返回推薦條目的列表

json array

[{"item_id":"248791390","score":0.9991594902203332,"retrieve_id":"mock_recall"}]

items 條目具體說明如下:

名稱

說明

類型

樣本

item_id

推薦物品ID

string

3v5RE7417j7R

retrieve_id

召回源ID標識

string

u2i_recall

score

推薦得分

float

0.45

錯誤碼說明

錯誤碼

說明

msg

200

介面正常

success

299

返回的數量不足

items size not enough

400

參數錯誤,不同的情況, msg 說明不同

uid not empty 或者nexpected end of JSON input 等

500

伺服器錯誤, 以 HTTP 錯誤碼形式返回

配置及調用樣本

這裡我們用上下文召回舉例,上下文召回是通過介面傳入召回列表,引擎配置如下,情境這裡我們用home_feed舉例:

{
  "RunMode": "product",
  "ListenConf": {
    "HttpAddr": "",
    "HttpPort": 8000
  },
  "SortNames": {
    "default": ["ItemRankScore"]
  },
  "FilterNames": {
    "default": ["UniqueFilter"]
  },
  "SceneConfs": {
    "home_feed": {
      "default": {
        "RecallNames": ["ContextItemRecall"]
      }
    }
  }
}

請求body為

{
  "uid":"13579",
  "size":2,
  "scene_id":"home_feed",
  "item_list":[{"item_id":"1111", "score":1},{"item_id":"222", "score":0.95}]
}

介面調用

通過curl命令調用

如果需要本地通過curl命令請求引擎服務,需要先在EAS控制台找到對應服務的請求地址和token,如下圖:

在服務詳情中點擊查看調用資訊,即可彈出調用資訊。

image

重要

注意,如果是本地調用,需要使用公網地址。公網地址+/api/rec/feed,才是完整的請求地址。

curl -X 'POST' -v \
'http://12*****.vpc.hangzhou.pai-eas.aliyuncs.com/api/predict/test/api/rec/feed' \
-H 'Authorization:YmRjZThkM2Z*****************TU5Mw==' \
-d '{
"uid":"13579",
"size":2,
"scene_id":"home_feed",
"item_list":[{"item_id":"1111", "score":1},{"item_id":"222", "score":0.95}]
}'

返回資料

{
  "code":200,
  "msg":"success",
  "request_id":"e332fe9c-7d99-45a8-a047-bc7ec33d07f6",
  "size":2,
  "experiment_id":"",
  "items":[
    {
      "item_id":"1111",
      "score":0.9991594902203332,
      "retrieve_id":"ContextItemRecall"
    },
    ...
  ]
}

通過PAI-Rec診斷工具調用

如果您是通過PAI-Rec控制台服務管理部署的服務,可以直接使用診斷工具來調試推薦結果,如下圖:

image

您需要選擇對應服務、環境,路由資訊選擇/api/rec/feed

物品表:如果您有item的詳情表,這裡也可以選擇,會將item的詳情和返回的資料進行關聯;

請求資料:會展示您最近一段時間的請求參數,也可以手動填寫。

如下圖所示,選擇和填寫好相關參數,點擊診斷即可獲得推薦結果。

image