AWS Machine Learning Blog
Integrate Amazon Kendra and Amazon Lex using a search intent
Customer service conversations typically revolve around one or more topics and contain related questions. Answering these questions seamlessly is essential for a good conversational experience. For example, as part of a car rental reservation, you have queries such as, “What’s the charge for an additional driver?” or, “Do you have car seats for kids?” Starting today, you can use a search intent in your Amazon Lex bots to integrate with Amazon Kendra, so your bots can surface answers from Kendra.
Amazon Kendra was recently made generally available to all AWS customers, with exciting new features. Amazon Kendra provides you with a highly accurate and easy-to-use enterprise search service powered by machine learning. It offers a more intuitive way to search—using natural language—and returns more accurate answers, so your end-users can discover information stored within your organization’s vast amount of content.
We previously described how you can add an AWS Lambda function in an Amazon Lex bot to integrate with Kendra. For more information, see Smarter FAQ bots with Amazon Kendra. With this approach, you need to write and maintain integration code, and any updates to the configuration require updating this code. Now you can can add a search intent to get the answers you’re looking for from FAQ documents. You simply define the search index parameters in the intent as part of the bot definition. The bot queries the Amazon Kendra search index during the interaction if the user input doesn’t match any of the other configured intents. The search query responses are populated with request attributes that the bot can use in its response. You don’t have to write any Lambda code. The integration is simple, and you can seamlessly deliver natural language answers from Amazon Kendra in your Amazon Lex conversations.
This post shows how you can integrate an Amazon Lex bot with Amazon Kendra using a search intent, so you can quickly build a bot to provide answers in a conversation. The following diagram illustrates this solution.
Building a Lex bot
We will use the same conversation from the previous post to model a bot conversation:
User: Where’s the IT Help Desk?
Agent: 2nd floor; room 201 (two rights after you get out of the elevators).
User: Can I come in at noon?
Agent: Sure. What’s the nature of your problem?
User: I have a cracked laptop screen.
Agent: For verification purposes, can I get the last four digits of your employee ID?
User: 1234.
Agent: Got it, we’ll see you then to take a look at your screen.
User: How long does it take to fix a screen?
Agent: Laptop screen repairs typically take 4 hours.
User: What do I need to bring with me for a screen repair?
Agent: For a laptop screen repair, please bring your employee badge, laptop, and VPN fob.
User: How do I access my documents while my laptop is being repaired?
Agent: You can use Amazon Workdocs to access your documents.
User: Can I use WorkDocs on my tablet?
Agent: Yes. Users can access Amazon WorkDocs using free applications for iPad, Kindle Fire, and Android tablets that you can download from iTunes, Amazon Appstore for Android, and Google Play. Users can also access Amazon WorkDocs using the web browser on any mobile device.
User: When does the help desk close?
Agent: Our hours are from 11 AM to 2 PM.
User: Is there a coffee shop nearby?
Agent: There is one on the third floor and it’s open from 8 AM to 4 PM daily.
The first step is to build an Amazon Lex bot with intents to book an appointment and check appointment status. The MakeAppointment
intent elicits the information required to make an appointment, such as the date, time, employee ID, and the nature of the issue. The CheckAppointmentStatus
intent provides the status of the appointment. When a user asks a question that the Lex bot can’t answer with these intents, it uses the built-in KendraSearchIntent
intent to connect to Amazon Kendra to search for an appropriate answer.
Deploying the sample bot
To create the sample bot, complete the following steps. This creates an Amazon Lex bot called help_desk_bot
and a Lambda fulfillment function called help_desk_bot_handler
.
- Download the Amazon Lex definition and Lambda code.
- In the AWS Lambda console, choose Create function.
- Enter the function name
help_desk_bot_handler
. - Choose the latest Python runtime (for example, Python 3.8).
- For Permissions, choose Create a new role with basic Lambda permissions.
- Choose Create function.
- Once your new Lambda function is available, in the Function code section, choose Actions, choose Upload a .zip file, choose Upload, and select the
help_desk_bot_lambda_handler.zip
file that you downloaded. - Choose Save.
- On the Amazon Lex console, choose Actions, and then Import.
- Choose the file
help_desk_bot.zip
that you downloaded, and choose Import. - On the Amazon Lex console, choose the bot
help_desk_bot
. - For each of the intents, choose AWS Lambda function in the Fulfillment section, and select the
help_desk_bot_handler
function in the dropdown list. If you are prompted “You are about to give Amazon Lex permission to invoke your Lambda Function”, choose OK. - When all the intents are updated, choose Build.
At this point, you should have a working bot that is not yet connected to Amazon Kendra.
Creating an Amazon Kendra index
You’re now ready to create an Amazon Kendra index for your documents and FAQ. Complete the following steps:
- On the Amazon Kendra console, choose Launch Amazon Kendra.
- If you have existing Amazon Kendra indexes, choose Create index.
- For Index name, enter a name, such as
it-helpdesk
. - For Description, enter an optional description, such as
IT Help Desk FAQs
. - For IAM role, choose Create a new role to create a role to allow Amazon Kendra to access Amazon CloudWatch Logs.
- For Role name, enter a name, such as
cloudwatch-logs
. Kendra will prefix the name withAmazonKendra
and the AWS region. - Choose Next.
- For Provisioning editions, choose Developer edition.
- Choose Create.
Adding your FAQ content
While Amazon Kendra creates your new index, upload your content to an Amazon Simple Storage Service (Amazon S3) bucket.
- On the Amazon S3 console, create a new bucket, such as
kendra-it-helpdesk-docs-<your-account#>
. - Keep the default settings and choose Create bucket.
- Download the following sample files and upload them to your new S3 bucket:
When the index creation is complete, you can add your FAQ content.
- On the Amazon Kendra console, choose your index, then choose FAQs, and Add FAQ.
- For FAQ name, enter a name, such as
it-helpdesk-faq
. - For Description, enter an optional description, such as
FAQ for the IT Help Desk
. - For S3, browse Amazon S3 to find your bucket, and choose help-desk-faq.csv.
- For IAM role, choose Create a new role to allow Amazon Kendra to access your S3 bucket.
- For Role name, enter a name, such as
s3-access
. Kendra will prefix your role name withAmazonKendra-
. - Choose Add.
- Stay on the page while Amazon Kendra creates your FAQ.
- When the FAQ is complete, choose Add FAQ to add another FAQ.
- For FAQ name, enter a name, such as
workdocs-faq
. - For Description, enter a description, such as
FAQ for Amazon WorkDocs
mobile and web access. - For S3, browse Amazon S3 to find your bucket, and choose workdocs-faq.csv.
- For IAM role, choose the same role you created in step 9.
- Choose Add.
After you create your FAQs, you can try some Kendra searches by choosing Search console. For example:
- When is the help desk open?
- When does the help desk close?
- Where is the help desk?
- Can I access WorkDocs from my phone?
Adding a search intent
Now that you have a working Amazon Kendra index, you need to add a search intent.
- On the Amazon Lex console, choose
help_desk_bot
. - Under Intents, choose the + icon next to add an intent.
- Choose Search existing intents.
- Under Built-in intents, choose KendraSearchIntent.
- Enter a name for your intent, such as
help_desk_kendra_search
. - Choose Add.
- Under Amazon Kendra query, choose the index you created (
it-helpdesk
). - For IAM role, choose Add Amazon Kendra permissions.
- For Fulfillment, leave the default value Return parameters to client selected.
- For Response, choose Message, enter the following message value and choose + to add it:
- Choose Save intent.
- Choose Build.
The message value you used in step 10 is a request attribute, which is set automatically by the Amazon Kendra search intent. This response is only selected if Kendra surfaces an answer. For more information on request attributes, see the AMAZON.KendraSearchIntent documentation.
Your bot can now execute Amazon Kendra queries. You can test this on the Amazon Lex console. For example, you can try the sample conversation from the beginning of this post.
Deploying on a Slack channel
You can put this solution in a real chat environment, such as Slack, so that users can easily get information. To create a Slack channel association with your bot, complete the following steps:
- On the Amazon Lex console, choose Settings.
- Choose Publish.
- For Create an alias, enter an alias name, such as
test
. - Choose Publish.
- When your alias is published, choose the Channels
- Under Channels, choose Slack.
- Enter a Channel Name, such as
slack_help_desk_bot
. - For Channel Description, add an optional description.
- From the KMS Key drop-down menu, leave aws/lex selected.
- For Alias, choose
test
. - Provide the Client Id, Client Secret, and Verification Token for your Slack application.
- Choose Activate to generate the OAuth URL and Postback URL.
Use the OAuth URL and Postback URL on the Slack application portal to complete the integration. For more information about setting up a Slack application and integrating with Amazon Lex, see Integrating an Amazon Lex Bot with Slack.
Conclusion
This post demonstrates how to integrate Amazon Lex and Amazon Kendra using a search intent. Amazon Kendra can extract specific answers from unstructured data. No pre-training is required; you simply point Amazon Kendra at your content, and it provides specific answers to natural language queries. For more information about incorporating these techniques into your bots, please see the AMAZON.KendraSearchIntent documentation.
About the authors
Brian Yost is a Senior Consultant with the AWS Professional Services Conversational AI team. In his spare time, he enjoys mountain biking, home brewing, and tinkering with technology.
As a Product Manager on the Amazon Lex team, Harshal Pimpalkhute spends his time trying to get machines to engage (nicely) with humans.