Use the category prediction feature

Updated at:

Process overview

Note: Category prediction takes effect only after all items shown in the figure are configured.

Process demonstration

Create and train a category prediction model

  1. In the left-side navigation pane, choose Sort Configuration > Category Prediction. On the page that appears, click Create to start the creation process.

  2. In the creation process, specify information such as the model name, data type, product ID, product title, category ID, category name, and filter condition.

    In this example, set Target Application to keep_algo_metrics_enh_vpc under the Ha3 engine, set Model Name to test_categroy_model, and select item data for Data Type. In the field mappings, select id for Product ID, title for Product Title, cate_id for Category ID, and title for Category Name.

    • Data Type:

      • Item data refers to the existing document data in the current application. The application must already store data for the following three fields: category ID, item title, and category name.

      • Behavioral data refers to the uploaded data collected on user click behavior. For more information, see Data collection.

    • Category ID: the field that represents the category ID in the application. The INT type is supported. This parameter is required.

    • Item Title: the field that represents the item title in the application. The TEXT and LITERAL types are supported. This parameter is required.

    • Category Name: the field that represents the category name in the application. The TEXT and LITERAL types are supported. This parameter is required.

    • Filter Condition: optional. If you specify a filter condition, make sure that the field names in the filter condition are field names in the application schema. The following operators are supported in filter conditions: <, >, <=, >=, =, and !=. Multiple filter conditions are evaluated with an AND relationship and must be separated by commas (,). The comma indicates a logical AND. Logical OR is not supported. Example filter condition: is_onsale > 0.

  3. After the configuration is complete, click Complete to go to the details page of the category prediction model.

  4. After the model is created, return to the Category Prediction page. The model is in the To Be Trained state. Click Start Training to train the model with data.

Training states of category prediction models:

  • To Be Trained: The model has just been created but has not been trained with data.

  • Training: The model has been created and has entered training, but training is not yet complete.

  • Training Failed: Model training failed due to data errors.

  • Not Applied: The model has been trained successfully but has not been applied in the retrieval or sorting features.

Configure query analysis and sort expressions

  1. In the left-side navigation pane, choose Retrieval Configuration > Query Analysis. On the page that appears, click Create to start the creation process.

  2. In the creation process, edit and create the rule by following the process shown in the following figure.

  3. Then, apply the category prediction model in rough sort or fine sort. In the left-side navigation pane, choose Sort Configuration > Policy Management. On the page that appears, click Create to start the creation process.

The following process applies the model to basic sort:

  1. In the creation process, enter a policy name, select basic sort (the first round, rough sort), and then select a type. Currently, only expressions can be configured in the console. Custom plug-ins will be supported in the future.

  2. Then, in the sort configuration, select category_score() under scoring features.

  3. Configure the search field and the weight of the scoring feature, and save the configuration.

    For example, select category_score() as the scoring feature, set the search field to is_onsale, and set the weight to 13.

The following process applies the model to business sort:

  1. In the creation process, enter a policy name, select business sort (the second round, fine sort), and then select a type. Currently, only expressions can be configured in the console. Custom plug-ins will be supported in the future.

    From the Target Application drop-down list, select the application for which you want to configure a sort policy. The policy name must be 1 to 30 characters in length, must start with a letter, and can contain uppercase and lowercase letters, digits, and underscores. The name must be different from the names of other policies of the same type.

  2. Then, in the sort configuration, select category_score(cate_id_field) under built-in functions.

  3. Replace cate_id_field with the category ID of the model and save the configuration.

    In the text editing area of the sort configuration, enter the expression category_score(cate_id), replace cate_id with the actual category ID, and then click Complete.

  4. Status after the model is applied.

    After the model is applied in query analysis and policy management, the Last Training Status column of the model in the model management list displays Applied.

  5. To view the effect in a search test, add the parameter raw_query=search query.

    On the search test page, select the application test_1 and Online Application, enter default:'sticky rice' in the query field, and set the clause configuration to config=start:0;hit:10;format:fulljson. In the parameter area, you can see that the raw_query value is sticky rice.

Call the query operation by using an SDK

Set the query parameter raw_query:

  • This parameter is used for category prediction queries. The category prediction configured in query analysis is queried only when the search query matches the content of raw_query.

  • We recommend that you set this parameter to the original search query entered by the end user. Format:

    raw_query=content
    //When passed through the API, content must be URL-encoded (URL_ENCODE). Encoding is not required when you use an SDK. content is the original search query.

    Example: Assume that the query analysis rules of an application are configured as shown in the following table:

Index name

Query analysis rule name

Category prediction configured

index1

rule1

No

index2

rule2

Yes

index3

rule3

Yes

  1. If category prediction is not configured for the queried index and the request contains raw_query, category prediction is not queried and the query returns results normally.

  2. If category prediction is not configured for the queried index and the request does not contain raw_query, category prediction is not queried and the query returns results normally.

  3. If category prediction is configured for the queried index and the request does not contain raw_query, category prediction is not queried and the query returns results normally: a. query=index2:'search_query'

  4. If category prediction is configured for the queried index and the request contains raw_query, but raw_query differs from the search query for the queried index, category prediction is not queried and the query returns results normally: a. query=index2:'search_query'&raw_query=raw_query

  5. If category prediction is configured for the queried index and the request contains raw_query that is the same as the search query for the queried index, category prediction is queried and the query returns results normally: a. query=index2:'search_query'&raw_query=search_query

  6. If the query involves multiple indexes and the query contains raw_query: a. query=index2:'index_query' AND index3:'search_query'&raw_query=search_query       # Category prediction takes effect on index3.b. query=index2:'search_query' AND index3:'search_query'&raw_query=search_query      # Category prediction preferentially takes effect on index2. If no result is returned, category prediction on index3 is queried.

Usage notes

  • You can create up to five category prediction models for a single application.

  • The training fields of a category prediction model configured in a query analysis rule must be included in the index to which the query analysis rule is applied.

  • Before you create a category prediction model, make sure that the relevant field used by category prediction (category ID) has been added to the list of attribute fields.

  • If category prediction is configured in query analysis and the query request specifies the category_prediction parameter, the query returns an error.

  • A category prediction model takes effect only if query analysis (category prediction) and a sort expression (category_score) are both configured, and the query carries the fixed parameter (raw_query).

  • If you select behavioral data when you create a model, the category prediction model predicts only queries that were clicked within the last 14 days. In other words, if a query was not clicked, no category prediction result is returned.

  • Category IDs must be positive numbers and cannot be negative. Otherwise, the query returns the error server error.

  • To train a category prediction model, the number of unique queries in the most recent day must be greater than 100. The number of unique queries indicates the number of successful search requests that include the raw_query parameter.

  • Related management API operations: Algorithm-related operations

  • Do not select the "Query Analysis - Text Vectorization" feature. Text vectorization has a default query policy that triggers multi-channel queries. The query policy includes a result merge sort, which does not support obtaining the sort scores of category prediction.

Troubleshoot model training failures

If a category prediction model fails to be trained, perform the following steps to identify and resolve the cause:

  1. View the exception report: On the model details page, check the Latest Version Status. If the status indicates an exception, view the Exception Report to locate the specific cause of the training failure.

  2. View the completeness level and upgrade conditions: Check the Completeness Level and the corresponding Upgrade Conditions. Adjust the data based on the upgrade conditions to improve completeness and meet the training requirements.

  3. T-1 data logic (a "field does not exist" error during the first training of a newly created model): Model training uses the statistical data of the previous day (T-1). If the model was created on the current day, no data from the previous day is available yet, so the first training may report a "training field does not exist" error. This is normal. Wait until the data is ready the next day and then start training again.

  4. Data volume requirements (L1 conditions): Training requires the following data volume conditions to be met:

    • The data table contains at least 1,000 data records.

    • The number of unique queries in the most recent day is greater than 100. The number of unique queries is the number of successful search requests that include the raw_query parameter.

  5. Filter condition format: If a filter condition is configured, the field names must be field names in the application schema. Multiple conditions are evaluated with an AND relationship and must be separated by commas (,). An invalid format causes training to fail.

Advanced usage

  1. Using category prediction together with the entity recognition feature in a query rule can expand the retrieval scope of category prediction. Query analysis uses the entity recognition results: if category prediction returns no result for the original query, query analysis drops terms from the query based on specific rules, queries category prediction again, and returns the category prediction result obtained after term dropping as the final category prediction result. For more information, see the entity recognition documentation.

  2. Manual intervention is supported for trained category prediction models. The intervention process is similar to that of query analysis intervention. For the steps to perform category prediction intervention, see the documentation.