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
Log on to the OpenSearch console and go to Search Algorithm Center > Sort Configuration in the left-side navigation pane.
On the Policy Management page, click CTR Prediction Models in the left-side pane, then click Create.

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.


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

Monitor training progress on the model details page.

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.

Enable scheduled training to retrain the model daily and keep it current.
Apply the model in a fine sort policy
Go to Search Algorithm Center > Sort Configuration > Policy Management and click Create.

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.

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.Click Compile. If compilation succeeds, click Save and then Publish.


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.
| 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.
Training fields
Click Map Training Fields to modify or delete fields in the Map Training Fields panel. After changing training fields, retrain the model.
Scheduled training
Scheduled training is enabled by default and runs daily. Modify the schedule to customize the training cycle.
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, wherebhv_type=click. When a user clicks a result, upload two behavioral data entries: one withbhv_type=exposeand one withbhv_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. | — |




