Integrate Amazon Kendra - QnABot on AWS

Integrate Amazon Kendra

Amazon Kendra is an intelligent search service powered by machine learning. There are two ways to take advantage of Amazon Kendra’s natural language processing model to enhance the solution’s ability to understand human questions:

  1. Use Amazon Kendra’s FAQ queries to match users’ questions to the answers in the solution’s knowledge base. Kendra’s machine learning models can handle many variations in how users phrase their questions, and this can reduce the amount of tuning needed for the solution to find the right answer from your knowledge base.

  2. Use Amazon Kendra’s document index as a fallback source of answers when a question/answer is not found in the solution’s knowledge base.

For more information, refer to Amazon Kendra Pricing, and use the Getting started topic in the Amazon Kendra Developer Guide to create your Amazon Kendra index.

Using Kendra FAQ for question matching

Use the following procedure to configure the solution to use your Amazon Kendra index to answer questions from the data populated in content designer:

  1. Update the QnABot on AWS setting KENDRA_FAQ_INDEX to specify the Amazon Kendra index to use.

    • Copy/paste your Index ID from the Amazon Kendra console.

    • If you previously provided a value for the parameter DefaultKendraIndexId when you installed or updated QnABot on AWS, then KENDRA_FAQ_INDEX will be pre-configured.

  2. Replicate all items from Content Designer to the Kendra index:

    • Select the menu () from the top right in Content Designer.

    • Choose SYNC KENDRA FAQ and wait for it to complete – it may take a few minutes.

The solution will now use Kendra FAQ queries to find matches to end users’ questions. Use the setting ALT_SEARCH_KENDRA_FAQ_CONFIDENCE_SCORE to adjust the confidence threshold for Kendra FAQ answers used by QnABot on AWS.

If Kendra FAQ cannot find an answer that meets the confidence threshold, the solution will revert by default to using an Amazon OpenSearch Service query. The combination of Kendra FAQ and Amazon OpenSearch Service gives you the best of both worlds.

Using Kendra search as a fallback source of answers

You can add one or more data sources to your Amazon Kendra index, and configure the solution to query your index any time it gets a question that it doesn’t know how to answer.

  • Update the QnABot on AWS setting ALT_SEARCH_KENDRA_INDEXES to specify one or more Amazon Kendra indexes to use for fallback searches.

    • The value of ALT_SEARCH_KENDRA_INDEXES should be either a single index id, or an array of quoted index ids, for example:

      857710ab-example-do-not-copy

      –Or–

      ["857710ab-example1-do-not-copy","857710ab-example2-do-not-copy"]

    • If you previously provided a value for the parameter DefaultKendraIndexId when you installed or updated QnABot on AWS, then ALT_SEARCH_KENDRA_INDEXES will be pre-configured.

Kendra redirect

QnABot supports multiple mechanisms for dynamic interaction flows. For example:

  • Using Lambda Hooks in a given Item ID to perform additional actions, such as creating a ticket, resetting a password, and saving data to a data store.

  • Using a Kendra Index as a fallback mechanism to look for answers to user's questions.

There are various options to process Kendra queries. One option is to create a custom Lambda hook and map it to an Item ID. The Lambda hook then includes the business logic to use a Kendra Index and process the query.

The Kendra Redirect feature provides a much simpler option. You can include a Kendra query within an Item ID, and QnABot will do the rest to process the Kendra request and respond back with the results.

Configuring an Item ID with Kendra Redirect

  • Create a QnABot question as you would normally do by providing an Item ID and Questions/Utterances.

  • Expand the Advanced option.

  • Kendra Redirect: Query Text accepts a QueryText to search for (for example what is q and a bot) and retrieve the answer from the Kendra Fallback index specified in Settings . Amazon Kendra searches your index for text content, question, and answer (FAQ) content. You can also use handlebars to substitute values using session attributes or slots to support dynamic queries.

  • Kendra Redirect: Confidence score threshold provides a relative ranking that indicates how confident Amazon Kendra is that the response matches the query. This is an optional field having one of the values of: LOW | MEDIUM | HIGH | VERY HIGH. If no value is provided, the value for the ALT_KENDRA_FALLBACK_CONFIDENCE_THRESHOLD setting is used.

  • Kendra query argumentsis an optional field that allows filtered searches based on document attributes. For example: "AttributeFilter": {"EqualsTo": {"Key": "City", "Value": {"StringValue": "Seattle"}}}. You can also use handlebars to substitute values using session attributes or slots to support dynamic queries.

For more information on using Kendra query arguments, refer to the Amazon Kendra Query API in the Amazon KendraDevelop Guide.

Figure 14: Kendra redirect configuration

Note
  • Answer fields are ignored when KendraRedirect query is used.

  • Use this feature for use cases where you have Item IDs that directly need to interact with a Kendra Index as configured in Settings.

  • When applying Kendra query arguments, check if the document fields are searchable. Searchable, determines whether the field is used in the search. For more information, refer to Mapping data source fields in the Amazon KendraDevelop Guide.

Web page indexer

This solution can answer questions based on the content of web pages.

  1. From content designer, select the tools menu ( ☰ ), and then choose Settings.

  2. Modify the following settings:

    • ENABLE_WEB_INDEXER: true

    • KENDRA_INDEXER_URLS:  https://aws.amazon.com/lex/faqs/

    • KENDRA_WEB_PAGE_INDEX: Existing Amazon Kendra index ID

    • KENDRA_INDEXER_SCHEDULER: rate (1 day) 

  3. From content designer, select the tools menu ( ), and then choose Kendra Web Page Indexing.

    1. Choose START INDEXING.

    2. Wait for indexing to complete (it can take several minutes).

  4. Open the web UI, and ask “What is Lex?”. QnABot on AWS provides an answer with a link to the Amazon Lex FAQ page.

For more information on web page indexing, refer to the README.md file in GitHub.