快速拉起向量召回服务

本文档为您展示一个示例,在本例中,我们将准备一份向量数据(假设数据表的表名为aime_example_vector),一份物品详情数据(假设数据表的表名为aime_example_detail),及一份行为表(假设行为表的表名为aime_example_exposure),然后在智能召回引擎控制台上注册数据,最后用这三份数据拉起一个向量召回服务。

数据准备

准备物品向量表

在MaxCompute客户端中准备离线数据

-- 创建数据表
CREATE TABLE IF NOT EXISTS aime_example_vector (
  item_id STRING COMMENT "物品ID",
  vector STRING COMMENT "物品向量"
) PARTITIONED BY (
  ds STRING COMMENT "分区字段"
);

-- 写入向量数据,实际业务场景下,具体的写入数据由您的算法逻辑产出
INSERT OVERWRITE TABLE aime_example_vector PARTITION (ds = '20210822')
SELECT '10001' AS item_id, '0.4426,0.0724,0.0210,0.4353,0.6385,0.0770,0.0158,0.4417' AS vector UNION
SELECT '10002' AS item_id, '0.2119,0.3770,0.5210,0.0279,0.5151,0.3806,0.3244,0.1590' AS vector UNION
SELECT '10003' AS item_id, '0.2829,0.0720,0.1324,0.2817,0.4565,0.6583,0.0338,0.4183' AS vector;

-- 写入标识分区
INSERT OVERWRITE TABLE aime_example_vector PARTITION (ds = '20210822.done')
SELECT NULL, NULL UNION;

在智能召回引擎控制台上注册数据

进入 实例详情-数据管理 页面,点击“注册数据”

image.png

配置基础信息:

image.png

点击“下一步”,开始配置索引

image.png

点击“下一步”,配置全量调度方式

image.png

点击“配置完成并上线”,完成注册并发布

image.png

准备物品详情表(可选)

在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;

在智能召回引擎控制台上注册数据

进入 实例详情-数据管理 页面,按照如下方式填写:

image.png

点击“下一步”,开始配置索引

image.png

点击“下一步”,开始配置全量调度方式

image.png

点击“配置完成并上线”,完成注册并发布

image.png

准备行为表(可选)

在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;

在智能召回引擎控制台上注册数据

进入 实例详情-数据管理 页面,按照如下方式填写:

image.png

点击“下一步”,开始配置索引

image.png

点击“下一步”,开始配置全量调度方式

image.png

点击“配置完成并上线”,完成注册并发布

image.png

服务注册

在 实例详情-服务管理 中,点击“创建召回服务”按钮,开始创建召回服务。

image.png

选择注册“向量召回”服务

image.png

点击“下一步”,填写基础配置信息:

image.png

点击“下一步”,选择我们刚刚注册的两张表

image.png

配置完成并上线

image.png

进入服务管理,可以看到我们刚才创建的召回服务,等待其发布完成,就可以使用了。

阿里云首页 智能推荐AIRec 相关技术圈