Drop-down suggestions
Drop-down suggestions are a basic feature of search services. While a user types a search query, the feature intelligently recommends candidate queries. This improves input efficiency and helps users find the content they want as quickly as possible.
Features
The drop-down suggestions feature intelligently extracts queries based on the content of your documents. Candidate queries can be retrieved by Chinese prefix, full pinyin, pinyin initials, a mix of Chinese characters and pinyin, prefixes after tokenization, and Chinese homophones or misspelled characters.
For example, the Chinese query \u8fde\u8863\u88d9\u957f\u6b3e (lianyiqun changkuan, meaning "long dress") can be retrieved in the following ways. In the examples below, Chinese characters are written as Unicode escapes (\uXXXX). Decode them into the actual Chinese characters before you enter them in a real query:
Chinese prefix:
\u8fde, \u8fde\u8863, …Full pinyin prefix:
l, li, lian, lianyi, lianyiqun, …Pinyin initials prefix:
l, ly, lyq, …Chinese characters plus pinyin:
\u8fdeyi, \u8fde\u8863qun, …Prefix after tokenization:
\u957f\u6b3e, \u957f\u6b3e\u8fde\u8863, \u8fde\u8863\u957f, …Chinese homophones or misspelled characters:
\u8fde\u8863\u7fa4, \u8054\u8c0a\u7fa4, …
In addition, you can use intervention entries to intervene in drop-down suggestion data. You can also view multiple business metrics for drop-down suggestions. For more information, see Drop-down suggestion reports.
Data sources
Drop-down suggestion data mainly comes from application documents and end-user queries. Both documents and queries can be filtered.
Generate candidate queries from application documents
Each drop-down suggestion model can use up to three fields from one application as data sources. During processing, the system selects a portion of the documents in the application (on the order of millions) and processes the selected fields in these documents based on the specified rules to generate candidate data for drop-down suggestions. The system then retains a certain amount of the data based on specific rules as candidate queries. The system supports two rules for generating candidate queries: Extract and Generate and Retain Original Value.
Extract and Generate: An analyzer trained by the Alibaba NLP team on massive amounts of natural language is used to tokenize the field content, extract meaningful terms, and combine them into candidate queries. This method aims to ensure that the generated candidate queries can retrieve the corresponding documents.
Retain Original Value: This rule does not tokenize the field content and uses it directly as a candidate query. However, if the field content exceeds the limit (30 characters), the field is truncated and the first 30 characters are retained as the candidate query. This method is suitable for application fields that do not require tokenization (such as store names, usernames, and song titles), or for candidate queries that you generate yourself and want to display as is. Therefore, we recommend that you use fields with short content and clear meanings.
When you use the Extract and Generate rule, you can also specify an extraction model for the drop-down suggestion model. After you specify it, the system uses a large language model to perform an additional round of screening on the extracted candidate queries and filter out meaningless candidates, which improves the quality of candidate queries. The extraction model is optional and takes effect only for fields that use Extract and Generate. After it takes effect, you are charged based on the number of tokens actually used by the model. For more information, see Billing overview for OpenSearch Industry Algorithm Edition.
Generate candidate queries from end-user queries
Based on the search history of all users over the past N days (7 days by default), the system comprehensively considers metrics such as query frequency, average number of returned results, historical weight, and recent query success rate to select representative queries as candidates for drop-down suggestions.
Search history feature: Drop-down suggestions also support a search history option that preferentially displays queries that the current user has searched for in the drop-down suggestions (the raw_query and user_id parameters must be passed). Search history is an extended feature of drop-down suggestions. After you enable it, you are charged training fees based on the compute hours consumed by each training. The search history feature is about to be discontinued and is no longer displayed as an option when you create a drop-down suggestion model. The following descriptions apply only to existing models for which this feature is enabled.
To disable end-user queries as a data source, you can set a query filter condition that matches nothing, such as biz_type=not_exist.
After you enable the search history feature, you must include the user_id parameter in drop-down suggestion requests to achieve a personalized experience for each user.
Search history displays only the queries that the current user has searched for, and different users are distinguished by the user_id parameter in requests. For example, if User A searched for dishwasher a few days ago, User A may see dishwasher again in drop-down suggestions today. If User B has never searched for dishwasher, the term will never appear in User B's drop-down suggestions.
Manual intervention
Drop-down suggestions support the following interventions:
Intervene in candidate query results, including blacklists and whitelists.
Set filter conditions on application documents used as the data source. After you configure filter conditions, only application documents that meet the conditions are used to generate drop-down suggestion candidates.
Parameter | Description |
Filter condition | Specify fields from the OpenSearch application schema. The filter condition applies to all document data of the application in the current service. Note:
Example: If the filter condition is status=1,level=1, only records that meet the condition are selected. |
On the Create Drop-down Suggestion Model page in the console, you can configure the following items:
Target Application: Select the application from which drop-down suggestion candidate data is sourced.
Model Name: The name must be 1 to 30 characters in length and start with a letter. It can contain uppercase and lowercase letters, digits, and underscores, and must be different from other model names.
Training Fields: Select fields from the target application as data sources, and specify Extract and Generate or Retain Original Value as the processing method for each field.
Extraction Model: Optional. The currently available extraction model is deepseek-v4-flash. After you select an extraction model, a large language model screens the extracted candidates and filters out meaningless ones. This setting takes effect only for fields that use Extract and Generate. After it takes effect, you are charged based on the number of tokens actually used by the model.
Doc Filter Condition and Query Filter Condition: filter conditions that apply to the application document data source and the end-user query data source, respectively (such as status=1 and biz_type=phone). For the rules, see the filter condition description above.
Intervene in candidate query results
Blacklist: Keywords in the blacklist use contains matching. Queries that contain a blacklisted keyword do not appear in drop-down suggestion results. Therefore, if unwanted results appear in drop-down suggestions, you can add the keywords to the drop-down suggestion blacklist to block these results.
Whitelist: When queries in the whitelist meet the recommendation conditions, they are preferentially displayed in drop-down suggestions. Therefore, if some high-quality queries are not identified or are ranked low, you can add them to the whitelist to improve drop-down suggestion performance. For details about how to configure blacklists and whitelists, click here.
Standard applications do not support drop-down suggestions. Only advanced applications support this feature.
You can create up to 10 drop-down suggestion models for a single application.
Name restriction for drop-down suggestions: A user cannot create models with the same name (including drop-down suggestion, popularity, category prediction, top search, and hint models).
Drop-down suggestions can use only indexed fields of the TEXT, SHORT_TEXT, LITERAL, or INT type from one application as data sources.
You can select up to 3 training fields for a model.
When you modify the application schema, you cannot modify fields that are used as drop-down suggestion data sources.
When a drop-down suggestion model is trained, the data volume of the application table (the sum of raw_query data and data stored in the application) must be greater than 1,000. Otherwise, model training may fail due to data completeness issues.
When you delete an application, its drop-down suggestions are also deleted.
In drop-down suggestion searches, the query parameter can be up to 30 bytes in length in UTF-8 encoding, which is up to 10 Chinese characters. Otherwise, an error is reported and no results are returned.
In drop-down suggestion searches, the hit parameter must be an integer in the range of (0, 30]. Otherwise, the default value 30 is used and an error is returned. For example, if hit is set to 0, -1, or 31, the default value 30 is used and an error is returned.
The blacklist can contain up to 500 keywords.
The whitelist can contain up to 500 queries.
If blacklist and whitelist data conflict, blocking by the blacklist takes precedence.
Changes to the blacklist and whitelist take effect in real time.
After a drop-down suggestion model is created, scheduled daily model training is enabled by default, and drop-down suggestion data is periodically updated with the scheduled training.
The training duration of drop-down suggestions depends on the data volume of the application and the system load. If training does not finish for a long time (more than half an hour), contact us.
Completion and retrieval based on Chinese homophones or misspelled characters is enabled by default. You can disable it by adding the parameter
re_search="disable"to the request.The basic drop-down suggestion feature is currently free of charge, so computing and storage resources are configured uniformly by the system. Each drop-down suggestion model has computing resources of approximately 100 QPS and storage resources of approximately 2 million candidate queries.
We recommend that you set the raw_query parameter in search requests so that the original queries entered by end users can be identified during data processing. For more information, see the search processing documentation.
If you enable the search history feature, you are charged training fees based on the compute hours consumed by each training. For more information, see Billing. (This feature is about to be discontinued and is no longer displayed as an option when you create a drop-down suggestion model.)
After you configure an extraction model, you are charged based on the number of tokens actually used by the model. For more information, see Billing.
For descriptions of the raw_query, user_id, and from_request_id parameters, click here.
Prerequisite for the high-frequency search terms feature to be enabled by default: search requests carry the raw_query parameter, or the query clause contains the default index.
Unique raw_query: The raw_query in the training promotion conditions is a parameter that must be carried in search requests. It must be a unique, non-duplicate query that returns results.
Training data for suggestion models is updated daily (T+1). Data uploaded on a given day takes effect after training on the next day.
Troubleshoot model training failures
If a drop-down suggestion model fails to be trained, perform the following steps to identify the cause and resolve the issue:
View the exception report: Go to the model details page. In the Basic Information section, check the Latest Version Status. If the status is "Training Failed" or "Data Exception", an Exception Report pop-up is displayed in this section. Hover over it to view the "Exception Details" and "Solution", and use them to identify the specific cause of the training failure.
View the completeness level and upgrade conditions: In the Data Verification section of the model details page, view the Completeness Level and the corresponding Upgrade Conditions. Adjust your data as prompted by the upgrade conditions to improve completeness, and then retrain the model.
T-1 data logic: Model training uses statistical data from the previous day (T-1). When a newly created model is trained for the first time, statistical data from the previous day is not yet available, so a "Training field does not exist" error may be reported. In this case, wait until the data is ready on the next day and then retrain the model.
Data volume requirements (L1 conditions): Model training requires that all of the following minimum data volume conditions are met:
The data volume of the data table (the sum of raw_query data and application document data) is at least 1,000.
The number of unique raw_query values is greater than 100.
Check the filter condition format: An invalid filter condition format is a common cause of training failures. Field names must be indexed fields in the application schema. Supported comparison operators are
<,>,<=,>=,=, and!=. Multiple filter conditions are combined with AND logic and must be separated by commas (,). For the complete configuration rules, see the filter condition description in the Manual intervention section above.
Recommendations
To further improve drop-down suggestion performance (such as the number of searches guided by drop-down suggestions and the click-through rate of search results), we strongly recommend that you associate drop-down suggestion requests with search requests. For the association method, see the "Associate drop-down suggestion requests with search requests" section at the end of this topic.
Select fields with concise content that are relevant to the document topic.
Use the Extract and Generate and Retain Original Value rules appropriately.
In query results, suggestions contains the results of the query, and errors indicates whether an error occurred. A non-empty errors value does not mean that suggestions is empty. Therefore, when you parse results, check whether suggestions is empty to determine whether there is no data to display.
Procedure demonstration
1. Choose Search Algorithm Center > Search Guidance > Drop-down Suggestions, and click "Create":
2. Enter a "Model Name", select "Training Fields" and the extraction method, select an "Extraction Model" (optional), enter "Filter Conditions" (optional), and click "OK".
3. On the drop-down suggestion list page, click "Train Model" to train the created model:
4. After training of the drop-down suggestion model starts, training takes about 20 to 30 minutes.
5. After the drop-down suggestion model is trained, you can test the drop-down suggestion performance. The following is a preview example of the "Retain Original Value" method:
Retain Original Value:
Click the Preview button in the upper-right corner of the model details page. In the search box of the dialog box, enter a query (for example, the letter E). Matching suggestions are displayed below (for example, "Eifini" and "ELF SACK"). On the right, you can set the User ID and Number of Results parameters.
6. Query candidates online. See the following demo. For detailed API descriptions, see Drop-down suggestion development guide.
Drop-down suggestion pages
Drop-down suggestion list page
In the OpenSearch console, choose Search Algorithm Center > Search Guidance > Drop-down Suggestions to go to the drop-down suggestion list page:
The list page displays information about drop-down suggestion models, such as "Model Name", "Created At", "Model Status", "Last Training Start Time", and "Latest Version Status" (including statuses such as Pending Training, Scheduling, Training, Trained and Passed, Training Failed, and Data Exception). In the Actions column, you can view model details, train models, and perform other operations.
Drop-down suggestion model details page
The top of the drop-down suggestion model details page is the Basic Information section, which displays the creation time, model status, and latest version status. The Preview button is in the upper-right corner of the page, and the page contains three tabs: Drop-down Suggestions, Top Searches and Hints, and Blacklist and Whitelist.
Basic Information mainly displays the model creation time, model status, last training start time, and latest version status. If the status is Training Failed or Data Exception, an "Exception Report" pop-up is displayed in this section.
Configuration Information mainly displays the training fields configured for the model and their processing methods, the extraction model, the Doc filter condition, the Query filter condition, the blacklist and whitelist, and scheduled tasks. You can click the Configure button in the upper-right corner to modify these settings.
Data Verification mainly displays the data completeness and completeness level for model training.
Training History mainly displays the training records of the model.
Core metrics
You can select different time ranges to display the core metrics of the drop-down suggestion model in tables and line charts.
Note: For the meanings of specific metrics, see Drop-down suggestion reports.
Drop-down suggestion SDK demo
API:
GET v3/openapi/suggestions/{suggestion_name}/actions/search?hit=10&query={your_query}&re_search=homonym&user_id=xxxMaven dependency for the Java SDK:
<dependency>
<groupId>com.aliyun.opensearch</groupId>
<artifactId>aliyun-sdk-opensearch</artifactId>
<version>4.0.0</version>
</dependency>Related link: Release notes
Sample code:
package com.example.opensearch;
import com.aliyun.opensearch.OpenSearchClient;
import com.aliyun.opensearch.SuggestionClient;
import com.aliyun.opensearch.sdk.generated.OpenSearch;
import com.aliyun.opensearch.sdk.generated.commons.OpenSearchClientException;
import com.aliyun.opensearch.sdk.generated.commons.OpenSearchException;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.nio.charset.Charset;
public class SuggestDemo {
static private final String accesskey = "Enter your AccessKey ID";
static private final String secret = "Enter your AccessKey secret";
static private final String host = "Enter the host of the region where the application associated with the drop-down suggestion model resides";
OpenSearch openSearch;
OpenSearchClient openSearchClient;
static private final byte hits = 8; //Maximum number of drop-down suggestions to return
static private final String suggestionName = "Enter the drop-down suggestion name"; //Enter the drop-down suggestion name
@Before
public void setUp() {
//Initialize the openSearch object
openSearch = new OpenSearch(accesskey, secret, host);
openSearchClient = new OpenSearchClient(openSearch);
}
@Test
public void TestEnv() {
//View the file encoding and default encoding
System.out.println(String.format("file.encoding: %s", System.getProperty("file.encoding")));
System.out.println(String.format("defaultCharset: %s", Charset.defaultCharset().name()));
//Create a drop-down suggestion object
SuggestionClient suggestionClient = new SuggestionClient("app_name", suggestionName, openSearchClient);
String query = "Enter the query";
try {
SuggestParams suggestParams = new SuggestParams();
suggestParams.setQuery(query); //Set the query
suggestParams.setHits(10); //Set the maximum number of drop-down suggestions to return
suggestParams.setUserId("12345678"); //Set user_id
//Completion and retrieval based on Chinese homophones or misspelled characters is enabled by default. You can adjust it by adding the re_search parameter to the request.
//ReSearch.findByValue(1) disables the feature. ReSearch.findByValue(0) or omitting the parameter enables it.
suggestParams.setReSearch(ReSearch.findByValue(1));
SearchResult result = suggestionClient.execute(suggestParams);
System.out.println(result); //Print the retrieved results
} catch (OpenSearchException e) {
e.printStackTrace();
} catch (OpenSearchClientException e) {
e.printStackTrace();
}
}
@After
public void clean() {
openSearch.clear();
}
}For details about the Java SDK for drop-down suggestions, see Drop-down suggestion demo.
Sample retrieval results:
{
"request_id": "159851481919726888064081",
"searchtime": 0.006246,
"suggestions": [
{
"suggestion": "skirt trendy"
},
{
"suggestion": "skirt petite dress"
},
{
"suggestion": "skirt polka dot dress"
},
{
"suggestion": "skirt youthful"
},
{
"suggestion": "skirt polka dot"
},
{
"suggestion": "skirt petite"
},
{
"suggestion": "skirt petite polka dot"
}
]
}Note: The request ID returned in the retrieval results can be used to associate search requests.
Associate drop-down suggestion requests with search requests
Associating drop-down suggestion requests with search requests benefits your business in the following ways:
You can calculate metrics that measure the effect of drop-down suggestions on search, such as page views (PVs) of searches guided by drop-down suggestions, the click-through rate of guided searches, and the no-result or few-result rate of guided searches. For more metrics, see Drop-down suggestion reports.
Based on the associated request data, you can obtain data such as drop-down suggestion click results to optimize the drop-down suggestion ranking model and improve the effectiveness of searches guided by drop-down suggestions.
Association method:
In an OpenSearch app search request, if the request is guided by drop-down suggestions, include the parameter
from_request_id={from_request_id}in the search request. from_request_id indicates where the search request was guided from. If the current query comes from a recommendation list of a feature such as drop-down suggestions, hot words, or hints, you can assign the request_id of the request for that recommendation list to this parameter. By associating this guidance event, you can calculate metrics for the upstream feature, measure its effectiveness, and obtain a basis for optimizing the feature. This parameter is also described in the search processing documentation.
Example:
The request ID in the results returned by the drop-down suggestion API is 159851481919726888064081. To associate a search request with it, refer to the following code:
SearchParams searchParams = new SearchParams(config);
searchParams.setQuery("title:'skirt petite'"); //Guided by drop-down suggestions
///Add the from_request_id parameter
Map<String, String> customParam =new HashMap<>();
customParam.put("from_request_id","159851481919726888064081");
searchParams.setCustomParam(customParam);
//Execute the query and return the data object
SearchResult execute = searcherClient.execute(searchParams);
//Return the query data as a string
String result = execute.getResult();
System.out.println(result);