Live Project: https://redagent.dev
RedAgent is a production-grade, multi-tenant RAG (Retrieval-Augmented Generation) platform designed as a scalable SaaS product. It provides organizations with a secure, conversational AI to interact with their private knowledge bases, transforming internal documentation into an intelligent, queryable resource.
Many companies possess vast amounts of information locked away in internal documents (PDFs, DOCX, etc.). Retrieving specific, timely information is often inefficient and time-consuming. RedAgent solves this by ingesting this unstructured data and providing a secure, intuitive chatbot interface for users to get instant, context-aware answers.
- Multi-Tenant Architecture: Guarantees complete data isolation and security for each client organization using a schema-per-tenant model in PostgreSQL.
- Role-Based Access Control (RBAC): Fine-grained permissions for Client Admins and Users, restricting access to document categories and platform features.
- End-to-End RAG Pipeline: A complete workflow for document management:
- Upload: Securely upload various document formats (PDF, DOCX, TXT).
- Ingest & Vectorize: Documents are automatically processed, chunked, and converted into vector embeddings using
pgvector. - Retrieve & Generate: Users receive accurate, context-aware answers from an AI, with responses grounded in the provided documents.
- Conversational AI Chat: An intuitive chat interface for users to query their organization's knowledge base in natural language.
- Automated Onboarding: A seamless, automated system for provisioning new tenants, including schema creation and migration.
- Scalable Cloud Infrastructure: Designed and deployed on AWS to ensure high availability, scalability, and security.
This platform was architected with security and scalability as first-class citizens.
-
Schema-per-Tenant Isolation: Each client organization operates within its own dedicated PostgreSQL schema. This prevents any possibility of data leakage between tenants and allows for independent scaling, backup, and extension for each client.
-
Dynamic Schema Management: New tenants are onboarded automatically. The application programmatically creates a new schema and runs all necessary table migrations, making the platform horizontally scalable with minimal operational overhead.
-
Asynchronous Backend: Built with FastAPI and
asyncpg, the entire backend is asynchronous, ensuring high performance and throughput for concurrent API requests and data processing tasks. -
Decoupled RAG Services: The services for document ingestion, vectorization, and querying are logically separated, allowing for independent maintenance and scaling of the AI pipeline.
| Category | Technologies |
|---|---|
| Backend | Python, FastAPI |
| Database | PostgreSQL, pgvector, SQLAlchemy (Async) |
| AI / ML | LangChain, OpenAI API, Google Generative AI API |
| Cloud & DevOps | AWS, Docker |
| Authentication | JWT (JSON Web Tokens), Passlib (for password hashing) |
- Python 3.10+
- PostgreSQL 12+ with the
pgvectoranduuid-osspextensions enabled. - An account with OpenAI or Google for Generative AI API keys.
- Docker (Recommended for easy database setup).
git clone https://github.com/pratiksontakke/redagent-backend.git
cd redagent-backendCreate a virtual environment and install the required dependencies.
python -m venv venv
source venv/bin/activate # On Windows, use `venv\Scripts\activate`
pip install -r requirements.txtCreate a .env file in the project root by copying the example file.
cp .env.example .envNow, edit the .env file with your specific configurations:
# .env
# Database Connection
DATABASE_URL=postgresql+asyncpg://USER:PASSWORD@HOST:PORT/DATABASE_NAME
# JWT Secret Key for Authentication
JWT_SECRET_KEY=your_strong_secret_key_here
# AI Provider API Keys (use at least one)
OPENAI_API_KEY=sk-...
GOOGLE_API_KEY=AIza...
# SMTP Configuration for sending OTP emails
SMTP_HOST=smtp.example.com
SMTP_PORT=587
SMTP_USER=your-email@example.com
SMTP_PASS=your-email-password
FROM_EMAIL=no-reply@redagent.devThe application uses a public schema for global data and creates tenant-specific schemas on the fly.
-
Connect to PostgreSQL as a superuser:
psql -U postgres -
Create the database and enable extensions:
CREATE DATABASE crm_rag_db; \c crm_rag_db; CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; CREATE EXTENSION IF NOT EXISTS "pgvector";
-
Run the public schema script: The application will create the public tables automatically on startup. No manual script run is needed.
Use Uvicorn to run the FastAPI server.
uvicorn api.main:app --host 0.0.0.0 --port 8000 --reloadThe application will be available at http://localhost:8000.
The interactive API documentation (Swagger UI) will be at http://localhost:8000/docs.
The project includes integration tests to verify key functionalities like the RAG pipeline.
Note: Ensure the FastAPI server is running before executing the tests. You will also need a valid JWT token from a logged-in user.
- Update the JWT_TOKEN in
test_rag_complete.pyandtest_upload.pywith a valid token. - Run the tests:
python test_rag_complete.py python test_upload.py
The API is organized by features. Key routers include:
/api/auth: User signup, login, and organization creation./api/users: CRUD operations for tenant users (Admin only)./api/categories: Management of document categories (Admin only)./api/kb: Knowledge Base operations, including document upload, status checks, and RAG queries/chat./admin/...: Super-admin-only routes for platform management.
For a complete and interactive list of all endpoints, please run the application and visit http://localhost:8000/docs.
Pratik Sontakke
- GitHub: @pratiksontakke
- LinkedIn: linkedin.com/in/pratik-sontakke
- Portfolio: pratiksontakke.com