A full-stack RAG platform that lets you chat with your documents, search the web, and collaborate on shared knowledge bases β all through a sleek glassmorphism UI.
Features Β· Quick Start Β· Architecture Β· RBAC Β· API Reference Β· Configuration
Synapse is a self-correcting RAG (Retrieval-Augmented Generation) system that transforms your documents into a searchable intelligence layer. It combines hybrid FAISS + BM25 retrieval, an Advanced RAG brain with query optimization, live web search, async document indexing via Celery, and a full role-based access control system for team collaboration β all streaming in real time through a polished glassmorphism interface.
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Synapse β at a glance β
β β
β Upload docs (PDF / DOCX / TXT / MD / XLSX) β
β β Async-indexed via Celery + Redis (or BackgroundTasks) β
β Simple RAG β FAISS + BM25 hybrid search β
β Advanced RAG β Query optimization + precision pull β
β Web Search β Serper (Google) + DuckDuckGo fallback β
β Summarizer β Chunked AI summarization β
β RBAC β Owner / Editor / Viewer per KB + Admin β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
- Knowledge Base Chat β Ask questions across one or more knowledge bases using hybrid retrieval
- Advanced RAG β Multi-step pipeline: query optimization β precision FAISS retrieval β reranking
- Web Search β Live Serper (Google) / DuckDuckGo search woven into answers
- Streaming Responses β Real-time NDJSON token-by-token output
- RAG Pipeline Visualizer β Live numbered step-by-step progress card during retrieval
- Citation Chips β Source pills with document name + color-coded relevance score
- π’ β₯ 85 % Β· π‘ 70β84 % Β· π΄ < 70 %
- Skeleton Loaders β Shimmer placeholders while the model is retrieving
- Session Memory β Persistent conversation history across browser sessions
- Multiple Knowledge Bases β Create, switch, and query multiple KBs at once
- Async Document Indexing β Celery workers process uploads in the background with automatic retry; falls back to FastAPI BackgroundTasks when Redis is not available
- Document Upload β Ingest PDF, DOCX, DOC, TXT, Markdown, XLSX (chunked + embedded in background)
- Document Preview β Read source files inline without leaving the chat
- Summarizer β Paste text or upload a file to get a summary + key takeaways
- FAISS Quantization β Optional 8-bit scalar quantization (4Γ memory reduction, ~1 % recall loss)
- Role-Based Access Control (RBAC) β Two-layer permission system
- Global roles:
admin/user - Per-KB roles:
owner/editor/viewer
- Global roles:
- KB Sharing β Owners invite teammates by username with a specific role
- Admin Panel β User management, role promotion/demotion, system-wide stats
- First-user Admin β The first registered account automatically gets
adminrole - Permission guards β Every API route enforces the minimum required role
| Provider | Notes |
|---|---|
| Groq | Default β fast Llama 3.1 inference (free tier available) |
| OpenAI | GPT-4o Mini and above |
| Google Gemini | Gemini 2.0 Flash (free tier + 1 M context) |
| NVIDIA NIM | Meta Llama via NVIDIA cloud API |
| AWS Bedrock | Claude 3 Haiku and other foundation models |
| Ollama | Fully local β no API key required |
- Glassmorphism dark-first design with aurora blue-violet gradient
- Light / Dark theme toggle (persisted)
- Settings page with tabbed navigation β LLM Providers Β· Web Search Β· Account
- Collapsible sidebar with session management and Admin nav item (visible to admins only)
- Role pills on KB cards; Share modal for member management; role-gated upload/delete controls
| Layer | Technology |
|---|---|
| API Framework | FastAPI 0.110+ |
| Server | Uvicorn (async) |
| Database | SQLite via SQLAlchemy async (PostgreSQL-ready) |
| Auth | JWT (PyJWT) + bcrypt |
| Task Queue | Celery 5.3+ with Redis broker |
| Vector Store | FAISS-CPU (flat + optional SQ8/SQ4 quantization) |
| Keyword Search | BM25 (rank-bm25) |
| Embeddings | Sentence Transformers (all-MiniLM-L6-v2) |
| LLM Orchestration | LangChain + LangGraph |
| Web Search | DuckDuckGo Search / Serper API |
| File Parsing | pdfplumber, python-docx, pandas |
| Encryption | AES-256-GCM (API keys at rest) |
| Layer | Technology |
|---|---|
| Framework | React 18 |
| Build Tool | Vite 5 |
| HTTP Client | Axios |
| Styling | Pure CSS with design tokens (no CSS framework) |
KnowledgeBase/
βββ src/ # FastAPI backend
β βββ main.py # App factory, lifespan, schema migrations
β βββ api/
β β βββ auth.py # Register / login / JWT (first-user admin)
β β βββ chat.py # Streaming chat endpoint (NDJSON)
β β βββ knowledge_base.py # KB CRUD + member management endpoints
β β βββ documents.py # Upload, list, delete, summarize
β β βββ admin.py # Admin-only: users, roles, stats
β βββ worker/
β β βββ celery_app.py # Celery app factory (reads settings)
β β βββ tasks/indexing.py # index_document Celery task (retry logic)
β βββ application/
β β βββ rag_service.py # SelfCorrectingRAG orchestrator
β β βββ hybrid_retriever.py # FAISS + BM25 + RRF fusion
β βββ core/
β β βββ settings.py # Pydantic settings (reads .env)
β β βββ search/ # Query processor, reranker, web search
β β βββ services/summarizer.py # Chunked AI summarizer
β βββ infrastructure/
β β βββ adapters/ # LLM, FAISS, BM25, DB adapters
β β βββ database/
β β βββ models.py # ORM: User, KnowledgeBase, Document,
β β β # ChatSession, Message, KBMember
β β βββ repositories.py # Typed repos incl. KBMemberRepository
β βββ shared/
β βββ rbac.py # ROLE_ORDER, require_admin, require_kb_role
β βββ encryption.py # AES-256-GCM for API keys
β βββ security.py # JWT helpers
β
βββ web/ # React frontend
β βββ src/
β βββ pages/
β β βββ Chat.jsx # Main chat interface + RAG controls
β β βββ KnowledgeBase.jsx # KB management + Share modal
β β βββ Settings.jsx # Tabbed settings (LLM / Web Search / Account)
β β βββ AdminPage.jsx # Admin panel: user table + stats
β βββ components/
β β βββ Sidebar.jsx # Nav with Admin item for admins
β β βββ AuthPage.jsx
β β βββ SummarizerPage.jsx
β β βββ ErrorBoundary.jsx
β βββ hooks/
β β βββ useDocuments.js # Module-level cache (instant re-nav)
β β βββ useRAGQuery.js # Streaming fetch + NDJSON parser
β βββ api/
β βββ documentApi.js # KB, document, member API calls
β βββ adminApi.js # Admin API calls
β
βββ data_storage/ # Auto-created at runtime
β βββ knowledge_base.db # SQLite database
β βββ uploads/ # Uploaded source files
β βββ indices/ # FAISS + BM25 index files
β
βββ docker-compose.yml # Redis + backend + Celery worker + frontend
βββ Dockerfile.backend
βββ requirements.txt
βββ .env # API keys & config (see setup)
- Python 3.11+
- Node.js 18+
- At least one LLM API key or Ollama running locally
- Redis (optional β only needed for Celery; omit for BackgroundTasks mode)
git clone <repo-url>
cd KnowledgeBase
python -m venv .venv
# Windows
.venv\Scripts\activate
# macOS / Linux
source .venv/bin/activate
pip install -r requirements.txtCopy .env.example to .env and fill in your values:
# ββ Security (required) ββββββββββββββββββββββββββββββββββββ
JWT_SECRET=your-secure-256-bit-secret-here
ENCRYPTION_KEY=your-64-char-hex-key-here # python -c "import secrets; print(secrets.token_hex(32))"
# ββ LLM Provider (pick at least one) ββββββββββββββββββββββ
GROQ_API_KEY=gsk_... # https://console.groq.com (free tier)
OPENAI_API_KEY=sk-...
GEMINI_API_KEY=AIza... # https://aistudio.google.com (free tier)
# ββ Web Search (optional) ββββββββββββββββββββββββββββββββββ
SERPER_API_KEY=... # Leave blank β DuckDuckGo fallback
# ββ Celery (optional β leave blank for BackgroundTasks) ββββ
CELERY_BROKER_URL=redis://localhost:6379/0
CELERY_RESULT_BACKEND=redis://localhost:6379/0
# ββ CORS βββββββββββββββββββββββββββββββββββββββββββββββββββ
CORS_ORIGINS=http://localhost:5173,http://localhost:3000uvicorn src.main:app --reload --port 8000Interactive API docs: http://localhost:8000/docs
Only needed if CELERY_BROKER_URL is set. Without it, document indexing runs as FastAPI BackgroundTasks.
# Requires Redis to be running
celery -A src.worker.celery_app.celery_app worker --loglevel=info --concurrency=2cd web
npm install
npm run devOpen http://localhost:5173
- Register β the first account automatically becomes admin
- Go to Settings β LLM Providers β enter your API key β Save & Activate
- Go to Knowledge Base β create a KB β upload documents
- Go to Chat β select your KB β ask questions
Starts Redis + FastAPI backend + Celery worker + React frontend in one command:
cp .env.example .env # fill in JWT_SECRET and at least one API key
docker compose up --build| Service | Port | Description |
|---|---|---|
redis |
6379 | Celery broker + result backend |
backend |
8000 | FastAPI + Uvicorn |
celery_worker |
β | Async document indexing |
frontend |
3000 | React (Vite production build) |
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β React Frontend :5173 β
β β
β AuthPage β App.jsx β Sidebar + Chat / KB / Settings / Admin β
β β
β Chat.jsx β
β ββ RAG controls (KB selector, Advanced RAG, Web Search) β
β ββ PipelineProgress (live step visualizer) β
β ββ Citation chips (source + relevance %) β
β β
β KnowledgeBase.jsx β
β ββ Role pills (owner / editor / viewer) β
β ββ Share modal β member invite + role management β
β ββ Upload / delete gated by role β
β β
β AdminPage.jsx β
β ββ Stats cards + user table (promote / demote) β
βββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββ
β REST + NDJSON streaming (Axios + JWT)
βββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββ
β FastAPI Backend :8000 β
β β
β RBAC middleware β
β ββ require_admin() β global admin guard β
β ββ require_kb_role() β per-KB role guard (admins bypass) β
β β
β POST /api/chat (streaming NDJSON) β
β ββ JWT auth + KB viewer check β
β ββ Resolve LLM adapter (per-user provider + key) β
β ββ Optional: WebSearch β inject results into context β
β ββ SelfCorrectingRAG.answer(query, context) β
β β ββ HybridRetriever β FAISS + BM25 + RRF fusion β
β β ββ LLM.chat(system + context + query) β
β β ββ confidence_score < threshold β retry β
β ββ Stream: status β content β meta (sources, confidence) β
β β
β POST /api/kb/{id}/documents (upload) β
β ββ editor+ check β save file β dispatch to Celery / BG task β
ββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββββ
β
ββββββββββββββ΄βββββββββββββββββββββββββββββββ
β β
βββββββΌβββββββ βββββββββββββββββββββββββββββββββββββββββββββββββ
β SQLite DB β β Celery Worker β
β users β β index_document task β
β kb_membersβ β ββ extract text (PDF/DOCX/TXT/XLSX) β
β knowledge β β ββ chunk + embed (SentenceTransformer) β
β _bases β β ββ build FAISS + BM25 index β
β documents β β ββ update DB status (indexed / failed) β
β sessions β β max_retries=2, retry_delay=30s β
β messages β βββββββββββββββββββββββββββββββββββββββββββββββββ
ββββββββββββββ
| Action | Viewer | Editor | Owner | Admin |
|---|---|---|---|---|
| Chat with KB / view documents | β | β | β | β |
| Upload / delete documents | β | β | β | β |
| Delete KB | β | β | β | β |
| Manage members (invite / remove / change role) | β | β | β | β |
| View all users | β | β | β | β |
| Change global user roles | β | β | β | β |
| Access any KB regardless of membership | β | β | β | β |
- Global role (
user/admin) is stored onUser.role. The first registered user automatically becomes admin. - Per-KB role (
viewer/editor/owner) is stored in theKBMemberjoin table. Creating a KB auto-enrolls the creator as owner. - Admin users bypass all per-KB membership checks β they can access everything.
- Existing knowledge bases are auto-migrated on startup: every KB gets an owner
KBMemberrecord for its creator.
- Open Knowledge Base β select a KB you own
- Click the π₯ icon beside the KB name
- In the Share modal: type a username, pick a role, click Invite
- Members can be re-roled or removed at any time
Documents are indexed asynchronously so uploads return instantly.
Set CELERY_BROKER_URL and CELERY_RESULT_BACKEND in .env:
CELERY_BROKER_URL=redis://localhost:6379/0
CELERY_RESULT_BACKEND=redis://localhost:6379/0Start the worker:
celery -A src.worker.celery_app.celery_app worker --loglevel=info --concurrency=2Features: persistent queue, survives server restarts, automatic retry (up to 2Γ with 30 s delay), per-task status tracking.
Leave both CELERY_* vars empty. Indexing runs inside FastAPI's BackgroundTasks β zero extra infrastructure, fine for local development.
Reduce memory footprint of large FAISS indices:
FAISS_QUANTIZE=true
FAISS_QUANTIZE_TYPE=sq8 # sq8 = 8-bit (4Γ reduction, ~1% recall loss)
# sq4 = 4-bit (8Γ reduction, ~3% recall loss)Set FAISS_QUANTIZE=false to use raw float32 IndexFlatL2.
| Mode | What happens |
|---|---|
| No KB selected | General LLM chat (no retrieval) |
| KB selected | Simple RAG β FAISS + BM25 hybrid search |
| KB + Advanced RAG | Query optimization β precision retrieval β reranking |
| + Web Search | Augments any mode with live search results |
Each line from POST /api/chat is a JSON object:
{ "type": "session", "session_id": 42 }
{ "type": "status", "content": "π Searching knowledge base..." }
{ "type": "content", "delta": "According to " }
{ "type": "meta", "session_id": 42, "sources": [...] }
{ "type": "error", "content": "..." }| Method | Endpoint | Description |
|---|---|---|
POST |
/auth/register |
Create account, returns JWT + role |
POST |
/auth/login |
Login, returns JWT + role |
GET |
/auth/me |
Current user profile (includes role) |
GET/POST |
/auth/settings |
Read / update user settings |
| Method | Endpoint | Description |
|---|---|---|
POST |
/api/chat |
Streaming chat (NDJSON) |
GET |
/api/sessions |
List chat sessions |
POST |
/api/sessions |
Create session |
DELETE |
/api/sessions/{id} |
Delete session |
GET |
/api/models |
List models for active provider |
| Method | Endpoint | Min Role | Description |
|---|---|---|---|
GET |
/api/kb |
β | List KBs the caller is a member of |
POST |
/api/kb |
β | Create KB (caller becomes owner) |
GET |
/api/kb/{id} |
viewer | Get KB detail |
DELETE |
/api/kb/{id} |
owner | Delete KB + all documents |
GET |
/api/kb/{id}/documents |
viewer | List documents |
POST |
/api/kb/{id}/documents |
editor | Upload file |
DELETE |
/api/documents/{id} |
editor | Delete document |
GET |
/api/documents/{id}/file |
viewer | Download source file |
POST |
/api/summarize |
β | Summarize text |
POST |
/api/summarize/file |
β | Upload + summarize file |
| Method | Endpoint | Min Role | Description |
|---|---|---|---|
GET |
/api/kb/{id}/members |
viewer | List members + roles |
POST |
/api/kb/{id}/members |
owner | Invite user by username |
PUT |
/api/kb/{id}/members/{uid} |
owner | Change member role |
DELETE |
/api/kb/{id}/members/{uid} |
owner | Remove member |
| Method | Endpoint | Description |
|---|---|---|
GET |
/api/admin/users |
Paginated user list |
PUT |
/api/admin/users/{id}/role |
Promote / demote user |
GET |
/api/admin/stats |
Total users / KBs / documents |
| Method | Endpoint | Description |
|---|---|---|
GET |
/health |
Health check |
GET |
/docs |
Swagger UI |
| Variable | Default | Description |
|---|---|---|
JWT_SECRET |
dev default | Change in production |
ENCRYPTION_KEY |
β | 64-char hex key for API key encryption at rest |
DATABASE_URL |
sqlite:///data_storage/knowledge_base.db |
SQLite or PostgreSQL URL |
CORS_ORIGINS |
http://localhost:3000 |
Comma-separated allowed origins |
CELERY_BROKER_URL |
"" |
Redis URL β leave empty for BackgroundTasks |
CELERY_RESULT_BACKEND |
"" |
Redis URL for task results |
FAISS_QUANTIZE |
true |
Enable SQ8 quantization |
FAISS_QUANTIZE_TYPE |
sq8 |
sq8 or sq4 |
GROQ_API_KEY |
β | Groq API key |
GROQ_MODEL |
llama-3.1-8b-instant |
Groq model |
OPENAI_API_KEY |
β | OpenAI API key |
OPENAI_MODEL |
gpt-4o-mini |
OpenAI model |
GEMINI_API_KEY |
β | Google Gemini key |
GEMINI_MODEL |
gemini-2.0-flash |
Gemini model |
NVIDIA_API_KEY |
β | NVIDIA NIM key |
AWS_ACCESS_KEY_ID |
β | AWS credentials |
SERPER_API_KEY |
β | Google Search via Serper (optional) |
EMBEDDER_MODEL |
all-MiniLM-L6-v2 |
Sentence Transformer model |
CONFIDENCE_THRESHOLD |
0.5 |
Min RAG score before retry |
OLLAMA_BASE_URL |
http://localhost:11434 |
Ollama server URL |
LOG_LEVEL |
INFO |
Logging verbosity |
DEBUG |
false |
FastAPI debug mode |
| Format | Parser |
|---|---|
.pdf |
pdfplumber (fallback: PyPDF2) |
.docx / .doc |
python-docx |
.xlsx / .xls |
pandas + openpyxl |
.txt / .md |
Built-in |
Files are indexed asynchronously β the upload endpoint returns immediately while chunking, embedding, and FAISS/BM25 indexing happen in the background.
# Backend with hot reload
uvicorn src.main:app --reload --port 8000
# Celery worker (separate terminal, needs Redis)
celery -A src.worker.celery_app.celery_app worker --loglevel=info
# Frontend with HMR
cd web && npm run dev
# Run tests
pytest tests/ -v
# Production frontend build
cd web && npm run build # outputs to web/dist/- Create
src/infrastructure/adapters/myprovider_llm_adapter.pyimplementingLLMPort - Add a branch in
src/infrastructure/adapters/llm_provider_factory.py - Add static fallback models in
src/api/chat.py - Add the provider tab to
web/src/pages/Settings.jsx
- Streaming responses (NDJSON)
- Hybrid FAISS + BM25 retrieval with RRF fusion
- Advanced RAG (query optimization + reranking)
- Multi-KB search
- Live web search (Serper + DuckDuckGo)
- RAG pipeline step visualizer
- Citation chips with relevance scores
- Skeleton loaders
- Settings page tabs
- API key encryption at rest (AES-256-GCM)
- Async document indexing with Celery + Redis
- FAISS quantization (SQ8/SQ4)
- Role-based access control (Admin / Owner / Editor / Viewer)
- KB sharing & member management
- Admin panel (user list, role management, system stats)
- Docker Compose (Redis + backend + Celery + frontend)
- OCR for scanned PDFs
- Multimodal RAG (images in documents)
- Export chat history (PDF / Markdown)
- Email invitations for KB sharing
MIT License β see LICENSE for details.
Built with FastAPI Β· React Β· LangChain Β· FAISS Β· Sentence Transformers Β· Celery