召回配置項對應配置總覽中的RecallConfs。
如何配置
PAI-Rec引擎已經內建了多個召回模板,包括協同過濾(UserCollaborativeFilterRecall),向量召回(HologresVectorRecall),U2I 召回(UserCustomRecall)等等,並且支援 Hologres、PAI-FeatureStore、TableStore(OTS)等多個資料來源。
召回公用配置一覽
每種召回配置,都會用到公用配置中的一部分,在此統一解釋,單獨的召回配置中則不再贅述。
配置樣本:
{
"RecallConfs": [
{
"Name": "collaborative_filter",
"RecallType": "UserCollaborativeFilterRecall",
"RecallCount": 1000,
"RecallAlgo": "",
"ItemType": "",
"CacheAdapter": "",
"CacheConfig": "",
"CachePrefix": "",
"CacheTime": 0
}
]
}欄位 | 類型 | 是否必填 | 描述 |
Name | string | 是 | 召回的自訂名稱,可以在SceneConfs中引用。 |
RecallType | string | 是 | 引擎內建召回類型,枚舉值,目前支援:
|
RecallCount | string | 是 | 召回數量 |
RecallAlgo | string | 否 | 調用的向量模型名稱,需要先在AlgoConfs裡配置,只在即時向量召回中使用。 |
ItemType | string | 否 | 推薦物品類型。 |
CacheAdapter | string | 否 | 這裡可以將召回的結果進行緩衝,枚舉值:
|
CacheConfig | string | 否 | 緩衝的一些配置。 當使用Redis緩衝時,參考配置:"{\"host\":\"xxx.redis.rds.aliyuncs.com\", \"port\":6379,\"maxIdle\":10, \"password\":\"xxxx\"}" 當使用localCache時,參考配置 "{\"defaultExpiration\":600, \"cleanupInterval\":600}"。 |
CachePrefix | string | 否 | 這裡可以對當前召回結果的key加一個首碼。 當選擇使用緩衝時,為必填項。為了避免不同召回之間的緩衝互相影響。如 "group_hot_",代表組熱門召回的某個user的緩衝結果。 |
CacheTime | string | 否 | 緩衝時間長度,預設1800秒。 |
協同過濾(UserCollaborativeFilterRecall)
Hologres
協同過濾需要有兩張表,一張u2i表,根據user_id擷取item列表,一張i2i表,擷取相似的item,這兩張表的 schema是固定格式的。
除了通過 i2i 表擷取相似的 item(下文稱 u2i2i),還可以通過 i2x 和 x2i 兩張表間接地擷取相似 item(下文稱 u2i2x2i),x 可以是類目、品牌、城市等屬性,先擷取 item 的屬性x(如下文中的category欄位),然後從x2i表中擷取相應x取值下的熱門物品作為推薦結果。 。
u2i 表
表欄位 | 類型 | 描述 |
user_id | string | 使用者id,保持其唯一性 |
item_ids | string | 使用者瀏覽的item id列表,支援格式: item_id1,item_id2,item_id3..... 或者 item_id1:score1,item_id2:score2,item_id3:score3...... |
i2i 表(僅 u2i2i 需要)
表欄位 | 類型 | 描述 |
item_id | string | item id,保持其唯一性 |
similar_item_ids | string | 和item_id相似的item列表,支援格式:item_id1:score1,item_id2:score2,item_id3:score3...... |
i2x 表(僅 u2i2x2i 需要)
item_id | string | item id,保持其唯一性 |
x | string | item的屬性,列名可以自訂,在引擎配置中指定實際列名。 |
x2i 表(僅 u2i2x2i 需要)
x | string | item的屬性,列名可以自訂,在引擎配置中指定實際列名。 |
item_id | string | item id,多值用 ”,“分隔 |
u2i2i 配置樣本:
{
"RecallConfs": [
{
"Name": "collaborative_filter",
"RecallType": "UserCollaborativeFilterRecall",
"RecallCount": 1000,
"UserCollaborativeDaoConf": {
"AdapterType": "hologres",
"HologresName": "holo_info",
"User2ItemTable": "u2i_table",
"Item2ItemTable": "i2i_table",
"Normalization": "on"
}
}
]
}u2i2x2i 配置樣本:
{
"RecallConfs": [
{
"Name": "collaborative_filter",
"RecallType": "UserCollaborativeFilterRecall",
"RecallCount": 1000,
"UserCollaborativeDaoConf": {
"AdapterType": "hologres",
"HologresName": "holo_info",
"User2ItemTable": "u2i_table",
"Item2XTable": "i2x_table",
"X2ItemTable": "x2i_table",
"XKey": "category",
"XDelimiter": ",",
"Normalization": "on"
}
}
]
}UserCollaborativeDaoConfig:
欄位 | 類型 | 是否必填 | 描述 |
AdapterType | string | 是 | 固定值 hologres |
HologresName | string | 是 | 在資料來源配置(HologresConfs)中配置好的holo的自訂名稱,如資料來源配置中的holo_info |
User2ItemTable | string | 是 | u2i表 |
Item2ItemTable | string | 否 | i2i表,使用 u2i2i 方式時必填 |
Item2XTable | string | 否 | i2x表,使用 u2i2x2i 方式時必填 |
X2ItemTable | string | 否 | x2i 表,使用 u2i2x2i 方式時必填 |
XKey | string | 否 | x 鍵,值為 i2x 表和 x2i 表 x 列名,使用 u2i2x2i 方式時必填 |
XDelimiter | string | 否 | x 值分隔字元,預設不對 x 值分割 |
Normalization | string | 否 | 枚舉值:on/off。是否對召回的item進行歸一化,預設為"on" |
PAI-FeatureStore
協同過濾需要有兩張表,一張u2i表,根據user_id擷取item列表,一張i2i表,擷取相似的item,這兩張表的 schema是固定格式的。
兩種表的資料是在MaxCompute裡產生的。需要通過離線的FeatureView註冊到 FeatureStore上。MaxCompute的表資料schema參考如下。
u2i 表
表欄位 | 類型 | 描述 |
user_id | string | 使用者id,保持其唯一性 |
item_ids | string | 使用者瀏覽的item id列表,支援格式: item_id1,item_id2,item_id3..... 或者 item_id1:score1,item_id2:score2,item_id3:score3...... |
ds | string | MaxCompute表分區欄位 |
註冊到FeatureStore 參考如下:
i2i 表
表欄位 | 類型 | 描述 |
item_id | string | item id,保持其唯一性 |
similar_item_ids | string | 和item_id相似的item列表,支援格式:item_id1:score1,item_id2:score2,item_id3:score3...... |
dt | string | MaxCompute表分區欄位 |
配置樣本:
{
"RecallConfs": [
{
"Name": "collaborative_filter",
"RecallType": "UserCollaborativeFilterRecall",
"RecallCount": 1000,
"UserCollaborativeDaoConf": {
"AdapterType": "featurestore",
"FeatureStoreName": "fs_pairec",
"User2ItemFeatureViewName": "u2i_recall",
"Item2ItemFeatureViewName": "i2i_collaborative",
"Normalization": "on"
}
}
]
}UserCollaborativeDaoConfig:
欄位 | 類型 | 是否必填 | 描述 |
AdapterType | string | 是 | 固定值 featurestore |
FeatureStoreName | string | 是 | 在資料來源配置(FeatureStoreConfs)中配置好的featurestore的自訂名稱,如資料來源配置中的fs_pairec |
User2ItemFeatureViewName | string | 是 | u2i表對應的視圖名稱 |
Item2ItemFeatureViewName | string | 是 | i2i表對應的視圖名稱 |
Normalization | string | 否 | 枚舉值:on/off。是否對召回的item進行歸一化,預設為"on" |
TableStore(OTS)
協同過濾需要有兩張表,一張u2i表,根據user_id擷取item列表,一張i2i表,擷取相似的item,這兩張表的 schema是固定格式的。
u2i 表
表欄位 | 類型 | 描述 |
user_id | string | 使用者id,保持其唯一性 |
item_ids | string | 使用者瀏覽的item id列表,支援格式: item_id1,item_id2,item_id3..... 或者 item_id1:score1,item_id2:score2,item_id3:score3...... |
i2i 表
表欄位 | 類型 | 描述 |
item_id | string | item id,保持其唯一性 |
similar_item_ids | string | 和item_id相似的item列表,支援格式:item_id1:score1,item_id2:score2,item_id3:score3...... |
{
"RecallConfs": [
{
"Name": "collaborative_filter",
"RecallType": "UserCollaborativeFilterRecall",
"RecallCount": 1000,
"UserCollaborativeDaoConf": {
"AdapterType": "tablestore",
"TableStoreName": "tablestore_info",
"User2ItemTable": "u2i_table",
"Item2ItemTable": "i2i_table",
"Normalization": "on"
}
}
]
}欄位 | 類型 | 是否必填 | 描述 |
AdapterType | string | 是 | 固定值 tablestore |
TableStoreName | string | 是 | 在資料來源配置(TableStoreConfs)中配置好的tablestore的自訂名稱,如資料來源配置中的tablestore_info |
User2ItemTable | string | 是 | u2i表 |
Item2ItemTable | string | 是 | i2i表 |
Normalization | string | 否 | 枚舉值:on/off。是否對召回的item進行歸一化,預設為"on" |
Redis
Redis進行collaborative_filter流程比較特殊,單獨說明。 實際上也是分兩步:
根據RedisPrefix + uid構造key , 查詢U2I列表, 是個string, 支援格式: item_id1,item_id2,item_id3..... 或者 item_id1:score1,item_id2:score2,item_id3:score3......
然後查詢I2I列表, 根據上步查詢到的多個item_id,使用MGET進行查詢。 I2I的資料也是string , 格式如下:item_id1:score1,item_id2:score2,item_id3:score3......
配置樣本:
{
"RecallConfs": [
{
"Name": "collaborative_filter",
"RecallType": "UserCollaborativeFilterRecall",
"RecallCount": 1000,
"UserCollaborativeDaoConf": {
"AdapterType": "redis",
"RedisName": "redis_info",
"RedisPrefix": "cr_",
"Normalization": "on"
}
}
]
}欄位 | 類型 | 是否必填 | 描述 |
AdapterType | string | 是 | 固定值 redis |
RedisName | string | 是 | 在資料來源配置(RedisConfs)中配置好的Redis的自訂名稱,如資料來源配置中的redis_info |
RedisPrefix | string | 否 | U2I資料的首碼,key通過RedisPrefix + uid進行構造 |
僅支援Redis進行快取資料。
即時 U2I2I(RealTimeU2IRecall)
Hologres
擷取資料的思路和協同過濾中的是一樣的,只不過U2I的資料擷取是通過user歷史行為表Realtime Compute的。
user歷史行為表是根據即時日誌來同步更新的,這樣的召回是即時的召回。
和協同過濾一樣,也支援 u2i2x2i,先擷取 item 的 x 屬性,再通過相同 x 屬性的 item。
user歷史行為表
欄位 | 類型 | 描述 |
user_id | string | 使用者id |
item_id | string | 使用者瀏覽的item id |
event | string | 事件名稱 |
play_time | float | 事件的耗時,比如視頻觀看的時間長度,不存在可以設定為0 |
timestamp | int | 事件發生的時間戳記,單位為秒 |
i2i 表(僅 u2i2i 需要)
表欄位 | 類型 | 描述 |
item_id | string | item id,保持其唯一性 |
similar_item_ids | string | 和item_id相似的item列表,支援格式:item_id1:score1,item_id2:score2,item_id3:score3...... |
i2x 表(僅 u2i2x2i 需要)
item_id | string | item id,保持其唯一性 |
x | string | item的屬性,列名可以自訂,在引擎配置中指定實際列名。 |
x2i 表(僅 u2i2x2i 需要)
x | string | item的屬性,列名可以自訂,在引擎配置中指定實際列名。 |
item_id | string | item id,多值用 ”,“分隔 |
行為表建表語句:
BEGIN;
CREATE TABLE "sv_rec"."user_behavior_seq" (
"user_id" text NOT NULL,
"item_id" text NOT NULL,
"event" text NOT NULL,
"play_time" float8 NULL,
"timestamp" int8 NOT NULL
);
CALL SET_TABLE_PROPERTY('"sv_rec"."user_behavior_seq"', 'orientation', 'column');
call set_table_property('table_name', 'distribution_key', '"user_id"');
CALL SET_TABLE_PROPERTY('"sv_rec"."user_behavior_seq"', 'clustering_key', '"user_id:asc","timestamp:desc"');
CALL SET_TABLE_PROPERTY('"sv_rec"."user_behavior_seq"', 'bitmap_columns', '"user_id","event"');
CALL SET_TABLE_PROPERTY('"sv_rec"."user_behavior_seq"', 'dictionary_encoding_columns', '"user_id:auto","item_id:auto","event"');
CALL SET_TABLE_PROPERTY('"sv_rec"."user_behavior_seq"', 'time_to_live_in_seconds', '2592000');
comment on table "sv_rec"."user_behavior_seq" is '使用者即時行為序列';
comment on column "sv_rec"."user_behavior_seq"."user_id" is '使用者id';
comment on column "sv_rec"."user_behavior_seq"."item_id" is 'item id';
comment on column "sv_rec"."user_behavior_seq"."event" is '事件類型';
comment on column "sv_rec"."user_behavior_seq"."play_time" is '閱讀時間長度,播放時間長度';
comment on column "sv_rec"."user_behavior_seq"."timestamp" is '時間戳記,單位秒';
COMMIT;配置樣本:
{
"RecallConfs": [
{
"Name": "RealTimeEtrecRecall",
"RecallType": "RealTimeU2IRecall",
"RecallCount": 200,
"RealTimeUser2ItemDaoConf": {
"UserTriggerDaoConf": {
"AdapterType": "hologres",
"HologresName": "holo_info",
"HologresTableName": "user_behavior_table",
"WhereClause": "event='xxx'",
"Limit": 200,
"EventPlayTime": "playback:5000;playvslide:5000",
"EventWeight": "playback:1;playvslide:2",
"WeightExpression": "exp((-0.2)*((currentTime-eventTime)/3600/24))",
"WeightMode": "sum",
"NoUsePlayTimeField": false
},
"Item2ItemTable": "i2i_table",
"SimilarItemIdField": "similar_item_ids"
}
}
]
}u2i2x2i 配置樣本:
{
"RecallConfs": [
{
"Name": "RealTimeU2I2X2IRecall",
"RecallType": "RealTimeU2IRecall",
"RecallCount": 200,
"RealTimeUser2ItemDaoConf": {
"UserTriggerDaoConf": {
"AdapterType": "hologres",
"HologresName": "holo_info",
"HologresTableName": "user_behavior_table",
"WhereClause": "event='xxx'",
"Limit": 200,
"EventPlayTime": "playback:5000;playvslide:5000",
"EventWeight": "playback:1;playvslide:2",
"WeightExpression": "exp((-0.2)*((currentTime-eventTime)/3600/24))",
"WeightMode": "sum",
"NoUsePlayTimeField": false
},
"Item2XTable": "i2x_table",
"X2ItemTable": "x2i_table",
"XKey": "category",
"XDelimiter": ","
}
}
]
}RealTimeUser2ItemDaoConf:
欄位 | 類型 | 是否必填 | 描述 |
AdapterType | string | 是 | 固定值 hologres |
HologresName | string | 是 | 在資料來源配置(HologresConfs)中配置好的holo的自訂名稱,如資料來源配置中的holo_info |
HologresTableName | string | 是 | holo中user歷史行為表的表名 |
WhereClause | string | 否 | 過濾條件,相當於sql中的where條件 |
Limit | int | 否 | 查詢數量限制,相當於sql中的limit |
EventPlayTime | string | 否 | 事件播放時間的過濾。可以針對每個事件,進行過濾e_sv_func_svplayback:5000表示針對事件 e_sv_func_svplayback,play_time的值必須大於5000 , 不符合條件則被過濾掉。可以設定多個事件,以 ; 分隔 |
EventWeight | string | 否 | 事件的權重, 可以定義每個事件的權重, 不設定的話,預設值為1 |
WeightExpression | string | 否 | 權重運算式。 以時間衰減來計算事件的權重。currentTime代表當前的時間戳記,eventTime代錶行為表的裡timestamp |
WeightMode | string | 否 | 計算trigger權重的方式,取值為sum或者max 。 預設是sum |
NoUsePlayTimeField | bool | 否 | 如果不使用play_time欄位,可以設定為true |
Item2ItemTable | string | 否 | holo中的i2i表名稱,使用 u2i2i 方式時必填 |
SimilarItemIdField | string | 否 | holo中的i2i表中欄位名稱,預設值為 similar_item_ids |
Item2XTable | string | 否 | i2x表名,使用 u2i2x2i 方式時必填 |
X2ItemTable | string | 否 | x2i 表名,使用 u2i2x2i 方式時必填 |
XKey | string | 否 | x 鍵,值為 i2x 表和 x2i 表 x 列名,使用 u2i2x2i 方式時必填 |
XDelimiter | string | 否 | x 值分隔字元,預設不對 x 值分割 |
PAI-FeatureStore
擷取資料的思路和協同過濾中的是一樣的,只不過U2I的資料擷取是通過user歷史行為表Realtime Compute的。
user歷史行為表是根據即時日誌來同步更新的,這樣的召回是即時的召回。
在PAI-FeatureStore平台中,使用特徵視圖的行為序列類型可以儲存user歷史行為資料。
user歷史行為表
欄位 | 類型 | 描述 |
user_id | string | 使用者id |
item_id | string | 使用者瀏覽的item id |
event | string | 事件名稱 |
playtime | float | 事件的耗時,比如視頻觀看的時間長度,不存在可以設定為0 |
event_unix_time | int | 事件發生的時間戳記,單位為秒 |
i2i 表
表欄位 | 類型 | 描述 |
item_id | string | item id,保持其唯一性 |
similar_item_ids | string | 和item_id相似的item列表,支援格式:item_id1:score1,item_id2:score2,item_id3:score3...... |
配置樣本:
{
"RecallConfs": [
{
"Name": "realtimeu2i",
"RecallType": "RealTimeU2IRecall",
"RecallCount": 200,
"RealTimeUser2ItemDaoConf": {
"UserTriggerDaoConf": {
"AdapterType": "featurestore",
"FeatureStoreName": "fs_pairec",
"FeatureStoreViewName": "user_behavior_table",
"TriggerCount": 100,
"EventWeight": "click:1;order:1",
"WeightExpression": "exp((-0.2)*((currentTime-eventTime)/3600/24))",
"WeightMode": "sum",
"NoUsePlayTimeField": false,
"ItemIdFieldName": "item_id",
"EventFieldName": "event",
"PlayTimeFieldName": "playtime",
"TimestampFieldName": "event_unix_time"
},
"Item2ItemFeatureViewName": "i2i_collaborative",
"SimilarItemIdField": "similar_item_ids"
}
}
]
}RealTimeUser2ItemDaoConf:
欄位 | 類型 | 是否必填 | 描述 |
UserTriggerDaoConf | |||
| string | 是 | 固定值 featurestore |
| string | 是 | 在資料來源配置(FeatureStoreConfs)中配置好的featurestore的自訂名稱,如資料來源配置中的fs_pairec |
| string | 是 | FeatureStore中user歷史行為序列視圖名稱 |
| int | 是 | user行為trigger的數量 |
| string | 否 | 事件播放時間的過濾。可以針對每個事件,進行過濾e_sv_func_svplayback:5000表示針對事件 e_sv_func_svplayback,play_time的值必須大於5000 , 不符合條件則被過濾掉。可以設定多個事件,以 ; 分隔 |
| string | 是 | 事件的權重, 可以定義每個事件的權重, 不設定的話,預設值為1。多個event配置以 |
| string | 是 | 權重運算式。 以時間衰減來計算事件的權重。currentTime代表當前的時間戳記,eventTime代錶行為表的裡timestamp |
| string | 否 | 計算trigger權重的方式,取值為sum或者max 。 預設是sum |
| bool | 否 | 如果不使用play_time欄位,可以設定為true |
| string | 否 | user行為序列的item_id的欄位名稱,預設值為 item_id |
| string | 否 | user行為序列的事件的欄位名稱,預設值為 event |
| string | 否 | user行為序列的播放時間的欄位名稱,預設值為 play_time |
| string | 否 | user行為序列的時間戳記的欄位名稱,預設值為 timestamp |
Item2ItemFeatureViewName | string | 否 | FeatureStore中i2i的表的視圖名稱,使用 u2i2i 方式時必填 |
SimilarItemIdField | string | 否 | FeatureStore中i2i的表的欄位名稱,預設值為 similar_item_ids |
MergeMode | string | 否 | 控制triggerId召回的item如何合并。預設情況下,召回的item合并到一起排序去重。可選值:snake 可以輪詢triggerId召回的item列表合并到一起 |
I2ICacheSize | int | 否 | 大於0的情況下開啟cache。以triggerId 為key,從i2i表裡召回的item列表作為value 。 |
I2ICacheTime | int | 否 | 開啟cache的情況下,控制緩衝時間。單位秒。 |
向量召回(HologresVectorRecall)
目前向量召回只能使用hologres資料來源,向量資料都存在hologres表中
配置樣本:
{
"RecallConfs": [
{
"Name": "vector_recall",
"RecallType": "HologresVectorRecall",
"RecallCount": 100,
"VectorDaoConf": {
"AdapterType": "hologres",
"HologresName": "holo_info",
"HologresTableName": "user_embedding_table",
"KeyField": "user_id",
"EmbeddingField": "emb"
},
"HologresVectorConf": {
"VectorTable": "item_embedding_table",
"VectorEmbeddingField": "emb",
"VectorKeyField": "item_id"
}
}
]
}VectorDaoConf:
欄位 | 類型 | 是否必填 | 描述 |
AdapterType | string | 是 | 資料來源的類型,取值hologres |
HologresName | string | 是 | 在資料來源配置(HologresConfs)中配置好的holo的自訂名稱,如資料來源配置中的holo_info |
HologresTableName | string | 是 | holo中對應的向量表名稱 |
KeyField | string | 是 | 向量表中的主鍵欄位 |
EmbeddingField | string | 是 | 向量表中儲存向量的欄位 |
HologresVectorConf:
欄位 | 類型 | 是否必填 | 描述 |
VectorTable | string | 是 | holo中item向量表 |
VectorEmbeddingField | string | 是 | item向量表中的主鍵欄位 |
VectorKeyField | string | 是 | item向量表中儲存向量的欄位 |
VectorDaoConf裡記錄的是user向量資訊,表的定義如下
BEGIN;
CREATE TABLE "public"."graphsage_user_embedding" (
"user_id" text NOT NULL,
"emb" float4[] NOT NULL,
"dt" text,
PRIMARY KEY ("user_id")
);
CALL SET_TABLE_PROPERTY('"public"."graphsage_user_embedding"', 'orientation', 'row');
CALL SET_TABLE_PROPERTY('"public"."graphsage_user_embedding"', 'clustering_key', '"user_id:asc"');
CALL SET_TABLE_PROPERTY('"public"."graphsage_user_embedding"', 'time_to_live_in_seconds', '3153600000');
comment on column "public"."graphsage_user_embedding"."user_id" is '使用者ID';
comment on column "public"."graphsage_user_embedding"."emb" is '使用者特徵向量';
comment on column "public"."graphsage_user_embedding"."dt" is '日期 yyyyMMdd';
COMMIT;HologresVectorConf記錄的是item向量, 表定義如下
BEGIN;
CREATE TABLE "public"."graphsage_item_embedding" (
"item_id" text NOT NULL,
"emb" float4[] NOT NULL,
PRIMARY KEY ("item_id")
);
CALL SET_TABLE_PROPERTY('"public"."graphsage_item_embedding"', 'orientation', 'column');
CALL SET_TABLE_PROPERTY('"public"."graphsage_item_embedding"', 'bitmap_columns', '"item_id"');
CALL SET_TABLE_PROPERTY('"public"."graphsage_item_embedding"', 'time_to_live_in_seconds', '3153600000');
comment on column "public"."graphsage_item_embedding"."item_id" is '物品ID';
comment on column "public"."graphsage_item_embedding"."emb" is '物品特徵向量';
COMMIT;即時向量召回(OnlineHologresVectorRecall)
即時向量召回和向量召回的實現方式是一致的,也是基於hologres的表資料,不同的是,user向量不是從表裡擷取的,而是即時通過模型擷取到的,然後去item向量表查資料。實現思路基本上分為三步:
擷取user相關特徵,user特徵可以從資料表裡查詢
調用向量模型,擷取user向量。在我們的支援中,模型是部署在EAS上的
和向量召回一樣,通過item向量表進行查詢
配置樣本:
{
"RecallConfs": [
{
"Name": "online_vector_recall",
"RecallType": "OnlineHologresVectorRecall",
"RecallCount": 500,
"UserFeatureConfs": [
{
"FeatureDaoConf": {
"AdapterType": "hologres",
"HologresName": "holo_info",
"FeatureKey": "user:uid",
"UserFeatureKeyName": "userid",
"HologresTableName": "user_all_feature_table",
"UserSelectFields": "*",
"FeatureStore": "user"
},
"Features": []
}
],
"RecallAlgo": "sv_v2_mind",
"HologresVectorConf": {
"HologresName": "holo_info",
"VectorTable": "item_embedding_table",
"VectorEmbeddingField": "item_emb",
"VectorKeyField": "item_id"
}
}
]
}欄位 | 類型 | 是否必填 | 描述 |
Name | string | 是 | 自訂召回名稱 |
RecallType | string | 是 | 召回類型,固定值OnlineHologresVectorRecall |
RecallCount | int | 是 | 召回數量 |
RecallAlgo | string | 是 | 調用的向量模型名稱,需要在AlgoConfs裡配置,具體配置參考精排配置。 |
UserFeatureConfs:
欄位 | 類型 | 是否必填 | 描述 |
AdapterType | string | 是 | 資料來源的類型,取值hologres |
HologresName | string | 是 | 在資料來源配置(HologresConfs)中配置好的holo的自訂名稱,如資料來源配置中的holo_info |
FeatureKey | string | 是 | 這裡為引擎中user_id的來源,user:uid代表user中的uid特徵 |
UserFeatureKeyName | string | 是 | user特徵表中的主鍵欄位 |
HologresTableName | string | 是 | user特徵表 |
UserSelectFields | string | 是 | 要選擇哪些特徵,支援"*"的寫法,也可以 "f1,f2...."逗號分隔的寫法 |
FeatureStore | string | 是 | 在引擎中特徵儲存的位置,枚舉值:user/item |
HologresVectorConf:
欄位 | 類型 | 是否必填 | 描述 |
HologresName | string | 是 | 在資料來源配置(HologresConfs)中配置好的holo的自訂名稱,如資料來源配置中的holo_info |
VectorTable | string | 是 | holo中item向量表的表名 |
VectorEmbeddingField | string | 是 | item向量表中儲存向量的欄位 |
VectorKeyField | string | 是 | item向量表中的主鍵欄位 |
模型sv_v2_mind在AlgoConfs裡定義如下
{
"AlgoConfs": [
{
"Name": "sv_v2_mind",
"Type": "EAS",
"EasConf": {
"Processor": "EasyRec",
"Timeout": 100,
"ResponseFuncName": "easyrecUserEmbResponseFunc",
"Url": "http://xxx.vpc.cn-beijing.pai-eas.aliyuncs.com/api/predict/sv_v2_mind",
"Auth": "xxx"
}
}
]
}和排序模型的配置是一樣的,不同點是ResponseFuncName需要固定為easyrecUserEmbResponseFunc
U2I召回(UserCustomRecall)
Hologres
根據user id來找到對應的item列表。這裡的表定義是約定好的。
u2i 表
欄位 | 類型 | 描述 |
user_id | string | 使用者id |
item_ids | string | item id列表,支援格式:item_id1,item_id2,item_id3..... 或 item_id1:recall_id1,item_id2:recall_id2..... 或 item_id1:recall_id1:score1,item_id2:recall_id2:score2..... |
配置樣本:
{
"RecallConfs": [
{
"Name": "user2item_recall",
"RecallType": "UserCustomRecall",
"RecallCount": 500,
"DaoConf": {
"AdapterType": "hologres",
"HologresName": "holo_info",
"HologresTableName": "user_item_table"
}
}
]
}欄位 | 類型 | 是否必填 | 描述 |
Name | string | 是 | 自訂召回名稱 |
RecallType | string | 是 | 召回類型,固定值UserCustomRecall |
RecallCount | int | 是 | 召回數量 |
DaoConf | json object | 是 | Dao定義 |
AdapterType | string | 是 | 資料來源類型,取值hologres |
HologresName | string | 在資料來源配置(HologresConfs)中配置好的holo的自訂名稱,如資料來源配置中的holo_info | |
HologresTableName | string | 是 | 資料表名稱 |
PAI-FeatureStore
根據user id來找到對應的item列表。這裡的表定義是約定好的。
表的資料是在MaxCompute裡產生的。需要通過離線的FeatureView註冊到 FeatureStore上。MaxCompute的表資料schema參考如下。
u2i 表
欄位 | 類型 | 描述 |
user_id | string | 使用者id |
item_ids | string | item id列表,支援格式:item_id1,item_id2,item_id3..... 或 item_id1:recall_id1,item_id2:recall_id2..... 或 item_id1:recall_id1:score1,item_id2:recall_id2:score2..... |
ds | string | MaxCompute表分區欄位,名稱自訂 |
配置樣本:
{
"RecallConfs": [
{
"Name": "user2item_recall",
"RecallType": "UserCustomRecall",
"RecallCount": 500,
"DaoConf": {
"AdapterType": "featurestore",
"FeatureStoreName": "fs_pairec",
"FeatureStoreViewName": "u2i_recall"
}
}
]
}欄位 | 類型 | 是否必填 | 描述 |
Name | string | 是 | 自訂召回名稱 |
RecallType | string | 是 | 召回類型,固定值UserCustomRecall |
RecallCount | int | 是 | 召回數量 |
DaoConf | json object | 是 | Dao定義 |
AdapterType | string | 是 | 資料來源類型,取值featurestore |
FeatureStoreName | string | 在資料來源配置(FeatureStoreConfs)中配置好的holo的自訂名稱,如資料來源配置中的fs_pairec | |
FeatureStoreViewName | string | 是 | u2i表註冊的視圖名稱 |
TableStore(OTS)
根據user id來找到對應的item列表。這裡的表定義是約定好的。
u2i 表
欄位 | 類型 | 描述 |
user_id | string | 使用者id |
item_ids | string | item id列表,支援格式:item_id1,item_id2,item_id3..... 或 item_id1:recall_id1,item_id2:recall_id2..... 或 item_id1:recall_id1:score1,item_id2:recall_id2:score2..... |
配置樣本:
{
"RecallConfs": [
{
"Name": "user2item_recall",
"RecallType": "UserCustomRecall",
"RecallCount": 500,
"DaoConf": {
"AdapterType": "tablestore",
"TableStoreName": "ots_info",
"TableStoreTableName": "user_item_table"
}
}
]
}欄位 | 類型 | 是否必填 | 描述 |
Name | string | 是 | 自訂召回名稱 |
RecallType | string | 是 | 召回類型,固定值UserCustomRecall |
RecallCount | int | 是 | 召回數量 |
DaoConf | json object | 是 | Dao定義 |
AdapterType | string | 是 | 資料來源類型,取值tablestore |
TableStoreName | string | 在資料來源配置(TableStoreConfs)中配置好的 tablestore的自訂名稱,如資料來源配置中的tablestore_info | |
TableStoreTableName | string | 是 | 資料表名稱 |
Redis
配置樣本:
{
"RecallConfs": [
{
"Name": "user2item_recall",
"RecallType": "UserCustomRecall",
"RecallCount": 500,
"DaoConf": {
"AdapterType": "redis",
"RedisName": "redis_info",
"RedisPrefix": ""
}
}
]
}欄位 | 類型 | 是否必填 | 描述 |
Name | string | 是 | 自訂召回名稱 |
RecallType | string | 是 | 召回類型,固定值UserCustomRecall |
RecallCount | int | 是 | 召回數量 |
DaoConf | json object | 是 | Dao定義 |
AdapterType | string | 是 | 資料來源類型,取值redis |
RedisName | string | 在資料來源配置(RedisConfs)中配置好的Redis的自訂名稱,如資料來源配置中的redis_info | |
RedisPrefix | string | 是 | U2I資料的首碼,通過RedisPrefix + uid構造key擷取, value 的格式:item_id1,item_id2,item_id3..... 或 item_id1:recall_id1,item_id2:recall_id2..... 或 item_id1:recall_id1:score1,item_id2:recall_id2:score2..... |
圖召回(GraphRecall)
圖召回也屬於U2I召回的一種。通過GraphCompute圖資料庫進行召回。
配置樣本:
{
"RecallConfs": [
{
"Name": "graph_recall",
"RecallType": "GraphRecall",
"RecallCount": 500,
"GraphConf": {
"GraphName": "graph_test",
"ItemId": "item_id",
"QueryString": "g(\"test\").V(\"$1\").hasLabel(\"user\").outE().inV()",
"Params": [
"user.uid"
]
}
}
]
}GraphConf:
欄位 | 類型 | 是否必填 | 描述 |
Name | string | 是 | 自訂召回名稱 |
RecallType | string | 是 | 召回類型,固定值GraphRecall |
RecallCount | int | 是 | 召回數量 |
GraphName | string | 是 | 在資料來源配置(GraphConfs)中配置好的graph的自訂名稱,如資料來源配置中的graph_info |
ItemId | string | 是 | graph返回結果中,item的主鍵欄位 |
QueryString | string | 是 | 圖召回的查詢語句,其中$1為預留位置,需要從Params中取。 |
Params | string | 是 | 填充參數的來源。具體格式如:
|
使用者分組熱門召回(UserGroupHotRecall)
Hologres
分組熱門召回的表的格式也是約定好的。
group_hot_table
表欄位 | 類型 | 描述 |
trigger_id | string | trigger資訊,多個特徵組裝 |
item_ids | string | item id 列表,支援格式:item_id1,item_id2,item_id3..... 或 item_id1:recall_id1,item_id2:recall_id2..... 或 item_id1:recall_id1:score1,item_id2:recall_id2:score2..... |
按照使用者特徵和context資訊(例如地區、機型等)組裝trigger_id
按照順序將特徵用底線(_)拼接為trigger_id
特徵值為空白對應 "NULL"
包含 Boundaries 欄位的特徵需要進行離散化(左開,右閉區間),比如年齡 [20, 30, 40, 50] --> trigger對應 <=20, 20-30, 30-40,40-50, >50
使用者年齡23,對應"20-30"
使用者年齡空,對應"NULL"
使用者年齡60,對應">50"
使用者年齡19,對應"<=20"
hologres表示例:
此處使用性別、年齡、機型三個特徵
trigger_id | item_ids |
Male_<=20_IOS | item_id1::score1,item_id2::score2....... |
Famale_20-30_Android | item_id4::score4,item_id5::score5....... |
...... | ....... |
配置樣本:
{
"RecallConfs": [
{
"Name": "user_group_hot_recall",
"RecallType": "UserGroupHotRecall",
"RecallCount": 500,
"Triggers": [
{
"TriggerKey": "gender"
},
{
"TriggerKey": "age",
"Boundaries": [20,30,40,50]
},
{
"TriggerKey": "os"
}
],
"DaoConf": {
"AdapterType": "hologres",
"HologresName": "holo_info",
"HologresTableName": "group_hotness_table"
}
}
]
}欄位 | 類型 | 是否必填 | 描述 |
Name | string | 是 | 自訂召回名稱 |
RecallType | string | 是 | 召回類型,固定值UserGroupHotRecall |
RecallCount | int | 是 | 召回數量 |
Triggers | json array | 是 | 構造trigger_id的具體資訊 |
| string | 是 | 從user的特徵裡擷取trigger值 |
| json int array | 否 | 欄位的邊界值範圍 |
DaoConf | json object | 是 | Dao定義 |
| string | 是 | 資料來源類型,取值hologres |
| string | 在資料來源配置(HologresConfs)中配置好的holo 的自訂名稱,如資料來源配置中的holo_info | |
| string | 是 | 資料表名稱 |
PAI-FeatureStore
分組熱門召回的表的格式也是約定好的。
表的資料是在MaxCompute裡產生的。需要通過離線的FeatureView註冊到 FeatureStore上。MaxCompute的表資料schema參考如下。
group_hot_table
表欄位 | 類型 | 描述 |
trigger_id | string | trigger資訊,多個特徵組裝 |
item_ids | string | item id 列表,支援格式:item_id1,item_id2,item_id3..... 或 item_id1:recall_id1,item_id2:recall_id2..... 或 item_id1:recall_id1:score1,item_id2:recall_id2:score2..... |
ds | string | MaxCompute表的分區欄位,可以自訂 |
按照使用者特徵和context資訊(例如地區、機型等)組裝trigger_id
按照順序將特徵用底線(_)拼接為trigger_id
特徵值為空白對應 "NULL"
包含 Boundaries 欄位的特徵需要進行離散化(左開,右閉區間),比如年齡 [20, 30, 40, 50] --> trigger對應 <=20, 20-30, 30-40,40-50, >50
使用者年齡23,對應"20-30"
使用者年齡空,對應"NULL"
使用者年齡60,對應">50"
使用者年齡19,對應"<=20"
表示例:
此處使用性別、年齡、機型三個特徵
trigger_id | item_ids |
Male_<=20_IOS | item_id1::score1,item_id2::score2....... |
Famale_20-30_Android | item_id4::score4,item_id5::score5....... |
...... | ....... |
這裡使用了 trigger 特徵實體。
配置樣本:
{
"RecallConfs": [
{
"Name": "user_group_hot_recall",
"RecallType": "UserGroupHotRecall",
"RecallCount": 500,
"Triggers": [
{
"TriggerKey": "gender"
},
{
"TriggerKey": "age",
"Boundaries": [20,30,40,50]
},
{
"TriggerKey": "os"
}
],
"DaoConf": {
"AdapterType": "featurestore",
"FeatureStoreName": "fs_pairec",
"FeatureStoreViewName": "group_hot_recall"
}
}
]
}欄位 | 類型 | 是否必填 | 描述 |
Name | string | 是 | 自訂召回名稱 |
RecallType | string | 是 | 召回類型,固定值UserGroupHotRecall |
RecallCount | int | 是 | 召回數量 |
Triggers | json array | 是 | 構造trigger_id的具體資訊 |
| string | 是 | 從user的特徵裡擷取trigger值 |
| json int array | 否 | 欄位的邊界值範圍 |
DaoConf | json object | 是 | Dao定義 |
| string | 是 | 資料來源類型,取值featurestore |
| string | 在資料來源配置(FeatureStoreConfs)中配置好的holo 的自訂名稱,如資料來源配置中的fs_pairec | |
| string | 是 | 熱門召回表對應的視圖名稱 |
當分組熱門召回數量一直為0時,需要檢查Trigger的拼接順序,引擎配置中是按照Triggers中從上到下的順序拼接的,需要對比此拼接順序是否和召回表中的順序是否一致。
全域熱門召回(UserGlobalHotRecall)
Hologres
全域熱門召回的表schema和分組召回的表schema是相同的,只是全域熱門召回表中只有一條資料,而且 trigger_id = -1 。
配置樣本:
{
"RecallConfs": [
{
"Name": "UserGlobalHotRecall",
"RecallType": "UserGlobalHotRecall",
"RecallCount": 500,
"DaoConf": {
"AdapterType": "hologres",
"HologresName": "holo_info",
"HologresTableName": "global_hotness_table"
}
}
]
}PAI-FeatureStore
全域熱門召回的表schema和分組召回的表schema是相同的,只是全域熱門召回表中只有一條資料,而且 trigger_id = -1 。
表的資料是在MaxCompute裡產生的。需要通過離線的FeatureView註冊到 FeatureStore上。MaxCompute的表資料schema參考如下。
表欄位 | 類型 | 描述 |
trigger_id | string | 表裡只有一行資料,值為 -1 。 |
item_ids | string | item id 列表,支援格式:item_id1,item_id2,item_id3..... 或 item_id1:recall_id1,item_id2:recall_id2..... 或 item_id1:recall_id1:score1,item_id2:recall_id2:score2..... |
ds | string | MaxCompute表的分區欄位,可以自訂 |
配置樣本:
{
"RecallConfs": [
{
"Name": "UserGlobalHotRecall",
"RecallType": "UserGlobalHotRecall",
"RecallCount": 500,
"DaoConf": {
"AdapterType": "featurestore",
"FeatureStoreName": "fs_pairec",
"FeatureStoreViewName": "global_hot_recall"
}
}
]
}TableStore(OTS)
全域熱門召回的表schema和分組召回的表schema是相同的,只是全域熱門召回表中只有一條資料,而且 trigger_id = -1。
配置樣本:
{
"RecallConfs": [
{
"Name": "UserGlobalHotRecall",
"RecallType": "UserGlobalHotRecall",
"RecallCount": 500,
"DaoConf": {
"AdapterType": "tablestore",
"TableStoreName": "ots_info",
"TableStoreTableName": "global_hotness_recall"
}
}
]
}欄位 | 類型 | 是否必填 | 描述 |
Name | string | 是 | 自訂召回名稱 |
RecallType | string | 是 | 召回類型,固定值UserGlobalHotRecall |
RecallCount | int | 是 | 召回數量 |
DaoConf | json object | 是 | Dao定義 |
AdapterType | string | 是 | 資料來源類型,取值tablestore |
TableStoreName | string | 在資料來源配置(TableStoreConfs)中配置好的 tablestore的自訂名稱,如資料來源配置中的tablestore_info | |
TableStoreTableName | string | 是 | 資料表名稱 |
冷啟動召回(ColdStartRecall)
提供一個item物料表,根據條件或者時間進行過濾,查詢出符合規則的候選集。
Hologres
{
"RecallConfs": [
{
"Name": "AllLiveItemRecall",
"RecallType": "ColdStartRecall",
"RecallCount": 3000,
"ColdStartDaoConf": {
"AdapterType": "hologres",
"HologresName": "holo_info",
"HologresTableName": "item_status_table",
"WhereClause": "islist_status=1",
"PrimaryKey": "\"item_id\"",
"TimeInterval": 0
}
}
]
}ColdStartDaoConf:
欄位 | 類型 | 是否必填 | 描述 |
Name | string | 是 | 自訂召回名稱 |
RecallType | string | 是 | 召回類型,固定值ColdStartRecall |
RecallCount | int | 是 | 召回數量 |
ColdStartDaoConf | json object | 是 | 冷啟動資料定義 |
AdapterType | string | 是 | 資料來源的類型,取值hologres等 |
HologresName | string | 是 | 在資料來源配置(HologresConfs)中配置好的holo的自訂名稱,如資料來源配置中的holo_info |
HologresTableName | string | 是 | holo中的冷啟動召回表的表名 |
WhereClause | string | 否 | 過濾條件, 如果需要時間過濾,使用${time}。 比如根據建立時間, create_time > ${time} |
PrimaryKey | string | 是 | 表的主鍵 |
TimeInterval | int | 否 | 根據時間差,計算${time}時間值。 ${time} = 目前時間- TimeInterval |
在上述的配置中,通過 WhereClause 過濾候選集時,可以根據介面傳入的features欄位或者使用者的特徵欄位進行過濾。舉個例子說明。如果根據語言和使用者的城市屬性進行過濾候選集,WhereClause可以寫成
"language=${context.features.language} AND city=${user.city}"其中language可以通過介面的features裡傳入,city是使用者的某個特徵。
參數的來源。具體格式如:
user.xxx 代表從user的特徵裡面取xxx這個特徵的值
context.features.xxx 代表從介面中,features欄位中取xxx這個特徵的值
PAI-FeatureStore
僅支援線上資料來源為FeatureDB的FeatureView。
提供一個以物品ID為主鍵的FeatureView,從這個FeatureView 中隨機召回一批物品ID。
{
"RecallConfs": [
{
"Name": "item_cold_start_recall",
"RecallType": "ColdStartRecall",
"RecallCount": 200,
"ColdStartDaoConf": {
"AdapterType": "featurestore",
"FeatureStoreName": "fs_pairec",
"FeatureStoreViewName": "rec_sln_demo_item_table_preprocess_all_feature_v1"
},
"FilterParams": [
]
}
]
}各項配置如下:
欄位 | 類型 | 是否必填 | 描述 |
Name | string | 是 | 自訂召回名稱 |
RecallType | string | 是 | 召回類型,固定值ColdStartRecall |
RecallCount | int | 是 | 召回數量 |
ColdStartDaoConf | json object | 是 | 冷啟動資料定義 |
AdapterType | string | 是 | 資料來源的類型,固定值featurestore等 |
FeatureStoreName | string | 是 | 在資料來源配置(FeatureStoreConfs)中配置好的FeatureStore自訂名稱 |
FeatureStoreViewName | string | 是 | 冷啟動召回對應的FeatureView名稱 |
FilterParams | string | 否 | 冷啟動召回的過濾條件 |
FeatureStoreViewName 配置的FeatureView可以是離線的FeatureView,也可以是即時的。如果是即時的,此路召回也會即時的擷取到新增的物品ID。
如果FilterParams是空的話,說明不設定過濾條件,只隨機擷取物品ID。通過設定FilterParams可以過濾需要的物品ID。
{
"Name": "item_cold_start_recall",
"RecallType": "ColdStartRecall",
"RecallCount": 200,
"ColdStartDaoConf": {
"AdapterType": "featurestore",
"FeatureStoreName": "fs_pairec",
"FeatureStoreViewName": "rec_sln_demo_item_table_preprocess_all_feature_v1"
},
"FilterParams": [
{
"Name": "click_count",
"Type": "int",
"Operator": "greater",
"Value": "15"
},
{
"Name": "category",
"Type": "string",
"Operator": "in",
"Value": "user.category"
}
]
}上面的例子中,Value 以user. 開頭的說明會從user特徵擷取相關的值。category可以通過介面的features欄位傳入。
具體的 Operator 的使用,可以參考附錄。
上下文召回(ContextItemRecall)
有時候會把召回的條目通過引擎介面傳遞過來。引擎介面參考介面測試。通過 item_list 來傳遞自訂召回的資料。
ContextItemRecall 是引擎內建的召回名稱。可以直接在RecallNames中使用。參考如下:
{
"SceneConfs": {
"${scene_name}": {
"default": {
"RecallNames": [
"ContextItemRecall"
]
}
}
}
}I2I 召回(ItemCollaborativeFilterRecall)
Hologres
I2I 召回 用於相似性推薦。相似性推薦需要把相似性的 item_id 傳遞進來,具體介面定義,可以參考介面測試。
配置樣本:
{
"RecallConfs": [
{
"Name": "I2IRecall",
"RecallType": "ItemCollaborativeFilterRecall",
"RecallCount": 500,
"ItemCollaborativeDaoConf": {
"AdapterType": "hologres",
"HologresName": "holo_info",
"Item2ItemTable": "item_collaborative_list"
}
}
]
}配置欄位說明:
欄位 | 類型 | 是否必填 | 描述 |
Name | string | 是 | 自訂召回名稱 |
RecallType | string | 是 | 召回類型,固定值 ItemCollaborativeFilterRecall |
RecallCount | int | 是 | 召回數量 |
ItemCollaborativeDaoConf | json object | 是 | I2I表資料定義 |
| string | 是 | 資料來源的類型,取值 hologres |
| string | 是 | 在資料來源配置(HologresConfs)中配置好的 holo 的自訂名稱,如資料來源配置中的 holo_info |
| string | 是 | I2I 資料表名稱 |
Item2ItemTable 表的定義:
欄位 | 類型 | 描述 |
item_id | string | 物品id |
item_ids | string | item id列表,支援格式:item_id1,item_id2,item_id3..... 或 item_id1:recall_id1,item_id2:recall_id2..... 或 item_id1:recall_id1:score1,item_id2:recall_id2:score2..... |
PAI-FeatureStore
I2I 召回 用於相似性推薦。相似性推薦需要把相似性的 item_id 傳遞進來,具體介面定義,可以參考介面測試。
Item2ItemTable 表的定義:
欄位 | 類型 | 描述 |
item_id | string | 物品id |
item_ids | string | item id列表,支援格式:item_id1,item_id2,item_id3..... 或 item_id1:recall_id1,item_id2:recall_id2..... 或 item_id1:recall_id1:score1,item_id2:recall_id2:score2..... |
配置樣本:
{
"RecallConfs": [
{
"Name": "I2IRecall",
"RecallType": "ItemCollaborativeFilterRecall",
"RecallCount": 200,
"ItemCollaborativeDaoConf": {
"AdapterType": "featurestore",
"FeatureStoreName": "fs_pairec",
"FeatureStoreViewName": "i2i_recall"
}
}
]
}配置欄位說明:
欄位 | 類型 | 是否必填 | 描述 |
Name | string | 是 | 自訂召回名稱 |
RecallType | string | 是 | 召回類型,固定值 ItemCollaborativeFilterRecall |
RecallCount | int | 是 | 召回數量 |
ItemCollaborativeDaoConf | json object | 是 | I2I表資料定義 |
| string | 是 | 資料來源的類型,取值 featurestore |
| string | 是 | 在資料來源配置(FeatureStoreConfs)中配置好的自訂名稱,如資料來源配置中的 fs_pairec |
| string | 是 | I2I 資料工作表檢視名稱 |
EnableMultipleItemId | bool | 否 | 傳入的item_id是否是多值形式 |
MultipleItemIdDelimiter | string | 否 | 當EnableMultipleItemId=true時,item_id的分隔字元的定義。預設值是 |
如果介面傳入的item_id是多值形式,並且是通過,分隔的,可以參考如下配置:
{
"RecallConfs": [
{
"Name": "I2IRecall",
"RecallType": "ItemCollaborativeFilterRecall",
"RecallCount": 200,
"ItemCollaborativeDaoConf": {
"AdapterType": "featurestore",
"FeatureStoreName": "fs_pairec",
"FeatureStoreViewName": "i2i_recall"
},
"EnableMultipleItemId": true,
"MultipleItemIdDelimiter": ","
}
]
}當使用Redis或者localCache快取資料時,緩衝的key為item_id。
使用I2I召回時,需要對請求介面中的item_id欄位傳值。
OpenSearch召回(OpenSearchRecall)
直接調用 opensearch 服務返回召回列表。 opensearch 的文檔參考行業演算法版介紹。
配置樣本:
{
"RecallConfs": [
{
"Name": "OpenSearchRecall",
"RecallType": "OpenSearchRecall",
"OpenSearchConf": {
"OpenSearchName": "opensearch",
"AppName": "test_search",
"ItemId": "log_id",
"RequestParams": {
"query": "query=result:'$1'&&config=start:0,hit:10,format:fulljson&&sort=-log_id&&filter=request_time>1703952000000",
"format": "fulljson",
"second_rank_type": "expression",
"fetch_fields": "log_id;result_data"
},
"Params": [
"context.features.topic"
]
}
}
]
}上面的執行個體說明使用 result 索引進行查詢,查詢的詞是通過介面的上下文中 features 的 topic 欄位獲得。
OpenSearchConf 配置欄位說明:
欄位 | 類型 | 是否必填 | 描述 |
Name | string | 是 | 自訂召回名稱 |
RecallType | string | 是 | 召回類型,固定值 OpenSearchRecall |
RecallCount | int | 是 | 召回數量 |
OpenSearchName | string | 是 | 在資料來源配置(OpenSearchConfs)中配置好的 opensearch 的自訂名稱 |
AppName | string | 是 | opensearch 應用程式名稱 |
ItemId | string | 是 | opensearch 返回結果中,item 的主鍵欄位 |
RequestParams | map[string]interface{} | 是 | opensearch 查詢語句,其中 $1 為預留位置,需要從 Params 裡擷取,詳細文法可以參考 開發指南 |
Params | string | 是 | 填充參數的來源。具體格式如下:
|
如何使用
召回的使用位置對應配置總覽中的SceneConfs,SceneConfs是一個Map[string]object結構,可以分情境的使用召回,配置如下
"SceneConfs": {
"${scene_name}": {
"default": {
"RecallNames": [
"collaborative_filter"
]
}
}
}${scene_name}需要替換為自己的情境名。
default為目錄,這裡保持預設即可。
RecallNames是一個[]string,值為召回配置中的自訂召回名稱。