Creating a Knowledge-Driven Chatbot Using AWS Lex and Bedrock
Leveraging AWS services to build a chatbot with RAG, vector databases, and advanced AI capabilities
In this post, I will walk through creating a chatbot using AWS services, primarily AWS Lex, Bedrock, and S3. Below is a brief overview of each service:
Amazon Lex – A fully managed AI service for building conversational interfaces using voice and text. It uses advanced NLP to understand user inputs and generate responses.
Amazon Bedrock – A service that provides access to foundation models (FMs) from various AI providers, enabling you to integrate generative AI into applications without managing infrastructure. It can enhance chatbot responses with more advanced reasoning and contextual understanding.
Amazon S3 (Simple Storage Service) – A scalable object storage service used to store and retrieve data.
In terms of RAG to create a knowledge base, here are the datasets I used that contain publicly available information on World War:
The datasets above are saved to a S3 bucket.
The next step is to create a knowledge base. In Amazon Bedrock, I built a knowledge base using Titan Text Embedding V2, Amazon’s embedding model, to generate a vector database from PDF files. This foundation model converts text into high-dimensional vector representations, enabling semantic search and retrieval-augmented generation (RAG) by capturing the meaning of text rather than just matching keywords.
For the vector store, I used Amazon OpenSearch Serverless, a fully managed search and analytics service that efficiently stores, indexes, and searches vector embeddings. This serves as the chatbot’s vector store, allowing for fast retrieval of relevant information from the knowledge base.
The files in s3 is pointed as a location to create the knowledge base.
In order to create a knowledge base, you will have to sign in as an IAM user with appropriate permissions. Once the knowledge base is built, make sure to sync!
Once the knowledge base is created, the next step is to configure the chatbot using Amazon Lex. Amazon Lex offers two approaches for creating a bot:
Traditional Bot: Allows you to build a bot by manually adding and customizing its features.
Generative AI Bot: Comes with pre-built AI-powered features for quicker setup and deployment.
I chose to create a Traditional Bot for this project.
The bot can be configured with various intents. Here's what I implemented:
Welcome Intent: Triggered when the user first interacts with the bot. I set up a generic response for the bot to greet the user and await their input.
Fallback Intent: This is an automatically created default intent. It activates when no other intent matches the user's input.
The bot can be configured with various complex intents, such as closing intents and conditional intents, which allow for more advanced interactions. However, for simplicity, I will focus on creating the bot with just the Welcome Intent for this demonstration.
As shown above, the bot currently responds with the default answer that the user has provided. Additionally, you can see that the Welcome Intent is working as expected. However, when I add more context-specific questions, the bot falls back to the default Fallback Intent since no other specific intent has been configured yet.
Next, while building utterances and adding numerous features for intents is possible, as done in traditional bot design, this is where Bedrock comes in to simplify and enhance the process!
Next, I added the GenAI Q/A intent, which is a really cool feature that automatically identifies intents with minimal configuration. However, you will still need to configure the model.
Now, the bot is ready to answer questions!
As shown, it can retrieve context from the vector database and answer questions successfully! And if asked about something outside the context, the default fallback intent is triggered.
Additionally, this bot can now be deployed in a front-end UI. I found some useful resources that can help with this:
Check out:
Amazon lex UI repo
The repo provides cloud formation files that can set up AWS services automatically.