Flowchart
Note: To make category prediction take effect, you must complete all the configurations in the preceding figure.
Procedure
Create and train a category prediction model
In the left-side navigation pane, choose Search Algorithm Center > Sort Configuration. On the Policy Management page, click Category Prediction Model in the left-side pane. On the Category Prediction Model page, click Create to create a category prediction model.
On the Create Category Prediction page, specify model information such as the model name, data type, commodity ID, commodity title, category ID, category name, and filter condition.
Data Type:
Commodity Data: the document data in the current application. If you select Commodity Data as the data type, make sure that the document data contains the category ID, commodity title, and category name fields.
Behavior Data: the collected click behavior data. For more information, see the topics about data collection.
Category ID: the field that represents the category ID in the application documents. The INT data type is supported. This parameter is required.
Commodity Title: the field that represents the commodity title in the application documents. The TEXT and LITERAL data types are supported. This parameter is required.
Category Name: the field that represents the category name in the application documents. The TEXT and LITERAL data types are supported. This parameter is required.
Filter Condition: the condition that is used to filter the training data for the model. This parameter is optional. If you set this parameter, make sure that the field names in the filter conditions are the same as those in the application schema. The following operators are supported: <, >, <=, >=, =, and !=. If you configure multiple filter conditions, separate the conditions with commas (,). In this case, all the conditions take effect at the same time based on the AND logical operation. The OR logical operation is not supported. Example: is_onsale > 0.
After the model is created, click Complete to go to the details page of the category prediction model.
Return to the Category Prediction Model page. The created model is in the Pending Training state. Click Start Training to train the model.
A category prediction model can be in one of the following states:
Pending Training: indicates that the model is created but not trained.
Training: indicates that the model is created and being trained.
Training Failed: indicates that the training of the model failed due to a data error.
Not Applied: indicates that the model is trained but not referenced for retrieval or sorting.
Trained and Not Passed: indicates that the model is trained but failed to pass the training.
If you have questions, submit a ticket.
Configure query analysis and sort expressions
In the left-side navigation pane, choose Search Algorithm Center > Retrieval Configuration. On the Basic Configuration page, click Query Analysis Rule Configuration in the left-side pane. On the Query Analysis Rule Configuration page, click Create to create a query analysis rule.
Configure and create the query analysis rule, as shown in the following figure.
Apply a category prediction model to rough sorting or fine sorting. In the left-side navigation pane, choose Search Algorithm Center > Sort Configuration. On the Policy Management page, click Create to create a sort policy.
To apply a category prediction model to rough sorting, perform the following steps:
On the Create Policy page, enter a policy name. Select Rough Sort from the Scope drop-down list. The first round of sorting is a rough sort. Then, select Expression from the Type drop-down list. Only expressions are supported in the console. Custom plug-ins will be supported later.
In the Sort Configuration step, select category_score() from the Scoring Characteristics drop-down list.
Select a field, set the weight, and then save the configurations.
To apply a category prediction model to fine sorting, perform the following steps:
On the Create Policy page, enter a policy name. Select Fine Sort from the Scope drop-down list. The second round of sorting is a fine sort. Then, select Expression from the Type drop-down list. Only expressions are supported in the console. Custom plug-ins will be supported later.
2. In the Sort Configuration step, select category_score(cate_id_field) from the Built-in Functions drop-down list.
3. Replace the cate_id_field variable with the category ID of the model and save the configurations.
4. View the status of the category prediction model after the model is referenced by a sort policy.
5. Perform a search test on the application of the category prediction model and view the test result. In this step, you must set the raw_query= parameter to a search query.
Call the search operation in an SDK
Set the raw_query parameter:
This parameter is used for searches based on category prediction. Search results are sorted based on category prediction only when the search query is the same as the value of the raw_query parameter.
We recommend that you set this parameter to the search query that is entered by your user. You must set this parameter in the following format:
raw_query=content // If you call an API operation to pass a search query to the parameter, the search query must be encoded by using the URL_ENCODE function. If you use an SDK to pass a search query to the parameter, the search query does not need to be encoded.
Example: The following table describes the query analysis rules of an application.
Index | Query analysis rule | Category prediction |
index1 | rule1 | No |
index2 | rule2 | Yes |
index3 | rule3 | Yes |
If a search index is configured with category prediction disabled and the request contains the raw_query parameter, the search results are not sorted based on category prediction.
If a search index is configured with category prediction disabled and the request does not contain the raw_query parameter, the search results are not sorted based on category prediction.
If a search index is configured with category prediction enabled and the request does not contain the raw_query parameter, the search results are not sorted based on category prediction:
query=index2:'search_query'
.If a search index is configured with category prediction enabled and the value of the raw_query parameter in the request is different from the search query in the search index, the search results are not sorted based on category prediction:
query=index2:'search_query'&raw_query=raw_query
.If a search index is configured with category prediction enabled and the value of the raw_query parameter in the request is the same as the search query in the search index, the search results are sorted based on category prediction:
query=index2:'search_query'&raw_query=search_query
.If a search contains multiple indexes and the request contains the raw_query parameter, the category prediction of different indexes may take effect: a.
query=index2:'index_query' AND index3:'search_query'&raw_query=search_query # The category prediction of index3 takes effect.
b.query=index2:'search_query' AND index3:'search_query'&raw_query=search_query # The category prediction of index2 preferentially takes effect. If the category prediction configuration of index2 does not apply to the search results, the category prediction of index3 takes effect.
Usage notes
You can create a maximum of five category prediction models for an application.
If a query analysis rule references a category prediction model, the data fields that are used to train the model must be included in the indexes to which the query analysis rule is applied.
Before you create a category prediction model, make sure that the fields, such as the category ID, used for category prediction are configured as attribute fields.
If a query analysis rule references a category prediction model and the request contains the category_prediction parameter, an error occurs.
To make a prediction model take effect, make sure that a query analysis rule that references the category prediction model and a sort expression that contains the category_score function are configured, and the request contains the raw_query parameter.
The category ID must be a positive number. Otherwise, a server error occurs.
Related management and control API operations: Algorithms
Advanced usage
If you configure named entity recognition (NER) in addition to category prediction in a query analysis rule, more documents are retrieved. The NER results are also used to retrieve documents. If no data matches the configured categories, one or more words in the search query are ignored to retrieve more documents, which is returned as the final search results for category prediction. For more information, see Named entity recognition.
OpenSearch allows you to intervene in trained category prediction models. The process of category prediction intervention is similar to that of query analysis intervention. For more information, see Intervention dictionaries for category prediction.