CTR prediction models

更新时间:
复制 MD 格式

Click-through rate (CTR) prediction scores the likelihood that a user clicks a search result after it is shown. OpenSearch uses this score in fine sort scripts to re-rank results, improving both relevance and CTR.

Limitations

  • Available only on Industry Algorithm Edition - Dedicated Cluster instances.

  • Each application supports up to three CTR prediction models.

  • CTR prediction models can only be called from Cava-based plugins.

Prerequisites

Before you begin, make sure you have:

Create and train a model

  1. Log on to the OpenSearch console and go to Search Algorithm Center > Sort Configuration in the left-side navigation pane.

  2. On the Policy Management page, click CTR Prediction Models in the left-side pane, then click Create.

    image

  3. Enter a model name and map the training fields.

    • Commodity ID and Commodity Title are required. The more fields you map, the better the model performs.

    image

    image

  4. Find the model on the CTR Prediction Models page and click Train in the Actions column.

    image

  5. Monitor training progress on the model details page.

    image

  6. After training completes, check the model status:

    • Available: The model is ready to use.

    • Unavailable: Adjust your data to meet the upgrade conditions in the Data integrity levels section, then retrain the following day. If issues persist, submit a ticket for technical support.

    image

Enable scheduled training to retrain the model daily and keep it current.

Apply the model in a fine sort policy

  1. Go to Search Algorithm Center > Sort Configuration > Policy Management and click Create.

    image

  2. Set the Policy Name, select Fine Sort from the Scope drop-down list, and select Cava Script from the Type drop-down list. Click Next.

    image

  3. Click Add Script File, paste the sample Cava script below into the editor, and replace "Name of your CTR prediction model" with your model name.

  4. Click Compile. If compilation succeeds, click Save and then Publish.

    image

    image

Sample Cava script:

package users.scorer;
import com.aliyun.opensearch.cava.framework.OpsScoreParams;
import com.aliyun.opensearch.cava.framework.OpsScorerInitParams;
import com.aliyun.opensearch.cava.framework.OpsRequest;
import com.aliyun.opensearch.cava.framework.OpsDoc;
import com.aliyun.opensearch.cava.features.algo.AlgoModel;

class BasicSimilarityScorer {
    boolean init(OpsScorerInitParams params) {
        return true;
    }

    double score(OpsScoreParams params) {
        double score = 0;
        return score;
    }
};

class IntelligenceAlgorithmScorer {
    AlgoModel _algoModel;

    boolean init(OpsScorerInitParams params) {
        // tf_checkpoint is a fixed parameter name—do not change it.
        _algoModel = AlgoModel.create(params, "tf_checkpoint", "ctr", "Name of your CTR prediction model");
        return true;
    }

    double score(OpsScoreParams params) {
        OpsDoc doc = params.getDoc();
        double modelScore = _algoModel.evaluate(params);
        doc.trace("ctrModelScore: ", modelScore);

        double score = modelScore + 700;
        return score;
    }
};

The IntelligenceAlgorithmScorer loads your CTR model using AlgoModel.create and scores each document in the fine sort (second-stage ranking) phase.

Run a search test

After publishing the policy, send a search request with the following required parameters.

image
Parameter Required Description
second_rank_type Yes Must reference the fine sort policy type.
second_rank_name Yes Must reference the fine sort policy name you created.
raw_query Yes The original search query string. Must be a unique, independent query that returns results.
user_id Recommended Include in both search requests and behavioral data to improve model personalization.

For example Java SDK code, see SDK for Java demo code for implementing the search feature.

Manage the model

Basic information

The model details page shows Created At, Status, Last Training Time, and Latest Version Status.

image

Training fields

Click Map Training Fields to modify or delete fields in the Map Training Fields panel. After changing training fields, retrain the model.

image

Scheduled training

Scheduled training is enabled by default and runs daily. Modify the schedule to customize the training cycle.

image

Data integrity levels

The integrity level reflects the volume and quality of your behavioral data. A higher level means richer data and more accurate model training.

Data Integrity has two valid values: Available Data and Abnormal Data.

Item page views (IPVs) measure CTR per search, where bhv_type=click. When a user clicks a result, upload two behavioral data entries: one with bhv_type=expose and one with bhv_type=click.

The table below describes each level and the conditions required to advance to the next.

Level Description Conditions to advance
l0 Completely unavailable. Required core fields are missing or data volume is too small to process. Advance to l1: application table has more than 1,000 entries; PVs in the last 24 hours exceed 10,000; independent queries in the last 24 hours exceed 1,000 (counted by raw_query).
l1 Core fields are present and meet basic requirements, but behavioral data is small and some fields are missing. Optimization that doesn't rely on behavioral data is possible. Advance to l2: IPVs in the last 24 hours exceed 1,000; impressions exceed IPVs and bhv_type is not empty; unique visitors (UVs) in the last 24 hours exceed 1,000 (counted by user_id); rn field is populated in more than 90% of behavioral data; item_id is populated in more than 90%; bhv_time is populated in more than 90%; item_id matches the application table in more than 90%; rn matches request_id in search logs in more than 60%; bhv_time contains valid timestamps in more than 60%; bhv_time indicates the current day in more than 60% (confirming data is reported without delay).
l2 Data quality meets requirements, but data volume is small, which limits optimization accuracy. Advance to l3: PVs exceed 1,000,000; UVs exceed 100,000; independent queries exceed 100,000; IPVs exceed 100,000; impressions exceed IPVs; rn matches request_id in more than 90%; bhv_time contains valid timestamps in more than 90%; bhv_time indicates the current day in more than 90%.
l3 Both data quality and volume meet requirements. Full optimization is available. Advance to l4: PVs exceed 10,000,000; UVs exceed 1,000,000; independent queries exceed 1,000,000; IPVs exceed 1,000,000.
l4 Large data volume (tens of millions of entries) with strong integrity. Advance to l5: PVs exceed 100,000,000; UVs exceed 10,000,000; independent queries exceed 10,000,000; IPVs exceed 10,000,000.
l5 Very large data volume (hundreds of millions of entries). Deep optimization is available.

What's next