Vector retrieval API
Background
The PAI-Rec engine provides an API to retrieve user and item vectors generated by models such as Deep Structured Semantic Models (DSSM). You can integrate these vectors into your systems and optionally write data to a DataHub message queue for consistency tracking.

Pass a user_id with user_features, or an item_id with item_features. The engine returns the corresponding embedding and can optionally log requests to DataHub.
API reference
Endpoint
POST /api/embedding
Request parameters
|
Parameter |
Description |
Type |
Required |
Example |
|
uid |
The user ID. Required for generating a user vector. |
string |
No |
"1000079" |
|
scene_id |
The scenario ID. |
string |
Yes |
"home_feed" |
|
user_features |
User-side features. Required for generating a user vector. |
JSON object |
No |
{"age":20, "sex":"male"} |
|
item_id |
The item ID. Required for generating an item vector. |
string |
No |
"248791390" |
|
item_features |
Item-side features. Required for generating an item vector. |
JSON object |
No |
{"brand":"Nike", "category":"shoes"} |
|
debug |
Enables additional debug logs. |
boolean |
No |
true |
|
request_id |
Unique request ID. Auto-generated if omitted. |
string |
No |
"c46c3f5e-***-1248" |
Response body
|
Parameter |
Description |
Type |
Example |
|
code |
Status code of the request. |
integer |
200 |
|
msg |
Response message. |
string |
"success" |
|
request_id |
Unique request ID. |
string |
"e332fe9c-***-d07f6" |
|
embedding |
Generated vector data. |
array<float> |
[-0.10198704, 0.10990965, 0.04562417, ...] |
|
model_config |
Configuration passed through from the model. |
object |
{"model_version":"20260513"} |
Error codes
|
Error code |
Description |
Message example |
|
200 |
Request succeeded. |
"success" |
|
400 |
Invalid parameter. Check the |
|
|
500 |
Internal server error. |
Request examples
Generate a user vector
curl -v http://host/api/embedding -d '{"uid":"76295990", "user_features":{"context_industry_index":"0,0,0"}, "scene_id":"dssm_user_embedding"}'
Response
{
"code": 200,
"msg": "success",
"request_id": "d96534c7-***-163b1e2f173b",
"embedding": [
-0.10198704,
0.10990965,
0.04562417,
...
]
}
Generate an item vector
curl -v http://host/api/embedding -d '{"item_id":"76295990", "item_features":{"context_industry_index":"0,0,0"}, "scene_id":"dssm_item_embedding"}'
Response
{
"code": 200,
"msg": "success",
"request_id": "5f339fef-***-5e72466d4d68",
"embedding": [
0.003976563,
0.22998181,
0.013637823,
...
]
}
Engine configuration
EmbeddingConfs has two parts:
-
Calling the retrieval model
-
Writing logs (only DataHub is supported)
{
"EmbeddingConfs": {
"dssm_user_embedding": {
"RankConf": {
"RankAlgoList": [
"test_dssm_rec"
],
"Processor": "EasyRec"
},
"DataSource": {
"Name": "pairec_emb_dh",
"Type": "datahub"
}
},
"dssm_item_embedding": {
"RankConf": {
"RankAlgoList": [
"test_dssm_item"
],
"Processor": "EasyRec"
}
}
}
}
EmbeddingConfs supports multiple scenarios. In this example, the two scenarios are dssm_user_embedding and dssm_item_embedding.
-
RankConf: Model configuration, same as a standard engine service. -
DataSource-
Type: Message queue type. Onlydatahubis supported. -
pairec_emb_dh: Data source name, defined inDatahubConfs. Thedssm_item_embeddingscenario has noDataSource, so its requests are not logged.
-
Model configuration
In the preceding configuration, test_dssm_rec and test_dssm_item are model configurations defined in AlgoConfs.
{
"AlgoConfs": [
{
"Name": "test_dssm_item",
"Type": "EAS",
"EasConf": {
"Processor": "EasyRec",
"Timeout": 300,
"ResponseFuncName": "torchrecEmbeddingResponseFunc",
"EndpointType": "DIRECT",
"Url": "http://xxx.vpc.cn-beijing.pai-eas.aliyuncs.com/api/predict/test_dssm_item",
"Auth": "***"
}
},
{
"Name": "test_dssm_rec",
"Type": "EAS",
"EasConf": {
"Processor": "EasyRec",
"Timeout": 300,
"EndpointType": "DIRECT",
"ResponseFuncName": "torchrecEmbeddingResponseFunc",
"Url": "http://xxxx.vpc.cn-beijing.pai-eas.aliyuncs.com/api/predict/test_dssm_rec",
"Auth": "***"
}
}
]
}
The ResponseFuncName parameter must be set to the fixed value torchrecEmbeddingResponseFunc.
Data source configuration
Configure DataHub to collect request logs.
{
"DatahubConfs": {
"pairec_emb_dh": {
"Endpoint": "http://dh-cn-beijing-int-vpc.aliyuncs.com",
"AccessId": "${AccessKey}",
"AccessKey": "${AccessSecret}",
"ProjectName": "",
"TopicName": "",
"Schemas": [
{
"Field": "request_id",
"Type": "string"
},
{
"Field": "module",
"Type": "string"
},
{
"Field": "scene",
"Type": "string"
},
{
"Field": "request_time",
"Type": "integer"
},
{
"Field": "user_features",
"Type": "string"
},
{
"Field": "item_features",
"Type": "string"
},
{
"Field": "user_id",
"Type": "string"
},
{
"Field": "item_id",
"Type": "string"
},
{
"Field": "embeddings",
"Type": "string"
}
]
}
}
}
Set ProjectName and TopicName. Create the project in the DataHub console; the topic is created automatically.