Improve your search encounters with AI-driven Amazon Kendra
Tags: aws, ai, search, kendra
Published: 2024-04-10 12:54:26

Technological advancements open doors to drive scientific exploration, accelerate human progress, and enhance quality of life. Artificial Intelligence (AI) tools stand out as particularly promising in this regard. Amazon Kendra and Amazon Q are two powerful tools that exemplify this potential. Amazon Kendra revolutionizes search experiences, offering natural language processing capabilities that enable users to discover information more intuitively and efficiently. It's particularly valuable for enterprises dealing with vast amounts of data, enhancing productivity and decision-making processes.

* [Amazon Kendra](#kendra)
  * [Traditional Search vs Intelligent Search](#compare)
  * [Create index](#index)
  * [Add Data source](#addds)
  * [Sync Data source](#syncds)
  * [Monitoring & Logging](#logging)
  * [Experiences](#experiences)
* [Clean-up](#cleanup)
  * [Kendra Resources](#kendra-res)
  * [Roles](#roles)
  * [Logs](#logs)
* [Roles are different for index, data source and experience. Why & how?](#diffroles)
* [Resources](#resources)
* [Conclusion](conclusion)


###  <a name="kendra">Amazon Kendra</a>
When you wanted to find accurate information faster in situations like improving customer interactions and boost workforce productivity, an intelligent search is the way to go. Amazon Kendra is an intelligent search service powered by machine learning which uses natural language search capabilities to help your organization quickly return accurate answers from unstructured content.

####<a name="compare">Traditional Search vs Intelligent Search</a>
Amazon Kendra, the intelligent search service, offers numerous advantages over traditional services, particularly when searching through unstructured data such as PDFs, Word documents, or HTML pages.
- Kendra's intelligent search capabilities enable it to understand natural language, providing more accurate answers to search queries instead of simply providing links to documents.
- Kendra continuously improves over time by fine-tuning its machine-learning models periodically.
- Implementation is easy with the click of a button, allowing users to quickly find the answers they are looking for.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wh967nc1hqos3gbx4jxi.png)

Let’s explore Kendra deeper

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5z9ul01hdf9uaiorwdd7.png)

####<a name="index">Create index</a>
- Login into AWS Console
- Go to Amazon Kendra service
- Follow the instructions in the below image to create the index in Amazon Kendra
- Observe the Active status, note down the Role ARN and Index ID. This will help you to verify once you add to Amazon Q or Amazon Bedrock for integration.

**Important Note:**
As per the below process, you please create a new role for the index, data source and experience.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wv5lr716lqdj4suotnmt.png)

####<a name="addds">Add Data source</a>

- Amazon Kendra comes with data source connector to connect your documents and index data to an Amazon Kendra index. You can create a data source connector for Amazon Kendra to connect to and index your documents. 

- Amazon Q supports 45+ data sources covering data systems like Aurora(MySQL, PostgreSQL), RDS(MySQL, MS SQL, PostgreSQL), IBM DB2, object storage like S3, source control systems like GitHub, Content Management System like Confluence, Alfresco, Collaborative tools like Slack & Microsoft, Incident Management systems like Jira, Service Now etc.

- When you create a data source connector, you give Amazon Kendra the configuration information required to connect to your source repository. Unlike adding documents directly to an index, you can periodically scan the data source to update the index.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t8ah3qf96qd3met10vkf.png)

####<a name="syncds">Sync Data source</a>

- Once the data source is created successfully, you will have to sync manually since the demo configuration here is **Run On Demand**
You will receive the below message 


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j7al7hwkgmemfr96agyu.png)

- **Failure-**
During a demo, showing that everything is "all green" or perfect may not be ideal because it might create unrealistic expectations. In reality, there are often challenges and issues that need to be addressed. It's important to demonstrate a realistic scenario to manage expectations effectively.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l9vi5qlxnxhjln96dndl.png)

**Wondering why?**
The above recommendation was to create a new role for index but I used the role  was created for some other data source.

- Edit the index, create a new role, update and then run _Sync now_

**Note:**

- When you create a new role, as soon as you update the role and click Next, you will get a notification saying role updated successfully. 
- In the below screen shot the role name given was AmazonKendra-us-east-1-blog. However you need to pass two more screens (Configure user access control and Add additional capacity) before you reach Review and update. 
- Finally when you click the update button, you get the below error which will get you puzzled. No worries, that’s a bug in Amazon Kendra and you can move forward.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pxdu5chg15m0hn409qsu.png)

Hurray, after 2 failures, hit upon success and don’t miss to look at the total items scanned. 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gqqziz84q1yajiv7m5f1.png)

####<a name="logging">Monitoring & Logging</a>

- Look out for CloudWatch logs which gets created under log groups as /aws/kendra/<kendra index id>

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/luuflzhlr5907e76wjuc.png)

- CloudTrail records all API calls with the Event source, kendra.amazonaws.com.

####<a name="experiences">Experiences</a>
You can build and deploy an Amazon Kendra search application without the need for any front-end code. Amazon Kendra Experience Builder helps you build and deploy a fully functional search application in a few clicks so that you can start searching right away. You can custom design your search page and tune your search to tailor the experience to your users' needs. Amazon Kendra generates a unique, fully hosted endpoint URL of your search page to start searching your documents and FAQs. You can quickly build a proof of concept of your search experience and share it with others.

You use the search experience template available in the builder to customize your search. You can invite others to collaborate in building your search experience, or evaluate search results for tuning purposes. Once your search experience is ready for your users to start searching, you simply share the secure endpoint URL.

- Let’s experience the search with Amazon Kendra now with the below steps 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/acx2kd32zb53c2tshweb.png)

- Click the experience URL with the below format for the Live view to search the content you are looking for
https://<unique-id>.search.kendra.us-east-1.on.aws/home#/
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3d7g2mpvergc4qvug85d.png)

- You can **switch to build mode** to build your experience 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3r533eub7ylpxe3g9cxg.png)

###<a name="cleanup">Clean-up</a>
#### <a name="kendra-res">Kendra Resources</a>
- Go to Amazon Console -> Amazon Kendra Service
- Note down the 3 roles that you created for index, data source and experience respectively
- Go to Experiences -> Select experience name, click Delete on top right
- Go to Data sources -> Select data source name, click Delete on top right
- Go to index -> Select index name, click Delete on top right
This cool confirmation dialog lets you provide the feedback at the time of deleting any of these resources
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/auikkjrtil6veb2kmj0v.png)

- Do you want to jump the road and delete the index before data source ?
You got that covered. It has been verified when index is deleted before data source, data source is also deleted. 
If you are too curious to ask, “how did you verify when you do not see anything on the Amazon Kendra left pane when index itself is deleted?”
I had created an application in Amazon Q integrated with the same data source and peeped into it after the Kendra index was deleted. Got this message!! 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j77owtro9b2d5j9899zl.png)

That double confirms that deleting index before data source deletes the index. 

#### <a name="roles">Roles</a>

- Now the next question – Are the roles deleted automatically?
  - That’s No. 
  - So you go ahead and delete the 3 roles 

#### <a name="logs">Logs</a>
- You already saw that Amazon Kendra logs get created in CloudWatch under /aws/kendra/<kendra index id>
Does it get cleaned-up automatically? That’s again No.
- By default the CloudWatch log groups that gets created for Amazon Kendra has default retention as Never expire.
- Since you have deleted the Kendra index, it’s time to clean-up CloudWatch logs too. Hence go ahead and change the retention setting to expire by 1 day] 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0i21a0wlkaawz9356ndc.png)

**Pricing**
The present exploration is with Amazon Kendra Developer Edition which has 750 hrs of free tier for the first 30 days and later priced at $1.125 /hour. Good opportunity to learn and do PoC within 30 days.
Here is the Amazon Kendra service wise billing for this blog exploration.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rqyoyei38q9f0jxyd06e.png)
For production workload and enterprise scale, you may look at Enterprise Edition. Refer [Kendra Pricing](https://aws.amazon.com/kendra/pricing) for detailed comparison between Developer Edition and Enterprise Edition.

###<a name="diffroles">Roles are different for index, data source and experience. Why & how?</a>
Let’s compare two roles - say the service role for Amazon Kendra Index and Experience to understand better.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9fm5fu6lqd77g06p01km.png)

### <a name="resources">Resources</a>
- [Amazon Kendra](https://docs.aws.amazon.com/kendra/)
- [Amazon Pricing](https://aws.amazon.com/kendra/pricing)

### <a name="conclusion">Conclusion</a>
In conclusion, Amazon Kendra offers a powerful solution for enhancing search capabilities for wide variety of data sources. By creating an index, setting up data sources, and crawling data, we have demonstrated how Kendra can significantly improve the search experience. Its advanced machine learning capabilities enable accurate and relevant search results, making it a valuable tool for any organization looking to enhance their search functionality.