本文档为您展示一个示例,在本例中,我们将准备一份X2I召回数据(假设数据表的表名为aime_example_x2i
),一份物品详情数据(假设数据表的表名为aime_example_detail
),及一份行为表(假设行为表的表名为aime_example_expose
),然后在智能召回引擎控制台上注册数据,最后用这两份数据拉起一个X2I召回服务。
数据准备
准备X2I召回表
在MaxCompute客户端中准备离线数据
-- 创建数据表
CREATE TABLE IF NOT EXISTS aime_example_x2i (
trigger_id STRING COMMENT "召回字段",
item_id STRING COMMENT "物品ID",
score DOUBLE COMMENT "召回分"
) PARTITIONED BY (
ds STRING COMMENT "分区字段"
);
-- 写入X2I数据,实际业务场景下,具体的写入数据由您的算法逻辑产出
INSERT OVERWRITE TABLE aime_example_x2i PARTITION (ds = '20210822')
SELECT 'A' AS trigger_id, '10001' AS item_id, 1.12 AS score UNION
SELECT 'A' AS trigger_id, '10002' AS item_id, 1.07 AS score UNION
SELECT 'B' AS trigger_id, '10001' AS item_id, 0.98 AS score UNION
SELECT 'C' AS trigger_id, '10003' AS item_id, 0.87 AS score;
-- 写入标识分区
INSERT OVERWRITE TABLE aime_example_x2i PARTITION (ds = '20210822.done')
SELECT NULL, NULL, NULL UNION;
在智能召回引擎控制台上注册数据
进入实例详情-数据管理页面,点击“注册数据”
配置基础信息:
点击“下一步”,开始声明数据结构
点击“下一步”,配置全量调度方式
点击“配置完成并上线”,完成注册并发布
准备物品详情表(可选)
在MaxCompute客户端中准备数据
-- 创建数据表
CREATE TABLE IF NOT EXISTS aime_example_detail (
nid STRING COMMENT "物品ID",
title STRING COMMENT "物品名称",
price DOUBLE COMMENT "物品价格"
) PARTITIONED BY (
ds STRING COMMENT "分区字段"
);
-- 写入物品数据,实际业务场景下,具体应该写入您实际的物品详情数据
INSERT OVERWRITE TABLE aime_example_detail PARTITION (ds = '20210822')
SELECT '10001' AS nid, '甜美泡泡袖蝴蝶结宝藏连衣裙' AS title, 269.00 AS price UNION
SELECT '10002' AS nid, '亚麻法式小黑裙连衣裙' AS title, 259.00 AS price UNION
SELECT '10003' AS nid, '法式西装裙收腰衬衫裙子' AS title, 599.00 AS price;
-- 写入标识分区
INSERT OVERWRITE TABLE aime_example_detail PARTITION (ds = '20210822.done')
SELECT NULL, NULL, NULL UNION;
在智能召回引擎控制台上注册数据
进入实例详情-数据管理页面,按照如下方式填写:
点击“下一步”,开始配置索引
点击“下一步”,开始配置全量调度方式
点击“配置完成并上线”,完成注册并发布
准备行为表(可选)
在MaxCompute客户端中准备数据
DROP TABLE IF EXISTS aime_example_expose;
-- 创建数据表
CREATE TABLE IF NOT EXISTS aime_example_expose (
user_id STRING COMMENT "用户ID",
item_id STRING COMMENT "物品ID",
time BIGINT COMMENT "行为时间"
) PARTITIONED BY (
ds STRING COMMENT "分区字段"
);
-- 写入向量数据,实际业务场景下,具体的写入数据由您的算法逻辑产出
INSERT OVERWRITE TABLE aime_example_expose PARTITION (ds = '20210822')
SELECT 'u0001' AS user_id, '10001' AS item_id, 1640275200 AS time UNION -- 20211224
SELECT 'u0001' AS user_id, '10002' AS item_id, 1640275200 AS time UNION -- 20211224
SELECT 'u0002' AS user_id, '10003' AS item_id, 1640275200 AS time UNION -- 20211224
SELECT 'u0002' AS user_id, '10004' AS item_id, 1640275200 AS time UNION -- 20211224
SELECT 'u0003' AS user_id, '10001' AS item_id, 1640275200 AS time UNION -- 20211224
SELECT 'u0003' AS user_id, '10002' AS item_id, 1640188800 AS time UNION -- 20211223
SELECT 'u0003' AS user_id, '10003' AS item_id, 1640102400 AS time UNION -- 20211222
SELECT 'u0003' AS user_id, '10004' AS item_id, 1640016000 AS time UNION -- 20211221
SELECT 'u0003' AS user_id, '10005' AS item_id, 1639929600 AS time UNION -- 20211220
SELECT 'u0003' AS user_id, '10006' AS item_id, 1639843200 AS time UNION -- 20211219
SELECT 'u0003' AS user_id, '10007' AS item_id, 1639756800 AS time UNION -- 20211218
SELECT 'u0003' AS user_id, '10008' AS item_id, 1639670400 AS time UNION -- 20211217
SELECT 'u0003' AS user_id, '10009' AS item_id, 1639584000 AS time UNION -- 20211216
SELECT 'u0003' AS user_id, '10010' AS item_id, 1639497600 AS time; -- 20211215
-- 写入标识分区
INSERT OVERWRITE TABLE aime_example_expose PARTITION (ds = '20210822.done')
SELECT NULL, NULL, NULL;
在智能召回引擎控制台上注册数据
进入实例详情-数据管理页面,按照如下方式填写:
点击“下一步”,开始配置索引
点击“下一步”,开始配置全量调度方式
点击“配置完成并上线”,完成注册并发布
服务注册
在实例详情-服务管理中,点击“创建召回服务”按钮,开始创建召回服务。
服务类型选择“X2I召回”
配置服务基础信息
配置数据,选择我们刚才准备好的数据
配置完成并上线
进入服务管理,可以看到我们刚才创建的召回服务,等待其发布完成,就可以使用了。
文档内容是否对您有帮助?