Skip to content

psadigh91/PrivateRAGForMidMarket

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ”’ AWS Private RAG

Privacy-first RAG (Retrieval-Augmented Generation) platform that runs entirely in your AWS account. Your documents never leave your infrastructure.

Build Status License AWS Python TypeScript


🎯 What is AWS Private RAG?

A self-hosted, privacy-focused alternative to cloud RAG platforms like ChatGPT Enterprise or Claude for Work. Perfect for:

  • πŸ₯ Healthcare practices (HIPAA compliance)
  • βš–οΈ Law firms (attorney-client privilege)
  • πŸ’° Financial services (SOC 2, SEC compliance)
  • 🏒 Any organization that can't send sensitive data to third-party APIs

Key Features

βœ… 100% Private - Data never leaves your AWS VPC
βœ… Open Source - Fork, modify, audit the code
βœ… Production-Ready - Full CRUD, auth, monitoring, backups
βœ… Cost-Effective - $50-$400/month depending on scale
βœ… Easy Deployment - One-command AWS CDK deploy
βœ… Multiple LLMs - Llama 3.1 8B (CPU) or 70B (GPU)
βœ… Compliance-Ready - HIPAA, SOC 2 documentation included


πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Your AWS Account / VPC                             β”‚
β”‚                                                      β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”‚
β”‚  β”‚ Next.js  β”‚β†’ β”‚ FastAPI  β”‚β†’ β”‚ Llama 3  β”‚         β”‚
β”‚  β”‚ Frontend β”‚  β”‚ Backend  β”‚  β”‚ (Local)  β”‚         β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β”‚
β”‚                      ↓              ↓               β”‚
β”‚              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”‚
β”‚              β”‚  Qdrant   β”‚   β”‚    S3    β”‚         β”‚
β”‚              β”‚ (Vectors) β”‚   β”‚ (Docs)   β”‚         β”‚
β”‚              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β”‚
β”‚                                                      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
        No external API calls β€’ Data stays private

Tech Stack

Frontend:

  • Next.js 14 (App Router)
  • TypeScript
  • Tailwind CSS + shadcn/ui
  • React Query

Backend:

  • Python 3.11 + FastAPI
  • LangChain
  • sentence-transformers
  • Qdrant (vector database)

LLM Inference:

  • Ollama (local inference)
  • Llama 3.1 8B (default, CPU)
  • Llama 3.1 70B (optional, GPU)

Infrastructure:

  • AWS ECS Fargate (web + API)
  • AWS EC2 Spot (GPU inference)
  • AWS RDS PostgreSQL (metadata)
  • AWS S3 (document storage)
  • AWS Cognito (authentication)
  • AWS CDK (Infrastructure as Code)

πŸš€ Quick Start

Option 1: Local Development (Docker Compose)

# Clone repository
git clone https://github.com/psadigh91/PrivateRAGForMidMarket.git
cd aws-private-rag

# Start all services
docker-compose up

# Open browser
open http://localhost:3000

Services:

Option 2: Deploy to AWS

# Prerequisites
npm install -g aws-cdk
aws configure

# Install dependencies
cd infrastructure
npm install

# Bootstrap CDK (first time only)
cdk bootstrap

# Deploy all stacks
cdk deploy --all

# Output will show your app URL
# https://your-alb-url.us-west-2.elb.amazonaws.com

Estimated AWS Cost: $50-$400/month (see Cost Breakdown)


πŸ“‹ Features

Document Management

  • βœ… Upload PDF, DOCX, TXT, MD, CSV, XLSX
  • βœ… OCR for scanned documents (AWS Textract)
  • βœ… Document versioning
  • βœ… Bulk upload (drag & drop)
  • βœ… Document preview
  • βœ… Soft delete with recovery

Intelligent Search

  • βœ… Semantic search (vector similarity)
  • βœ… Hybrid search (keyword + semantic)
  • βœ… Source citations with page numbers
  • βœ… Conversation history
  • βœ… Multi-document context
  • βœ… Streaming responses

Security & Compliance

  • βœ… Data encryption at rest (S3, RDS, EFS)
  • βœ… Encryption in transit (TLS 1.3)
  • βœ… Private VPC deployment
  • βœ… No external API calls (fully local LLM)
  • βœ… Audit logs (all document access)
  • βœ… PII detection and masking
  • βœ… Data retention policies
  • βœ… HIPAA compliance documentation
  • βœ… SOC 2 checklist

User Management

  • βœ… Multi-user workspaces
  • βœ… Role-based access control (admin, editor, viewer)
  • βœ… Email invitations
  • βœ… SSO integration (SAML, OAuth)
  • βœ… Usage quotas per user

Developer Experience

  • βœ… REST API with OpenAPI docs
  • βœ… Python SDK (pip install aws-private-rag-sdk)
  • βœ… Webhooks for events
  • βœ… CLI tool for management
  • βœ… Plugin system for custom processors

Admin Dashboard

  • βœ… Usage analytics
  • βœ… Cost tracking
  • βœ… Storage monitoring
  • βœ… Error logs
  • βœ… System health metrics

πŸ’° Cost Breakdown

Small Deployment (1-10 users, CPU only)

ECS Fargate (web + API):        $30/month
RDS PostgreSQL (db.t4g.micro):  $12/month
S3 (50GB documents):            $1.15/month
EFS (Qdrant persistence):       $3/month
Application Load Balancer:      $18/month
───────────────────────────────────────
Total: ~$65/month

Medium Deployment (10-50 users, GPU)

ECS Fargate (2 vCPU, 4GB):      $30/month
EC2 g5.xlarge Spot (GPU):       $220/month (70% savings vs on-demand)
RDS PostgreSQL (db.t4g.small):  $24/month
S3 (500GB documents):           $12/month
EFS (100GB):                    $30/month
ALB + data transfer:            $40/month
───────────────────────────────────────
Total: ~$356/month

Large Deployment (50-500 users)

ECS Fargate (4 vCPU, 8GB):      $60/month
EC2 g5.2xlarge Spot (GPU):      $440/month
RDS (db.m5.large):              $140/month
S3 (5TB):                       $115/month
EFS (1TB):                      $300/month
ALB + WAF:                      $150/month
───────────────────────────────────────
Total: ~$1,205/month

Note: Costs scale with usage. Free tier covers first year for small deployments.


πŸ› οΈ Installation

Prerequisites

Required:

  • Node.js 20+ (for CDK and frontend)
  • Python 3.11+ (for backend)
  • Docker Desktop (for local development)
  • AWS Account + CLI configured

Optional:

  • GPU (NVIDIA, 16GB+ VRAM) for Llama 3.1 70B

Local Development Setup

# 1. Clone repository
git clone https://github.com/your-org/aws-private-rag.git
cd aws-private-rag

# 2. Install backend dependencies
cd backend
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
pip install -r requirements.txt

# 3. Install frontend dependencies
cd ../frontend
npm install

# 4. Start services with Docker Compose
cd ..
docker-compose up -d

# 5. Run database migrations
cd backend
alembic upgrade head

# 6. Create initial admin user
python scripts/create_admin.py --email admin@example.com --password changeme

# 7. Start development servers
# Terminal 1: Backend
cd backend
uvicorn app.main:app --reload

# Terminal 2: Frontend
cd frontend
npm run dev

Open http://localhost:3000 and log in with admin credentials.


πŸŽ“ Usage

Basic Document Upload & Query

# 1. Upload a document
curl -X POST http://localhost:8000/api/documents \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -F "file=@contract.pdf" \
  -F "workspace_id=default"

# 2. Query the document
curl -X POST http://localhost:8000/api/query \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "What are the payment terms?",
    "workspace_id": "default"
  }'

Python SDK

from aws_private_rag import PrivateRAG

# Initialize client
client = PrivateRAG(
    api_url="http://localhost:8000",
    api_key="your-api-key"
)

# Upload document
doc = client.documents.upload(
    file_path="contract.pdf",
    workspace_id="default"
)

# Query
response = client.query(
    query="What are the payment terms?",
    workspace_id="default"
)

print(response.answer)
print(response.sources)  # Citations with page numbers

Web Interface

  1. Upload Documents: Drag & drop PDFs, Word docs, or text files
  2. Chat Interface: Ask questions about your documents
  3. View Sources: Click citations to see original text
  4. Manage Users: Invite team members, set permissions
  5. Monitor Usage: Track queries, storage, and costs

πŸ” Security

Data Protection

  • At Rest: All data encrypted with AWS KMS
  • In Transit: TLS 1.3 for all connections
  • Private Network: Runs in isolated VPC, no public internet access to data services
  • No External Calls: LLM runs locally, OpenAI/Anthropic never see your data

Authentication

  • AWS Cognito for user management
  • JWT tokens with 15-minute expiration
  • Refresh tokens with 7-day expiration
  • MFA support (TOTP)
  • SSO integration (SAML, OAuth)

Compliance

See COMPLIANCE.md for:

  • HIPAA compliance checklist
  • SOC 2 controls mapping
  • GDPR data handling guide
  • Audit logging setup

πŸ“Š Architecture Deep-Dive

Document Processing Pipeline

1. Upload β†’ S3 (encrypted bucket)
2. Extract text (PyPDF2, python-docx, Textract for OCR)
3. Chunk text (500 tokens, 50 token overlap)
4. Generate embeddings (all-MiniLM-L6-v2)
5. Store in Qdrant (with metadata: filename, page, user)
6. Index for search

Query Pipeline

1. User query β†’ Embed query
2. Vector search in Qdrant (top 5 chunks)
3. Retrieve original text from chunks
4. Inject into LLM prompt with context
5. Stream response to user
6. Log query + response for audit

LLM Options

Model Size Hardware Quality Speed Cost
Llama 3.1 8B 4.7GB CPU (8GB RAM) Good Fast $30/mo
Llama 3.1 70B 40GB GPU (16GB VRAM) Excellent Medium $220/mo
GPT-4 API* N/A Cloud Best Fast $2.50/1M tokens

*Not recommended for privacy use case, but available as hybrid fallback


πŸ§ͺ Testing

# Run unit tests
cd backend
pytest

# Run integration tests
pytest tests/integration/

# Run E2E tests
cd ../frontend
npm run test:e2e

# Load testing
cd ../tests
locust -f load_test.py --host=http://localhost:8000

Test Coverage:

  • Backend: 85%+ coverage
  • Frontend: 75%+ coverage
  • Integration tests for all API endpoints
  • E2E tests for critical user flows

🚒 Deployment

AWS CDK Deployment

cd infrastructure

# Configure deployment
export AWS_REGION=us-west-2
export DEPLOYMENT_MODE=serverless  # or 'gpu' or 'hybrid'

# Deploy
cdk deploy --all

# Outputs:
# - ApplicationURL: https://...
# - UserPoolId: us-west-2_...
# - APIEndpoint: https://...

Deployment Modes

Serverless (CPU only):

cdk deploy --context mode=serverless
# Llama 3.1 8B on CPU
# Cost: ~$65/month

GPU-Enhanced:

cdk deploy --context mode=gpu
# Llama 3.1 70B on GPU (EC2 Spot)
# Cost: ~$356/month

Hybrid (fallback to OpenAI API):

cdk deploy --context mode=hybrid
# Local by default, fallback to GPT-4 for complex queries
# Requires OPENAI_API_KEY in Secrets Manager

πŸ”„ Updates & Maintenance

# Update to latest version
git pull origin main

# Rebuild Docker images
docker-compose build --no-cache

# Update CDK deployment
cd infrastructure
cdk deploy --all

# Run database migrations
cd ../backend
alembic upgrade head

Update Notifications: Subscribe to GitHub releases for security updates.


🀝 Contributing

We welcome contributions! See CONTRIBUTING.md for guidelines.

Areas we need help:

  • πŸ› Bug reports and fixes
  • πŸ“š Documentation improvements
  • 🌍 Multi-language support
  • πŸ”Œ Plugin development (custom document processors)
  • πŸ§ͺ Test coverage improvements
  • 🎨 UI/UX enhancements

πŸ“„ License

MIT License - see LICENSE for details.


πŸ™ Acknowledgments

Built with:

Inspired by the need for privacy-first AI tools in regulated industries.


πŸ“ž Support


πŸ—ΊοΈ Roadmap

v1.0 (Current)

  • βœ… Core RAG pipeline
  • βœ… Document management
  • βœ… User authentication
  • βœ… AWS deployment

v1.1 (Next)

  • ⏳ Fine-tuning interface
  • ⏳ Advanced analytics
  • ⏳ Mobile app
  • ⏳ Slack/Teams integration

v2.0 (Future)

  • ⏳ Multi-modal support (images, audio)
  • ⏳ Real-time collaboration
  • ⏳ Knowledge graph visualization
  • ⏳ Auto-tagging and categorization

Built with ❀️ for the open-source community

Making AI private, secure, and accessible to everyone.

About

Private RAG platform with local LLM. Deploy your own AI in approximately 15 minutes. No external API call, no data sharing, no vendor lock-in Just your private data ready for an internal (or customer facing) Q&A agent.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages