Search results ranked purely by text relevance often miss what users actually want. When a user searches for "Bright," they are more likely looking for dairy products than rice — but a text-only ranker cannot capture that intent. Category prediction solves this by training a model on historical search and click data to learn the relevance between queries and product categories, then using that relevance score to adjust rankings at sort time.
When a sort expression references the category relevance score, commodities in high-relevance categories rank higher. This lets you surface the most commercially relevant results without manually tuning sort weights for every query.
How it works
Category prediction trains a model that measures relevance between a search query and each commodity category. The model draws on three data sources:
| Data source | How to provide it |
|---|---|
| Historical search queries | Add the raw_query parameter to search requests |
| Category and commodity data | Specify fields in the application; category ID and commodity title are required |
| Click behavioral data | Instrument the application to report click events |
OpenSearch supports two training modes depending on whether behavioral data is available.
Training with behavioral data
Use this mode when click data is uploaded and meets the training thresholds. At training start, OpenSearch automatically checks that the data meets required quantity, quality, and integrity criteria.
The training pipeline runs these steps:
Generate sample data from historical search queries and category information; use behavioral data to label the samples.
Collect index statistics and run feature calculations on click data to generate click features.
Analyze search queries and commodity titles to calculate semantic features.
If transaction behavioral data is available, run feature calculations to generate transaction features, which help rank commodities with stronger transaction performance higher.
Combine sample data, behavior features, semantic features, transaction features, and labels into training data; run iterative training on the algorithm.
Output a model describing relevance between search queries and categories.
Training without behavioral data
Use this mode when click data is unavailable, not yet uploaded, you do not want to use the behavioral data on clicks for training, or the data does not meet the training thresholds. Only the category ID and commodity title fields are required.
Without behavioral data, no labels exist for the sample data. The model instead calculates semantic relevance between search query text and commodity titles, using that as the category relevance score.
A model trained with behavioral data produces more accurate predictions because it captures more dimensions of relevance. Both modes require parameter tuning and validation across data from different scenarios.
Prerequisites
Before training a model, ensure you have:
A data source that stores commodity data
An application to associate with the model
Category and commodity data, historical search entries, and behavioral data of the application
The following fields specified in the application:
| Field | Required | Purpose |
|---|---|---|
| Category ID | Yes | Identifies the category for each commodity |
| Commodity title | Yes | Used to calculate semantic relevance |
| Category name | No (recommended) | Displayed on the performance evaluation page for manual review |
Including the category name field lets you verify on the performance evaluation page whether predicted category-query relevance matches expectations.
If click data is available and meets the training thresholds, select the additional behavioral data fields when configuring the model.
Get started with category prediction
Create a category prediction model and associate it with an application.
Apply the model to both query analysis and the rough and fine sort stages.
Create a query analysis rule, configure category prediction, and select the model created in step 1.
Make the category prediction model take effect in search requests: use an SDK to call the relevant operations and include the
raw_queryparameter.
For detailed configuration steps, see Use category prediction.
What's next
After the model is trained, export the prediction results and review them on the performance evaluation page. Confirm that the predicted category-query relevance meets your expectations.