Skip to content

AWS Serverless RAG chatbot endpoint using Amazon Bedrock Knowledge Base

Notifications You must be signed in to change notification settings

squatboy/amazon-bedrock-serverless-rag-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Amazon Bedrock Serverless RAG Bot

A serverless RAG (Retrieval-Augmented Generation) chatbot system based on AWS using Amazon Bedrock Knowledge Base

Project Overview

This project provides an AI chatbot that operates based on internal documents (regulations, manuals, knowledge base, etc.) of companies/organizations on a secure, scalable, and cost-effective serverless platform. Designed around AWS fully managed services, it minimizes infrastructure management burden and allows focus on business logic development.

Key Features

  • Serverless Architecture: Fully managed infrastructure using AWS Lambda, API Gateway, and Bedrock
  • RAG-based: Intelligent document search and answer generation through Amazon Bedrock Knowledge Base
  • IaC-based: Infrastructure code management through Terraform
  • Enhanced Security (Optional): PII protection and harmful content filtering through Bedrock Guardrails

System Architecture

image

Core Components

  • API Gateway: Single entry point of the system, provides RESTful API
  • Lambda: Handles user requests and communicates with Bedrock
  • Bedrock Knowledge Base: RAG pipeline automation and orchestration
  • S3: Document storage and vector storage
  • Bedrock Guardrails (Optional): PII protection and content filtering

Getting Started

Prerequisites

  • AWS CLI installed and configured
  • Terraform installed (>= 1.0)
  • Python 3.9+
  • Appropriate AWS permissions (Bedrock, Lambda, API Gateway, S3, etc.)

1. Clone Repository

git clone https://github.com/squatboy/amazon-bedrock-serverless-rag-bot.git
cd amazon-bedrock-serverless-rag-bot

2. Deploy Infrastructure

# Initialize Terraform
terraform init

# Check deployment plan
terraform plan

# Deploy infrastructure
terraform apply

3. Bedrock Knowledge Base Setup

Important: Bedrock Knowledge Base must be created manually in AWS Console.

  1. Create Knowledge Base in AWS Bedrock Console
  2. Use "Quick Create" option
  3. Connect S3 bucket data source (use bucket created by Terraform)
  4. Set the created Knowledge Base ID in Lambda environment variables

4. Document Upload and Synchronization

# Upload documents to S3 bucket
aws s3 cp your-documents/ s3://your-bucket-name/docs/ --recursive

# Execute "Sync" in Bedrock Console

Usage

API Endpoint

After deployment completion, you can request answers from the chatbot through the API Gateway URL:

# Request example
curl -X POST https://your-api-gateway-url/chat \
  -H "Content-Type: application/json" \
  -d '{"message": "Please tell me about the company vacation policy"}'

Response Format

{
  "response": "The company's annual leave is granted 15 days after 1 year from the date of employment...",
  "citations": [
    {
      "content": "Annual leave related regulations...",
      "source": "company-policy.pdf"
    }
  ]
}

About

AWS Serverless RAG chatbot endpoint using Amazon Bedrock Knowledge Base

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published