All Products
Search
Document Center

Usage of the category prediction

Last Updated: Sep 09, 2021

Flowchart

1

Note: To make the category prediction take effect, all the configurations in the preceding figure must be complete.

Procedure

Create and train a category prediction model

1.In the left-side navigation pane, choose Search Algorithm Center > Sort Configuration. On the Policy Management page, click Category Prediction in the left-side pane. On the Category Prediction page, click Create to create a category prediction model.

1

2.Set the required parameters, such as the Model Name, Sample Set, Category ID, Entity Title, Category Name, and Filter Condition parameters.

2
  • Entity Data: the document data in the current application. If you select Entity Data from the Sample Set drop-down list, make sure that the document data contains the category ID, entity title, and category name fields.

  • Behavior Data: the collected click behavior data. For more information, see the topics about data collection.

3

3.Click Activate to activate the behavior data collection feature.

5

4.Wait until the behavior data collection feature is activated.

6

5.Set the required parameters, such as the Category ID, Entity Title, and Category Name parameters.

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

  • Entity Title: the field that represents the entity 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. The following operators are supported: <, >, =, !=,>=, and <=. Separate multiple conditions with a comma (,). This parameter is optional.

Remarks: the remarks of the model. This parameter is optional.

6.After the model is created, return to the Category Prediction page. The created model is in the Pending Training state. Click Start Training to train the model.

9

A category prediction model can be in one of the following state:

  • 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 Referenced: indicates that the model is trained but is not referenced for retrieval or sorting.

Configure query analysis and sort expressions

1.In the left-side navigation pane, choose Search Algorithm Center > Retrieval Configuration. On the Basic Configuration page, click Query Analysis Rule Management in the left-side pane. On the Query Analysis Rule Management page, click Create to create a query analysis rule.

9

2.Configure and create the query analysis rule as shown in the following figure.

10

3.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.

11

To apply a category prediction model to rough sorting, perform the following steps:

1.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 soon.

11

2.In the Sort Configuration step, select category_score() from the Scoring Characteristics drop-down list.

12

3.Select a field, set the score weight, and then save the configurations.

13

To apply a category prediction model to fine sorting, perform the following steps:

1.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 soon.

14

2.In the Sort Configuration step, select category_score(cate_id_field) from the Built-in Functions drop-down list.

15

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

16

4.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.

17

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 users. 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

  1. 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.

  2. 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.

  3. 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'.

  4. 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.

  5. 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.

  6. 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.

Considerations

  • 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.

Advanced usage

  1. 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 Entity recognition.

  2. OpenSearch allows you to intervene in 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.