Prediction APIs
Function
This API is used to perform online prediction.
URI
POST Prediction address returned after the service is successfully deployed
Request
Table 1 describes the request parameters.
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| rec_num | No | Integer | Number of returned requests. The default value is 50. |
| user_id | Yes | String | User ID |
| items | No | List | List of item IDs. This parameter needs to be used together with the Item-Based Collaborative Filtering algorithm during service deployment and provides the function of querying the similarity between items. |
| others_users | No | List | List of user IDs. This parameter provides the function of querying the candidate sets of multiple users. |
| context | No | String | Context information, which can be used to configure the online filtering blacklist. Items in the blacklist will be excluded from the final candidate set. |
| filter_items | No | List | List of item IDs. Items in the online blacklist will not be in the returned recommendation candidate set. |
| online_tags | No | List | List of data formats that consist of attributes, attribute values, and attribute weights. The attribute values or attribute weights are optional. If the weight information is not provided, the default value 0.01 is used. This function must be used together with online retrieval during service deployment. The format is as follows: [{"name": "age","value": " middle-aged ","weight": 0.6},{"name": "sex","value": " male "}]. |
| online_override | No | Boolean | This parameter must be used together with online_tags. Indicates whether the online prediction tags overwrite the tags and weights configured when a service is released. The default value is false. If the value of online_override is false, the existing tags and weights are updated by the new ones. |
| priority_tags | No | List | List of data formats that consist of attributes, attribute values, attribute weights, and attribute data types. The attribute values or attribute weights are optional. If the weight information is not provided, the default value 0.01 is used. This parameter must be used together with attribute matching and ranking during service deployment. The format is as follows: [{"name":"age","value": "middle-aged ","item_data_type":"strArray"},{"name":"sex","value":[" male "," female "] ,"item_data_type":"strArray"}]. |
| priority_override | No | Boolean | This parameter must be used together with priority_tags. Indicates whether the online prediction tags overwrite the tags and weights related to attribute matching and ranking configured when a service is released. The default value is false. If the value of priority_override is false, the existing tags and weights are updated by the new ones. |
| topping_sources | No | List | This parameter is used to move the candidate sets of some strategies to the top as required. For example, if topping_sources is set to ["A", "B"], all selected candidate sets of A, all selected candidate sets of B, and candidate sets that are not in A or B are output in sequence. |
Response
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| is_success | Yes | Boolean | Whether the request is successful. The value can be true or false. true indicates the request is successful, and false indicates the request has failed. |
| data | Yes | JSON | Data parameter. For details, see Table 3. |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| trace_id | Yes | String | Message tracing ID, which identifies the recommendation result of the current request |
| rec_num | Yes | Integer | Number of returned results |
| user_id | Yes | String | User ID |
| content | Yes | List | Content of recommended items. For details, see Table 4 |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| score | Yes | Float | Score of an item. A larger value indicates a higher probability of being recommended. |
| item | Yes | JSON | Recommended item. For details, see Table 5. |
Example
- Example request
{ "user_id": "u1", "rank_items": ["i1", "i2", "i3"], "rec_num": 20, "items": ["i4", "i5"], "other_users": ["u2", "u3"], "context": "{\"blackItemList\":[\"i6\", \"i7\", \"i8\"]}", "topping_sources": ["A", "B"] } - Example of a successful response
{ "is_success": true, "data": { "trace_id": "a94495c062c6443b87c097427d99232d", "user_id": "260086000000100759", "rec_num": 2, "content": [{ "score": 0.51, "item": { "id": "3101010003401" }, "source": "A" }, { "score": 0.52, "item": { "id": "3101010003402" }, "source": "B" }, { "score": 0.53, "item": { "id": "3101010003403" }, "source": "C" } ] } } - Example of a failed response
{ "is_success": false, "error_msg": "Backend service found error. Failed to respond due to backend service not found or failed to respond, please check the service you request. " }
Status Code
For details about status codes, see Status Codes.
Last Article: Deploying Inference Services
Next Article: Prediction APIs (Ranking)
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.