All Products
Search
Document Center

OpenSearch:Create a custom sorting model

Last Updated:Jul 22, 2024

This topic describes how to create a custom sorting model by using OpenSearch Industry Algorithm Edition.

Procedure

  1. On the Feature Management page of the OpenSearch Industry Algorithm Edition console, create field features. In this example, the system_item table is used. If the required features are not listed in the system_item table, you can register them in an external MaxCompute table. For example, create the following features for the title field: custom_title, custom_title_match, and custom_title_len. Create features for other fields in a similar way. You can add features based on your business requirements. In this example, the fields in a click-through rate (CTR) model are used.

image.png

  1. Use the built-in features listed in the system_internal table in combination with the field features created in Step 1 to perform feature generation.

In this example, the common feature generation process of the CTR model is used. You can call the CreateFunctionResource operation to register multiple features at a time.

Set the ResourceType parameter to feature_generator, and specify the following information for the Data parameter. The input features whose names start with custom_ must be prepared in advance. You can create such features on the Feature Management page in Step 1.

[
  {
    "input": {
      "features": [
        {
          "type": "user",
          "name": "system_raw_q_ultra"
        },
        {
          "type": "item",
          "name": "system_item_id"
        }
      ]
    },
    "generator": "combo",
    "output": "comb_q_nid"
  },
  {
    "input": {
      "features": [
        {
          "type": "user",
          "name": "system_user_id"
        },
        {
          "type": "item",
          "name": "system_item_id"
        }
      ]
    },
    "generator": "combo",
    "output": "comb_uid_nid"
  },
  {
    "input": {
      "features": [
        {
          "type": "user",
          "name": "system_user_id"
        },
        {
          "type": "item",
          "name": "custom_tags"
        }
      ]
    },
    "generator": "combo",
    "output": "comb_uid_tags"
  },
  {
    "input": {
      "features": [
        {
          "type": "user",
          "name": "system_raw_q_ultra"
        },
        {
          "type": "item",
          "name": "custom_tags"
        }
      ]
    },
    "generator": "combo",
    "output": "comb_q_tags"
  },
  {
    "input": {
      "features": [
        {
          "type": "user",
          "name": "system_exp_time"
        }
      ]
    },
    "generator": "id",
    "output": "exp_time"
  },
  {
    "input": {
      "features": [
        {
          "type": "user",
          "name": "system_terms2"
        }
      ]
    },
    "generator": "id",
    "output": "terms2"
  },
  {
    "input": {
      "features": [
        {
          "type": "user",
          "name": "system_raw_q_ultra"
        }
      ]
    },
    "generator": "id",
    "output": "raw_q_ultra"
  },
  {
    "input": {
      "features": [
        {
          "type": "user",
          "name": "system_user_id"
        }
      ]
    },
    "generator": "id",
    "output": "user_id"
  },
  {
    "input": {
      "features": [
        {
          "type": "item",
          "name": "system_item_id"
        }
      ]
    },
    "generator": "id",
    "output": "item_id"
  },
  {
    "input": {
      "features": [
        {
          "type": "item",
          "name": "custom_description"
        }
      ]
    },
        "generator": "id",
        "output": "description"
    },
    {
        "input": {
            "features": [
                {
                    "type": "item",
                    "name": "custom_desc_len"
                }
            ]
        },
        "generator": "id",
        "output": "desc_len"
    },
    {
        "input": {
            "features": [
                {
                    "type": "item",
                    "name": "custom_title"
                }
            ]
        },
        "generator": "id",
        "output": "title"
    },
    {
        "input": {
            "features": [
                {
                    "type": "item",
                    "name": "custom_title_len"
                }
            ]
        },
        "generator": "id",
        "output": "title_len"
    },
    {
        "input": {
            "features": [
                {
                    "type": "item",
                    "name": "custom_category"
                }
            ]
        },
        "generator": "id",
        "output": "category"
    },
    {
        "input": {
            "features": [
                {
                    "type": "item",
                    "name": "custom_tags"
                }
            ]
        },
        "generator": "id",
        "output": "tags"
    },
    {
        "input": {
            "features": [
                {
                    "type": "item",
                    "name": "system_all_nid_ctr_30"
                }
            ]
        },
        "generator": "id",
        "output": "all_nid_ctr_30"
    },
    {
        "input": {
            "features": [
                {
                    "type": "item",
                    "name": "system_all_nid_ctr_7"
                }
            ]
        },
        "generator": "id",
        "output": "all_nid_ctr_7"
    },
    {
        "input": {
            "features": [
                {
                    "type": "item",
                    "name": "system_all_nid_ctr_1"
                }
            ]
        },
        "generator": "id",
        "output": "all_nid_ctr_1"
    },
    {
        "input": {
            "features": [
                {
                    "type": "item",
                    "name": "system_all_nid_pv_30"
                }
            ]
        },
        "generator": "id",
        "output": "all_nid_pv_30"
    },
    {
        "input": {
            "features": [
                {
                    "type": "item",
                    "name": "system_all_nid_pv_7"
                }
            ]
        },
        "generator": "id",
        "output": "all_nid_pv_7"
    },
    {
        "input": {
            "features": [
                {
                    "type": "item",
                    "name": "system_all_nid_pv_1"
                }
            ]
        },
        "generator": "id",
        "output": "all_nid_pv_1"
    },
    {
        "input": {
            "features": [
                {
                    "type": "item",
                    "name": "system_all_nid_ipv_30"
                }
            ]
        },
        "generator": "id",
        "output": "all_nid_ipv_30"
    },
    {
        "input": {
            "features": [
                {
                    "type": "item",
                    "name": "system_all_nid_ipv_7"
                }
            ]
        },
        "generator": "id",
        "output": "all_nid_ipv_7"
    },
    {
        "input": {
            "features": [
                {
                    "type": "item",
                    "name": "system_all_nid_ipv_1"
                }
            ]
        },
        "generator": "id",
        "output": "all_nid_ipv_1"
    },
    {
        "input": {
            "features": [
                {
                    "role": "map",
                    "type": "item",
                    "name": "custom_title_match"
                },
                {
                    "role": "key",
                    "type": "user",
                    "name": "system_terms2"
                }
            ]
        },
        "generator": "lookup",
        "output": "term_title_match"
    },
    {
        "input": {
            "features": [
                {
                    "role": "map",
                    "type": "item",
                    "name": "custom_desc_match"
                },
                {
                    "role": "key",
                    "type": "user",
                    "name": "system_terms2"
                }
            ]
        },
        "generator": "lookup",
        "output": "term_desc_match"
    },
    {
        "input": {
            "features": [
                {
                    "role": "map",
                    "type": "item",
                    "name": "custom_tags_match"
                },
                {
                    "role": "key",
                    "type": "user",
                    "name": "system_terms2"
                }
            ]
        },
        "generator": "lookup",
        "output": "term_tags_match"
    },
    {
        "input": {
            "features": [
                {
                    "role": "map",
                    "type": "item",
                    "name": "system_qterm_match_decay"
                },
                {
                    "role": "key",
                    "type": "user",
                    "name": "system_terms2"
                }
            ]
        },
        "generator": "lookup",
        "output": "term_os_kw_match"
    },
    {
        "input": {
            "features": [
                {
                    "type": "item",
                    "name": "system_query_cnt"
                }
            ]
        },
        "generator": "id",
        "output": "opensearch_query_cnt"
    },
    {
        "input": {
            "features": [
                {
                    "type": "item",
                    "name": "system_qterm_cnt"
                }
            ]
        },
        "generator": "id",
        "output": "opensearch_qterm_cnt"
    },
    {
        "input": {
            "features": [
                {
                    "role": "map",
                    "type": "item",
                    "name": "system_query_ctr_decay"
                },
                {
                    "role": "key",
                    "type": "user",
                    "name": "system_raw_q_ultra"
                }
            ]
        },
        "generator": "lookup",
        "output": "os_q_ctr_decay"
    },
    {
        "input": {
            "features": [
                {
                    "role": "map",
                    "type": "item",
                    "name": "system_qterm_ctr_decay"
                },
                {
                    "role": "key",
                    "type": "user",
                    "name": "system_terms2"
                }
            ]
        },
        "generator": "lookup",
        "output": "os_term_ctr_decay"
    },
    {
        "input": {
            "features": [
                {
                    "role": "map",
                    "type": "item",
                    "name": "system_query_ctr_decay"
                },
                {
                    "role": "key",
                    "type": "user",
                    "name": "system_raw_q_ultra"
                }
            ]
        },
        "generator": "lookup",
        "output": "os_q_ctr_decay_nokey"
    },
    {
        "input": {
            "features": [
                {
                    "role": "map",
                    "type": "item",
                    "name": "system_qterm_ctr_decay"
                },
                {
                    "role": "key",
                    "type": "user",
                    "name": "system_terms2"
                }
            ]
        },
        "generator": "lookup",
        "output": "os_term_ctr_decay_nokey"
    },
    {
        "input": {
            "features": [
                {
                    "type": "item",
                    "name": "system_query_seq_decay"
                }
            ]
        },
        "generator": "id",
        "output": "os_q_seq_decay"
    },
    {
        "input": {
            "features": [
                {
                    "type": "item",
                    "name": "system_qterm_seq_decay"
                }
            ]
        },
        "generator": "id",
        "output": "os_term_seq_decay"
    },
    {
        "input": {
            "features": [
                {
                    "role": "query",
                    "type": "user",
                    "name": "system_terms2"
                },
                {
                    "role": "title",
                    "type": "item",
                    "name": "system_qterm_seq_decay"
                }
            ],
            "method": "query_common_ratio"
        },
        "generator": "overlap",
        "output": "os_qterm_q_common_ratio"
    },
    {
        "input": {
            "features": [
                {
                    "role": "query",
                    "type": "user",
                    "name": "system_terms2"
                },
                {
                    "role": "title",
                    "type": "item",
                    "name": "system_qterm_seq_decay"
                }
            ],
            "method": "title_common_ratio"
        },
        "generator": "overlap",
        "output": "os_qterm_title_common_ratio"
    },
    {
        "input": {
            "features": [
                {
                    "role": "query",
                    "type": "user",
                    "name": "system_terms2"
                },
                {
                    "role": "title",
                    "type": "item",
                    "name": "custom_title"
                }
            ],
            "method": "query_common_ratio"
        },
        "generator": "overlap",
        "output": "title_q_common_ratio"
    },
    {
        "input": {
            "features": [
                {
                    "role": "query",
                    "type": "user",
                    "name": "system_terms2"
                },
                {
                    "role": "title",
                    "type": "item",
                    "name": "custom_title"
                }
            ],
            "method": "title_common_ratio"
        },
        "generator": "overlap",
        "output": "title_title_common_ratio"
    },
    {
        "input": {
            "features": [
                {
                    "role": "query",
                    "type": "user",
                    "name": "system_terms2"
                },
                {
                    "role": "title",
                    "type": "item",
                    "name": "custom_description"
                }
            ],
            "method": "query_common_ratio"
        },
        "generator": "overlap",
        "output": "desc_q_common_ratio"
    },
    {
        "input": {
            "features": [
                {
                    "role": "query",
                    "type": "user",
                    "name": "system_terms2"
                },
                {
                    "role": "title",
                    "type": "item",
                    "name": "custom_description"
                }
            ],
            "method": "title_common_ratio"
        },
        "generator": "overlap",
        "output": "desc_title_common_ratio"
    },
    {
        "input": {
            "features": [
                {
                    "type": "user",
                    "name": "system_term_seq_length"
                }
            ],
            "dimension": 1
        },
        "generator": "raw",
        "output": "term_seq_length"
    }
]

After the features are created, you can configure each feature on the corresponding feature description page.

image.png

The features are generated. To use the features, you must specify the features in the model code.

  1. Create a model description.

After you complete the steps that are described in the Get started with custom sorting models section of the "Developer guide for custom sorting models" topic, you can modify the features that you want to use. In most cases, the embedding_colums parameter is used.

image.png

  1. Specify a feature description and model description when you create a custom sorting model.

image.png

  1. After the custom sorting model is created and trained, you can use the custom sorting model in Cava in the same way as the CTR model. You can run an A/B test to test the model performance before you publish the model.