Privacy-first RAG (Retrieval-Augmented Generation) platform that runs entirely in your AWS account. Your documents never leave your infrastructure.
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
β
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
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Your AWS Account / VPC β
β β
β ββββββββββββ ββββββββββββ ββββββββββββ β
β β Next.js ββ β FastAPI ββ β Llama 3 β β
β β Frontend β β Backend β β (Local) β β
β ββββββββββββ ββββββββββββ ββββββββββββ β
β β β β
β βββββββββββββ ββββββββββββ β
β β Qdrant β β S3 β β
β β (Vectors) β β (Docs) β β
β βββββββββββββ ββββββββββββ β
β β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
No external API calls β’ Data stays private
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)
# 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:3000Services:
- Frontend: http://localhost:3000
- Backend API: http://localhost:8000
- API Docs: http://localhost:8000/docs
- Qdrant UI: http://localhost:6333/dashboard
# 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.comEstimated AWS Cost: $50-$400/month (see Cost Breakdown)
- β 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
- β Semantic search (vector similarity)
- β Hybrid search (keyword + semantic)
- β Source citations with page numbers
- β Conversation history
- β Multi-document context
- β Streaming responses
- β 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
- β Multi-user workspaces
- β Role-based access control (admin, editor, viewer)
- β Email invitations
- β SSO integration (SAML, OAuth)
- β Usage quotas per user
- β 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
- β Usage analytics
- β Cost tracking
- β Storage monitoring
- β Error logs
- β System health metrics
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
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
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.
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
# 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 devOpen http://localhost:3000 and log in with admin credentials.
# 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"
}'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- Upload Documents: Drag & drop PDFs, Word docs, or text files
- Chat Interface: Ask questions about your documents
- View Sources: Click citations to see original text
- Manage Users: Invite team members, set permissions
- Monitor Usage: Track queries, storage, and costs
- 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
- AWS Cognito for user management
- JWT tokens with 15-minute expiration
- Refresh tokens with 7-day expiration
- MFA support (TOTP)
- SSO integration (SAML, OAuth)
See COMPLIANCE.md for:
- HIPAA compliance checklist
- SOC 2 controls mapping
- GDPR data handling guide
- Audit logging setup
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
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
| 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
# 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:8000Test Coverage:
- Backend: 85%+ coverage
- Frontend: 75%+ coverage
- Integration tests for all API endpoints
- E2E tests for critical user flows
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://...Serverless (CPU only):
cdk deploy --context mode=serverless
# Llama 3.1 8B on CPU
# Cost: ~$65/monthGPU-Enhanced:
cdk deploy --context mode=gpu
# Llama 3.1 70B on GPU (EC2 Spot)
# Cost: ~$356/monthHybrid (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# 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 headUpdate Notifications: Subscribe to GitHub releases for security updates.
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
MIT License - see LICENSE for details.
Built with:
- LangChain - RAG orchestration
- Qdrant - Vector database
- Ollama - Local LLM inference
- Next.js - Frontend framework
- FastAPI - Backend framework
- shadcn/ui - UI components
Inspired by the need for privacy-first AI tools in regulated industries.
- π Documentation: docs/
- π Bug Reports: GitHub Issues
- π¬ Discussions: GitHub Discussions
- π§ Email: psadigh91@gmail.com
- β Core RAG pipeline
- β Document management
- β User authentication
- β AWS deployment
- β³ Fine-tuning interface
- β³ Advanced analytics
- β³ Mobile app
- β³ Slack/Teams integration
- β³ 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.