Handling position features in online prediction

更新时间:
复制 MD 格式

1. Background and problem

When building a recommendation system, models use the position feature as a key input during offline training to capture how user responses vary by display position. During online prediction, however, this position feature is unknown. The model must calculate a ranking score to determine an item's final position in the recommendation list, but the score calculation itself requires the position feature.

Solving this problem requires a strategy for assigning a position value to each candidate item during prediction, which enables the model to score them effectively. This document describes two methods: 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

The API method allows callers to specify the position feature. When making an online prediction request, you can pass the position information as a key-value pair within the features request parameter.

  • 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 automatically uses the default value preset in the fg.json configuration file. This method simplifies API requests and is suitable when granular control is unnecessary or the default setting is sufficient.