{"id":2024,"date":"2022-03-25T18:45:00","date_gmt":"2022-03-25T18:45:00","guid":{"rendered":"https:\/\/salarydistribution.com\/machine-learning\/2022\/03\/25\/improve-search-accuracy-with-spell-checker-in-amazon-kendra\/"},"modified":"2022-03-25T18:45:00","modified_gmt":"2022-03-25T18:45:00","slug":"improve-search-accuracy-with-spell-checker-in-amazon-kendra","status":"publish","type":"post","link":"https:\/\/salarydistribution.com\/machine-learning\/2022\/03\/25\/improve-search-accuracy-with-spell-checker-in-amazon-kendra\/","title":{"rendered":"Improve search accuracy with Spell Checker in Amazon Kendra"},"content":{"rendered":"<div id=\"\">\n<p><a href=\"https:\/\/aws.amazon.com\/kendra\/\" target=\"_blank\" rel=\"noopener noreferrer\">Amazon Kendra<\/a> is an intelligent search service powered by machine learning. You can receive spelling suggestions for misspelled terms in your queries by utilizing the <a href=\"https:\/\/aws.amazon.com\/about-aws\/whats-new\/2022\/03\/amazon-kendra-spell-checker-queries\/\" target=\"_blank\" rel=\"noopener noreferrer\">Amazon Kendra Spell Checker<\/a>. Spell Checker helps reduce the frequency of queries returning irrelevant results by providing spelling suggestions for unrecognized terms.<\/p>\n<p>In this post, we explore how to use Amazon Kendra Spell Checker on the <a href=\"http:\/\/aws.amazon.com\/console\" target=\"_blank\" rel=\"noopener noreferrer\">AWS Management Console<\/a>, as well as how to enable Spell Checker in an Amazon Kendra-powered search application through the <a href=\"http:\/\/aws.amazon.com\/cli\" target=\"_blank\" rel=\"noopener noreferrer\">AWS Command Line Interface<\/a> (AWS CLI) and AWS SDK.<\/p>\n<h2>Use Amazon Kendra Spell Checker on the console<\/h2>\n<p>You can automatically receive spelling suggestions for your misspelled Amazon Kendra queries when querying through the console.<\/p>\n<p>On the Amazon Kendra console, choose your desired index, then choose <strong>Search indexed content<\/strong> in the navigation pane. Make sure that the selected index has ingested documents; in this post, we use the sample AWS documentation found in the <strong>Data sources<\/strong> section of the navigation pane.<\/p>\n<p>On the Amazon Kendra search console, simply submit a query as you usually would. Misspelled terms in the query are substituted with suggested terms in the \u201cDid you mean\u201d section of the search console.<\/p>\n<p><a href=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2022\/03\/25\/ML-8602-image001.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-34609\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2022\/03\/25\/ML-8602-image001.jpg\" alt=\"\" width=\"1676\" height=\"766\"><\/a><\/p>\n<p>Choosing the suggested query submits a new query with the corrected spelling.<\/p>\n<p><a href=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2022\/03\/25\/ML-8602-image003.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-34610\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2022\/03\/25\/ML-8602-image003.jpg\" alt=\"\" width=\"1676\" height=\"732\"><\/a><\/p>\n<p>As you can see, the query results provided through the suggested query are significantly more relevant, thanks to Spell Checker!<\/p>\n<h2>Use Amazon Kendra Spell Checker in search applications<\/h2>\n<p>Search applications powered by Amazon Kendra can quickly and easily enable Spell Checker through the AWS CLI or AWS SDK, which we walk through in this section. Additionally, we go over an example of how to process the Spell Checker response.<\/p>\n<h3>AWS CLI<\/h3>\n<p>Let\u2019s look at how AWS CLI users can opt in to Amazon Kendra Spell Checker to receive spelling suggestions for misspelled query terms. We use the AWS CLI to query Amazon Kendra as usual, with only one small change: we include the <code>--spell-correction-configuration IncludeQuerySpellCheckSuggestions=true<\/code> argument:<\/p>\n<div class=\"hide-language\">\n<pre><code class=\"lang-bash\">$ aws kendra query --query-text \"what is knedar\" --index-id [YOUR_INDEX_ID] --spell-correction-configuration IncludeQuerySpellCheckSuggestions=true<\/code><\/pre>\n<\/p><\/div>\n<p>In addition to the normal query results, the response from Amazon Kendra now contains a <code>SpellCorrectedQueries<\/code> object, if there are any spelling suggestions for the query. For more information, see <a href=\"https:\/\/docs.aws.amazon.com\/kendra\/latest\/dg\/API_SpellCorrectedQuery.html\" target=\"_blank\" rel=\"noopener noreferrer\">SpellCorrectedQuery<\/a>.<\/p>\n<div class=\"hide-language\">\n<pre><code class=\"lang-bash\">\/\/ Full query response omitted for brevity\n\"SpellCorrectedQueries\": [\n  {\n    \"SuggestedQueryText\": \"what is kendra\",\n    \"Corrections\": [\n      {\n        \"BeginOffset\": 8,\n        \"EndOffset\": 14,\n        \"Term\": \"knedar\",\n        \"CorrectedTerm\": \"kendra\"\n      }\n    ]\n  }\n]<\/code><\/pre>\n<\/p><\/div>\n<h3>AWS SDK<\/h3>\n<p>Next, let\u2019s walk through how Amazon Kendra provides spell check functionality for AWS SDK users. For this example, we use Python 3. We submit a query with a few spelling errors, and print out the <code>SpellCorrectedQueries<\/code> object in the response:<\/p>\n<div class=\"hide-language\">\n<pre><code class=\"lang-python\">import boto3\n\nkendra = boto3.client('kendra')\n\nindex_id = '[YOUR_INDEX_ID]'\nquery_text = 'kendra fre teir hours'\nspell_correction_configuration = { 'IncludeQuerySpellCheckSuggestions': True }\n\nresponse = kendra.query(\n  IndexId = index_id,\n  QueryText = query_text,\n  SpellCorrectionConfiguration = spell_correction_configuration\n)\n\nprint(response['SpellCorrectedQueries'])<\/code><\/pre>\n<\/p><\/div>\n<p>The response from Amazon Kendra now contains the expected spelling suggestions:<\/p>\n<div class=\"hide-language\">\n<pre><code class=\"lang-bash\">[\n  {\n    'SuggestedQueryText': 'kendra free tier hours', \n    'Corrections': [\n      {\n        'BeginOffset': 7, \n        'EndOffset': 11, \n        'Term': 'fre', \n        'CorrectedTerm': 'free'\n      }, \n      {\n        'BeginOffset': 12, \n        'EndOffset': 16, \n        'Term': 'teir', \n        'CorrectedTerm': 'tier'\n      }\n    ]\n  }\n]<\/code><\/pre>\n<\/p><\/div>\n<h3>Process the Amazon Kendra Spell Check response<\/h3>\n<p>Now that we\u2019ve gone over how to programmatically get spelling suggestions through either the AWS CLI or AWS SDK, we can examine how we turn the response into a human-readable suggested query. For this example, we use the sample output from the previous section:<\/p>\n<div class=\"hide-language\">\n<pre><code class=\"lang-bash\">[\n  {\n    'SuggestedQueryText': 'kendra free tier hours', \n    'Corrections': [\n      {\n        'BeginOffset': 7, \n        'EndOffset': 11, \n        'Term': 'fre', \n        'CorrectedTerm': 'free'\n      }, \n      {\n        'BeginOffset': 12, \n        'EndOffset': 16, \n        'Term': 'teir', \n        'CorrectedTerm': 'tier'\n      }\n    ]\n  }\n]<\/code><\/pre>\n<\/p><\/div>\n<p>Each <code>SpellCorrectedQuery<\/code> has two keys: <code>SuggestedQueryText<\/code> and <code>Corrections<\/code>.<\/p>\n<ul>\n<li><code>SuggestedQueryText<\/code> maps to a string containing the updated query with the suggested spelling corrections.<\/li>\n<li><code>Corrections<\/code> maps to a list of <code>Correction<\/code> objects, which contains the beginning and ending offset of the correction, as well as the original term from the query and the spelling suggestion for that term.<\/li>\n<\/ul>\n<p>For our example, we want to show the suggested query text with the newly suggested terms italicized, similar to what is done on the Amazon Kendra console. To achieve this, we can add HTML italics opening tags <code>&lt;i&gt;<\/code> at the <code>BeginOffset<\/code> of each <code>Correction<\/code> and HTML italics closing tags <code>&lt;\/i&gt;<\/code> at the <code>EndOffset<\/code> of each <code>Correction<\/code> in the <code>Corrections<\/code> list. Note that <code>BeginOffset<\/code> and <code>EndOffset<\/code> are based on the length of the corrected terms, not the original terms.<\/p>\n<p>Adding the italics tags to <code>SuggestedQueryText<\/code> gives us the following suggested query text:<\/p>\n<div class=\"hide-language\">\n<pre><code class=\"lang-bash\">kendra &lt;i&gt;free&lt;\/i&gt; &lt;i&gt;tier&lt;\/i&gt; hours<\/code><\/pre>\n<\/p><\/div>\n<p>As you can see, Amazon Kendra Spell Checker makes it simple to add spell check functionality to your search application.<\/p>\n<h2>Conclusion<\/h2>\n<p>Spell Checker is a new, powerful feature offered by Amazon Kendra. Spell Checker is a simple, effective way to quickly reduce the number of unhelpful queries by providing spelling suggestions to end-users for misspelled terms.<\/p>\n<p>Spell Checker is available in all <a href=\"https:\/\/aws.amazon.com\/about-aws\/global-infrastructure\/regional-product-services\/\" target=\"_blank\" rel=\"noopener noreferrer\">AWS Regions<\/a> where Amazon Kendra is available, and supports all languages currently supported by Amazon Kendra.<\/p>\n<p>To learn more about Amazon Kendra, visit the <a href=\"https:\/\/aws.amazon.com\/kendra\/\" target=\"_blank\" rel=\"noopener noreferrer\">Amazon Kendra product page<\/a>.<\/p>\n<hr>\n<h3>About the Author<\/h3>\n<p><strong><a href=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2022\/03\/25\/Matthew-Peretick.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-34613 alignleft\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2022\/03\/25\/Matthew-Peretick.jpg\" alt=\"\" width=\"100\" height=\"133\"><\/a>Matthew Peretick<\/strong> is a Software Development Engineer at Amazon Web Services based in New York City. Matthew is a member of the Amazon Kendra team focused on enhancing the Amazon Kendra query experience.<\/p>\n<p>       <!-- '\"` -->\n      <\/div>\n","protected":false},"excerpt":{"rendered":"<p>https:\/\/aws.amazon.com\/blogs\/machine-learning\/improve-search-accuracy-with-spell-checker-in-amazon-kendra\/<\/p>\n","protected":false},"author":0,"featured_media":2025,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[],"_links":{"self":[{"href":"https:\/\/salarydistribution.com\/machine-learning\/wp-json\/wp\/v2\/posts\/2024"}],"collection":[{"href":"https:\/\/salarydistribution.com\/machine-learning\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/salarydistribution.com\/machine-learning\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/salarydistribution.com\/machine-learning\/wp-json\/wp\/v2\/comments?post=2024"}],"version-history":[{"count":0,"href":"https:\/\/salarydistribution.com\/machine-learning\/wp-json\/wp\/v2\/posts\/2024\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/salarydistribution.com\/machine-learning\/wp-json\/wp\/v2\/media\/2025"}],"wp:attachment":[{"href":"https:\/\/salarydistribution.com\/machine-learning\/wp-json\/wp\/v2\/media?parent=2024"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/salarydistribution.com\/machine-learning\/wp-json\/wp\/v2\/categories?post=2024"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/salarydistribution.com\/machine-learning\/wp-json\/wp\/v2\/tags?post=2024"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}