Intervention in Named Entity Recognition (NER) allows you to modify recognition results and adjust entity priorities. If the default NER results are inaccurate, you can use an intervention dictionary for NER to correct them.
Key concepts
NER intervention
You can create an intervention dictionary for NER and apply it in query analysis to modify NER results. Because semantic entities are closely tied to the analyzer, you must select an analyzer when you create an intervention dictionary. During query analysis configuration, you can use the dictionary only if its analyzer matches the analyzer used by the index.
-
When you create an intervention dictionary for NER, tailored model analyzers can be configured only for exclusive applications.
-
You can choose between a full match and a partial match for entries in the dictionary.
-
Each intervention dictionary can contain up to 1000 intervention entries.
-
When you add an intervention entry, the intervention query must be normalized by converting uppercase letters to lowercase and full-width characters to half-width characters. Otherwise, the entry can be added but will not take effect during searches.
-
When you configure an intervention dictionary for NER in query analysis, you can choose whether to ignore spaces in the search query.
-
In some cases, such as after an analyzer upgrade, the tokenization result for a search query may differ from the one generated when the intervention entry was created. If this happens, the intervention will fail, and the search will return error code 6612. If you receive this error, you must modify the intervention entry in the console.
Entity priority intervention
OpenSearch provides a default entity priority configuration that you can adjust based on your business needs. These adjustments affect the query rewrite rules.
-
If a search query matches multiple intervention entries, the entry with the higher match weight takes precedence.
-
If the match weights are the same, the entry that appears earlier in the query takes precedence.
-
If the match positions are also the same, the entry with more semantic terms takes precedence.
-
When you configure entity priorities, the High and Medium priority levels cannot both be empty. Otherwise, the NER-based query rewrite feature will fail.
-
Each entity can have only one priority level.
Usage
You can manually correct NER results by creating an intervention dictionary. The process typically involves four steps:
-
Create an intervention dictionary for NER. Navigate to
Search Algorithm Center > Retrieval Configuration > Dictionary Management. On the page that appears, click Create in the upper-right corner. Select a dictionary type and specify a name. After the dictionary is created, it appears in the dictionary list. -
Add and manage intervention entries. After the dictionary is created, click its name or click Manage in the list to go to its details page. On this page, you can add and manage intervention entries.
-
Use the intervention dictionary. After you create the dictionary and add entries to it, you can select it in your application's query analysis.
-
Test and deploy the dictionary. After applying the dictionary to a query analysis rule, test the search performance to ensure it meets your expectations before deploying it to your production environment.
Walkthrough
Scenario: An e-commerce shopping guide service uses a query analysis rule with the NER feature enabled in its OpenSearch application. However, a bad case in the production environment required intervention.
Bad case: For the user query "Chanel cushion", the default Named Entity Recognition (NER) classifies "Chanel" as a "regular term" and "cushion" as a "material". As a result, the query is rewritten as title:'cushion' RANK title:'Chanel'. However, from a business perspective, "Chanel" is not a regular term. Problem diagnosis: "Chanel" is a business-specific proper noun that requires NER intervention.
Solution: Create a new intervention dictionary for NER and apply it to the query analysis rule used in the production environment.
Procedure:
-
In the console, go to Search Algorithm Center > Retrieval Configuration > Dictionary Management, and then click Create.
Enter a Name. For Dictionary Type, select Entity Recognition. For Analyzer Type, select built-in analyzer/custom analyzer based on the analyzer configured in your query analysis. The Associated Analyzer drop-down list automatically filters and shows compatible analyzers. Note that NER can be configured only for analyzers of the e-commerce tokenization type.
If the index configured in query analysis uses a tailored model analyzer, set Analyzer Type to tailored model analyzer. For Instance, choose Ha3 engine and the corresponding Application Name. Ensure the Associated Analyzer matches the one in your query analysis configuration.
-
In the newly created intervention dictionary, add an intervention entry. Enter the query and modify the system's recognition result.
Original incorrect recognition result:
For the query
Chanel cushion, the system identifies Chanel as a regular term and cushion as a material. Result after intervention: For the queryChanel cushion, after you click Get System Recognition Result, the system identifies the entity Chanel as a brand and cushion as a material.If the intervention dictionary is based on a tailored model analyzer, you must select the analyzer version when adding an intervention entry. This version corresponds to the model version used by the tailored retrieval model.
ImportantFor Intervention Type, full match means the intervention applies only when the input query exactly matches the intervention query. partial match means the intervention applies when the input query contains the intervention query.
-
On the query analysis page, apply the newly created intervention dictionary to a non-production query analysis rule to test its effect.
In the Query Analysis Configuration list, find the target non-production query analysis rule and click Configure in the Actions column. On the configuration page, select the Entity Recognition checkbox. From the intervention dictionary drop-down list, select dic_entity. Set Ignore Spaces to Yes, and then click OK.
ImportantThe ignore spaces feature specifies whether to ignore spaces in a query when you perform an NER intervention. This feature is disabled by default. For example: If the input query is "dress women" and the intervention entry is "dresswomen", the intervention is applied if you select "Yes". If you select "No", no intervention is performed.
-
The search test works as expected: (Documents about "Chanel cushion" were retrieved.)
On the search test page, enter
title:'Chanel cushion'in the query field and set the qp parameter totest_entity. After the search, the actual query is rewritten as(name:"Chanel" AND name:"cushion"). This indicates that the query analysis plugin has taken effect and successfully returned one matching document: "Chanel New Water-Gel Jelly Cushion Foundation BB Cream".