Create and query an index

with HAQM Kendra

In this tutorial, you learn how to use HAQM Kendra create a new index and query the index for results.  

HAQM Kendra is a highly accurate and easy to use enterprise search service that’s powered by machine learning. HAQM Kendra delivers powerful search capabilities to your websites and applications, so your end users can quickly find the information they need within the vast amount of content spread across your company.

HAQM Kendra lets you ask natural language questions in addition to simple keywords and get the answers you’re looking for, whether that is a precise answer, an FAQ response, or an entire document. HAQM Kendra also lets you easily add content from HAQM S3, HAQM RDS, Microsoft SharePoint Online, ServiceNow, and Salesforce into a centralized location.

In this tutorial, you learn how to:

  1. Set up a new index in HAQM Kendra
  2. Set up an HAQM S3 bucket as a data source and ingest data using an HAQM Kendra connector
  3. Set up an FAQ data source
  4. Query the index using the Console search

For this tutorial, you use HAQM.com help documents in HTML format as discovered by the HAQM Kendra data source connector.

About this Tutorial
Time 1 hour                                          
Cost Less than $1
Use Case Machine Learning
Products HAQM Kendra
Audience Developer
Level Beginner
Last Updated September 11, 2020

Step 1. Create an AWS Account

The cost of this tutorial is less than $1.

Already have an account? Sign-in

Step 2. Set up the HAQM Kendra index

Complete the following steps to set up the HAQM Kendra index. An index can contain documents that are indexed from a data source, documents that are added directly to the index, and FAQs. Once the index is active you can index your documents using the operation or using one of the supported data sources.

Note: For more information, see Creating an index in the HAQM Kendra documentation.


a. Sign in to the HAQM Kendra console, and in the top right corner, verify your AWS Region is set to N. Virginia. Then, choose Create an index.


b. On the Index details page, fill the following fields and choose Next.

  • Index name: hands-on-tutorial
  • Description: HAQM Kendra tutorial.
  • IAM role: Create a new role
  • Role name: HAQMKendra-us-east-1-hands-on-tutorial

c. On the Provisioning editions page, choose Developer edition and then choose Create.
The index creation process takes an average of 15 minutes, but may take up to 30 minutes.

Step 3. Update the IAM role

When you create an index, data source, or an FAQ, HAQM Kendra needs access to the AWS resources required to create the HAQM Kendra resource. While the index is being created, you can update the IAM role to allow it to read from HAQM S3. In a production environment, this step is where you can lock down access to only read specific buckets or files/objects.

Complete the following steps to update the IAM role to allow HAQM S3 access.

Note: For more information, see IAM access roles for HAQM Kendra in the HAQM Kendra documentation.


a. Open the IAM console and in the left navigation pane, choose Roles. In the search box, type hands-on-tutorial. Select and choose the HAQMKendra-us-east-1-hands-on-tutorial role.

b. On the Summary page, choose Attach policies.

c. On the Attach permissions page, in the search box, type S3, and select the HAQMS3ReadOnlyAccess policy. Choose Attach policy.
On the Summary page, you should see two policies attached to the IAM role.
d. Return to the HAQM Kendra console and wait for the status of your index from Step 2 to change from Creating to Active before continuing to the next step.

Step 4. Configure an S3 connector to the data source

A data source is a location, such as an HAQM Simple Storage Service (HAQM S3) bucket, where you store the documents for indexing. Data sources can be automatically synchronized with an HAQM Kendra index so that new, updated, or deleted documents in the source repositories are included in searches. Connectors maintain document access rights and can be scheduled to automatically sync your index with your data source, so you're always securely searching through the most up to date content.

Complete the following steps to add a connector to the HAQM S3 bucket containing the HAQM.com help documents sample as a data source.

Note: For more information, see Data sources in the HAQM Kendra documentation.


a. In the Indexes list, choose your hands-on-tutorial.

b. In the left navigation pane, under Data management, choose Data sources. Under connector type, in the HAQM S3 box, choose Add connector.

c. On the Define attributes page, for Data source name, type HAQM-com-help-pages and choose Next.

d. On the Configure settings page, for Data source location, type  s3://serverless-analytics. For IAM role, choose the HAQMKendra-us-east-1-hands-on-tutorial role you created earlier. Then, expand Additional configuration.

e. In the Additional configuration section, for Include patterns, type amazon-help/documents/ and choose Add.

f. In the Set sync run schedule section, for Frequency, choose Run on demand and then choose Next.

g. Review the configuration details and then choose Create.

h. On the Data source details page, choose Sync now.
The S3 connector starts crawling and indexing the content it has permission to access through the assigned IAM role.

When the sync is completed, the Last sync status of the data source changes to Succeeded.

Step 5. Add an FAQ

For this step, you upload an FAQ to provide Kendra with direct answers to commonly asked questions. HAQM Kendra finds the closest question to the search query and returns the corresponding answer.

Complete the following steps to add an FAQ using the sample amazon-help-faqs.

Note: For more information, see HAQM Kendra Features.


a. In the left navigation pane of the HAQM Kendra console, choose FAQs, then choose Add FAQ.

b. On the Add FAQ page, fill the following fields and choose Add:
  • FAQ name: amazon-help-faqs
  • S3: s3://serverless-analytics/amazon-help/faqs/kendrapost.csv
  • IAM role: HAQMKendra-us-east-1-hands-on-tutorial

You should see the new FAQ and a message, You successfully created the following FAQ:’amazon-help-faqs’.

Step 6. Query the index

Now you can use the text search console to query your newly created index. This is just one of many ways you can query your index. When you search your index, HAQM Kendra uses all of the information that you provided to return the most accurate answer and relevant documents to your search query.  

Complete the following steps to query your newly created index.

Note: For more information, see Searching indexes in the HAQM Kendra documentation.


a. In the left navigation pane of the HAQM Kendra console, choose Search console. In the search box, type your first query: What is HAQM music unlimited?
 
At the top of the results, you can see an HAQM Kendra returned result.
b. Next, type another query: shipping rates to Canada
 
You can see another result returned by HAQM Kendra.

c. Type a more direct query: How do I sign up for the HAQM Prime free Trial?
 
In the results, you can see the HAQM Kendra recommended answer it pulled from the indexed documents along with a new answer from the FAQ data source.

Step 7. Clean up

In this step, you terminate the resources you used in this lab.

Important: Terminating resources that are not actively being used reduces costs and is a best practice. Not terminating your resources will result in charges to your account.


Delete the index:

  1. Open the HAQM Kendra Console.
  2. In the left navigation pane, choose Indexes.
  3. Choose the hands-on-tutorial index and then choose Actions, Delete.
  4. Type Delete to confirm.

Delete the IAM role and policy:

  1. Open the IAM Console.
  2. In the left navigation pane, choose Roles.
  3. In the search box, type hands-on-tutorial.
  4. Select the HAQMKendra-us-east-1-hands-on-tutorial role and then choose Delete role.
  5. Choose Yes, delete
  6. In the left navigation pane, choose Policies.
  7. In the search box, type hands-on-tutorial.
  8. Select the HAQMKendra-us-east-1-hands-on-tutorial policy and then choose Policy actions, Delete.
  9. Choose Delete.

Congratulations

You created and queried an index with HAQM Kendra.

Was this tutorial helpful?

Learn more

Learn more about HAQM Kendra by reading the HAQM Kendra Developer Guide.

Read more about HAQM Kendra features

See the HAQM Kendra Features page for more information.

Explore other machine learning services tutorials