Handling position features in online prediction

Updated at:

1. Background and problem

In a recommendation system, the position feature is a key input during offline training because it captures how user responses vary by display position. During online prediction, however, the position feature is unknown. The model needs it to calculate a ranking score, yet the actual position depends on that score.

To break this circular dependency, you assign a position value to each candidate item at prediction time. Two methods are available: passing the position feature dynamically through an API, and using a preset default value from a configuration file.

2. Solutions

1. Provide the position feature via the API

With the API method, you pass the position value as a key-value pair in the features request parameter when making an online prediction request.

  • Example request:

curl 'http://host/api/callback' -d '{"uid":"84603208","request_id":"d9cb1c8d-4d3f-491b-9ea3-380481dabde3","scene_id":"homepage","features":{"age":25, "city":"beijing", "position_feature":5 }, "item_list":[{"item_id":"113939841"},{"item_id":"113764910"}],"request_info":{"recom_id":"1111111"}}'

The required parameters for this API are uid (user ID, string), size (number of items to return, integer), and scene_id (scene ID, string). The optional parameters are features (context features, a JSON map), item_id (the item ID for similarity-based recommendations, string), item_list (a list of items for custom retrieval, a JSON array), and debug (enables additional logging, bool).

2. Use a default value

If you do not specify the position feature in the API request, the system uses the default value defined in the fg.json configuration file. This approach simplifies requests and works well when granular control over position values is unnecessary.