DEV Community

Cover image for Amazon Kendra: Build AI-Powered Search in Minutes
Tanseer for AWS Community Builders

Posted on

Amazon Kendra: Build AI-Powered Search in Minutes

Search across your company's documents in plain language and get real answers, not just a list of links. Stop eight in the AWS Hidden Gems series.

About this series

Most AWS learning stops after EC2, S3, IAM, and Lambda. But AWS has over two hundred services, and many of the most useful ones rarely appear in tutorials.

AWS Hidden Gems covers those underrated services you shouldn't ignore. Each article picks one, then explains why it exists, what it does, where it fits, and how to set it up from the console. Know the four basics above and you can follow along. Everything else gets explained as it comes up.

Today's service: Amazon Kendra

Search boxes on internal tools are usually frustrating. You type keywords, you get a list of documents that contain those words, and you dig through them to find the actual answer. Kendra is a search service that understands the question you are asking and returns the answer, drawing from your own documents and data.

Why does this service exist?

Traditional search matches keywords. If you search "how many vacation days do new employees get" in a normal search box, it looks for documents containing those words, ranks them roughly, and hands you a list. The answer might be buried on page nine of an HR policy.

Building search that actually understands the question needs natural language processing and machine learning expertise, which most teams do not have. Kendra packages that. It uses machine learning to understand meaning and intent, so it can return a specific answer passage, matching FAQs, and the most relevant documents, all from a plain language question.

What is Amazon Kendra?

Kendra is a managed intelligent search service. Intelligent search means it understands the meaning behind a query, not just the words in it.

The core pieces are:

  • An index, which is the searchable store of your content
  • Data sources, which are connectors that pull content in from where it lives
  • Queries, which your app or users send in natural language It connects to many content sources through ready made connectors, including S3, SharePoint, Confluence, databases, and websites, so you do not move your content, you point Kendra at it. When someone searches, Kendra can return a direct answer pulled from a document, a matching FAQ, and a ranked list of documents, and it respects access permissions so people only see what they are allowed to. It is also a popular way to feed relevant context to a generative AI assistant, since it finds the right passages to answer from.

A real world problem

A company's support agents waste time hunting through wikis, PDFs, and old tickets to answer customer questions. The information exists, but finding it fast is the problem.

A keyword search box has not helped, because agents rarely guess the exact wording used in the documents. They need to ask a question the way a customer would and get the answer.

Kendra indexes all that content and answers natural language questions directly. An agent types "what is the refund window for damaged items" and gets the passage that says so, pulled from the right policy document, in seconds.

Real world use cases

  • Support teams find answers fast across wikis, manuals, and past tickets
  • Employees search HR, IT, and policy documents in plain language on an internal portal
  • Legal and compliance teams search large sets of contracts and filings
  • Healthcare staff look up guidelines and protocols quickly
  • Customer facing help centers answer visitor questions from documentation
  • Generative AI assistants use Kendra to find the right content to answer from The pattern is asking a question in normal language and getting the answer out of your own content.

Where it fits in AWS

You point Kendra's connectors at your content sources, and it builds an index. Your app or a search page sends natural language queries to Kendra and gets back answers and ranked results. When paired with generative AI, Kendra retrieves the relevant passages and a model on Amazon Bedrock, the AWS service for foundation models, writes the final answer.

flowchart LR
    A[S3, SharePoint, databases, websites] -->|Connectors| B[Kendra index]
    C[Search page or app] -->|Natural language query| B
    B -->|Answer and ranked results| C
    B -->|Relevant passages| D[Generative AI on Bedrock]
Enter fullscreen mode Exit fullscreen mode

Kendra is the search brain over your content. Connectors bring content in, and your app asks questions of it.

How the workflow runs

You create an index, then add one or more data sources by choosing a connector and giving it access to your content. Kendra syncs the content into the index, and you can schedule that sync to keep it current. Once indexed, your app sends a natural language query, and Kendra returns a direct answer where it can find one, plus matching FAQs and ranked documents. You can tune relevance and add curated FAQs to sharpen results.

flowchart TD
    A[Create an index] --> B[Add a data source with a connector]
    B --> C[Kendra syncs content into the index]
    C --> D[App sends a natural language query]
    D --> E[Kendra returns an answer and ranked results]
Enter fullscreen mode Exit fullscreen mode

Setting it up in the AWS Console

You will create an index, connect an S3 bucket of documents, and search it.

  1. Sign in to the AWS Console, search for Kendra, and open it. Check the region in the top right corner.
  2. Click Create an index. Give it a name, let the console create the IAM role it needs, then choose the Developer edition for testing. Creating the index takes a little while.
  3. When the index is ready, open it and click Add data sources. Choose the Amazon S3 connector.
  4. Point the connector at an S3 bucket that holds some documents, such as PDFs or text files, and let the console create the IAM role that lets Kendra read that bucket. Set the sync to run once for now.
  5. Run the sync and wait for it to finish. Kendra reads your documents and builds them into the index.
  6. Open the Search console builder from the left menu. Type a natural language question about the content of your documents, and Kendra returns an answer passage and ranked results.
  7. To confirm your setup from code, send the same query with the API as shown next and check that results come back. Common mistakes: empty results usually mean the sync has not finished or the bucket had no readable documents, so confirm the sync completed and the files are supported types. Remember that the Developer edition is for building and testing, and it runs on an hourly charge whether or not you are querying, so delete the index when you are done experimenting.

Using it from code

Once an index has content, querying it is a single call with a plain language question.

import boto3

kendra = boto3.client("kendra")

response = kendra.query(
    IndexId="your-index-id",
    QueryText="how many vacation days do new employees get",
)

for result in response["ResultItems"]:
    excerpt = result.get("DocumentExcerpt", {}).get("Text", "")
    print(result["Type"], "->", excerpt[:150])
Enter fullscreen mode Exit fullscreen mode

The Type on each result tells you whether it is a direct answer, an FAQ match, or a document, so your app can show the best ones first.

Pricing

Item Detail
Pricing model Per hour for a running index, not per query
Developer edition Lower hourly rate, for building and testing, limited capacity
Enterprise edition Higher hourly rate, for production, scales with capacity units
Connector sync Some connectors add a charge while scanning content
Free tier Developer edition free for the first 30 days, up to 750 hours

The AWS search family

AWS Search and Discovery
├── Kendra        ML search over your content, returns answers
├── OpenSearch    full text search and analytics you run and tune
├── CloudSearch   older managed keyword search service
└── Q Business    generative AI assistant over your company data
Enter fullscreen mode Exit fullscreen mode

The main choice is Kendra versus OpenSearch. Kendra understands natural language and returns answers with little setup, but runs on a steady hourly cost. OpenSearch is a powerful search and analytics engine you configure and tune yourself, better when you want full control. Q Business takes Kendra's idea further, layering a generative AI assistant on top of your content.

Wrapping up

Kendra turns a keyword search box into something that understands questions and returns answers from your own documents. It connects to where your content already lives and needs no search expertise to set up. Just keep its hourly pricing in mind, since the index runs whether or not you are using it. Next time a project needs real search over internal content, you know where to start.

Series progress

You are on stop eight of AWS Hidden Gems.

  1. AWS Elemental MediaConvert
  2. Amazon IVS
  3. Amazon Rekognition
  4. Amazon Personalize
  5. AWS AppSync
  6. Amazon Timestream
  7. Amazon Textract
  8. Amazon Kendra (you are here)
  9. AWS DataSync
  10. AWS IoT Core Next up is AWS DataSync, the fast and reliable way to move large amounts of data into AWS.

Let's connect

Questions, corrections, or want to talk through where this fits in your own project? Reach me at khantanseer43@gmail.com.

Top comments (0)