How to Build a Smart Chatbot Using Amazon Bedrock, Knowledge Bases, and Your Own Documents
Vrajesh Jayswal

Vrajesh Jayswal @vrajesh_jayswal_bb93052b6

About: Technical Architect & AWS Community Builder

Joined:
Mar 28, 2025

How to Build a Smart Chatbot Using Amazon Bedrock, Knowledge Bases, and Your Own Documents

Publish Date: Apr 19
8 0

In the era of AI, building a chatbot that goes beyond generic answers and understands your private business documents is no longer a luxury — it’s a strategic advantage. In this blog, I will l walk you through how to build an intelligent chatbot using Amazon Bedrock, Knowledge Bases, and documents stored in an Amazon S3 bucket.

What Is Amazon Bedrock?
Amazon Bedrock is a fully managed service that makes foundation models (FMs) from providers like AWS, Anthropic, Cohere, and Meta available via API. It abstracts away the heavy lifting — no infrastructure to manage, just smart AI on tap.
With Knowledge Bases, Bedrock enables Retrieval-Augmented Generation (RAG) — meaning your chatbot can retrieve relevant content from your documents and generate human-like responses using FMs.

What We’re Building

Image description
We’ll create a chatbot that can:
• Answer questions using your private documents (PDFs, DOCX, TXT) stored in S3.
• Retrieve relevant snippets using semantic search.
• Generate accurate, conversational answers using a foundation model.
This is ideal for customer support, internal documentation, onboarding, and more.

Step 1: Store Your Documents in Amazon S3
Start by uploading all the documents you want your chatbot to learn from into an S3 bucket.
Make sure the documents are well-organized and stored in a private bucket.
I created new bucket with name ‘my-private-documents101’ so my S3 bucket URI is : s3://my-private-documents101/

Step 2: Create a Knowledge Base in Bedrock
Navigate to the Amazon Bedrock console and go to the Knowledge Bases section.
2.1. Create a New Knowledge Base with Vector store

• Give it a name (e.g., my-documents-kb)
• Choose Amazon S3 as the data source

Image description
• Provide the URI to your bucket or folder (e.g., s3:// my-private-documents101 /) created in Step#1.

Image description
• Attach an IAM role that has read access to above bucket.

2.2. Configure Embedding and Vector Store

• Choose an embedding model like Titan Embeddings.

Image description

• Select a vector store such as Amazon OpenSearch, Pinecone, or Redis.

Image description
• Bedrock will create the vector index and connect it to your documents.

2.3. Ingest the Documents
Hit "Ingest", and Bedrock will process your files, breaking them into chunks, embedding them, and storing them in the vector database.

Step 3: Build the Chatbot Using Bedrock’s RetrieveAndGenerate API
Once the Knowledge Base is ready, use Bedrock’s API to build your chatbot.
Here’s an example in Python:
import boto3
bedrock = boto3.client('bedrock-agent-runtime')
response = bedrock.retrieve_and_generate(
input={'text': "What is our leave policy for fulltime employees?"},
knowledgeBaseId=,
retrievalConfiguration={
'vectorSearchConfiguration': {'numberOfResults': 3}
}
)
print(response['output']['text'])

Above function:

  1. Takes the user’s question
  2. Retrieves top-matching document chunks
  3. Sends them to a foundation model
  4. Returns a natural language answer You can wrap this logic inside a web app, Slack bot, or API endpoint.

Step 4: Secure Your Setup
Security matters — especially with private documents.
• Ensure your S3 bucket is private.
• Use IAM roles to control access to Bedrock and S3.
• Monitor activity using AWS CloudTrail or CloudWatch.

Optional Step: Add a Chat UI
You can pair your chatbot with a user interface using:
• Amazon Lex – for voice/chat interfaces
• React + AWS Amplify – to build a web UI
• API Gateway + Lambda – to expose your chatbot as a RESTful API
With just a little front-end work, you will have a sleek and smart chatbot that feels custom-made.

Conclusion:
Amazon Bedrock + Knowledge Bases + your private S3 documents = a chatbot that actually knows your business. Whether it's employee onboarding, customer support, or internal search, you now have the power to build a truly intelligent assistant

Comments 0 total

    Add comment