Skip to content

tailorgunjan93/KnowledgeBase

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

32 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Synapse β€” AI Knowledge Base

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.

Python FastAPI React Celery License

Features Β· Quick Start Β· Architecture Β· RBAC Β· API Reference Β· Configuration


Overview

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   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Features

Chat & RAG

  • 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

Knowledge Management

  • 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)

Collaboration & Access Control

  • Role-Based Access Control (RBAC) β€” Two-layer permission system
    • Global roles: admin / user
    • Per-KB roles: owner / editor / viewer
  • 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 admin role
  • Permission guards β€” Every API route enforces the minimum required role

LLM Providers

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

UI / UX

  • 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

Tech Stack

Backend

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)

Frontend

Layer Technology
Framework React 18
Build Tool Vite 5
HTTP Client Axios
Styling Pure CSS with design tokens (no CSS framework)

Project Structure

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)

Quick Start

Prerequisites

  • 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)

1 β€” Clone & install backend

git clone <repo-url>
cd KnowledgeBase

python -m venv .venv

# Windows
.venv\Scripts\activate
# macOS / Linux
source .venv/bin/activate

pip install -r requirements.txt

2 β€” Configure environment

Copy .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:3000

3 β€” Start the backend

uvicorn src.main:app --reload --port 8000

Interactive API docs: http://localhost:8000/docs

4 β€” (Optional) Start Celery worker

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=2

5 β€” Start the frontend

cd web
npm install
npm run dev

Open http://localhost:5173

6 β€” First run

  1. Register β€” the first account automatically becomes admin
  2. Go to Settings β†’ LLM Providers β†’ enter your API key β†’ Save & Activate
  3. Go to Knowledge Base β†’ create a KB β†’ upload documents
  4. Go to Chat β†’ select your KB β†’ ask questions

Docker Compose

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)

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                     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  β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Role-Based Access Control

Permission Matrix

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 ❌ ❌ ❌ βœ…

How it works

  • Global role (user / admin) is stored on User.role. The first registered user automatically becomes admin.
  • Per-KB role (viewer / editor / owner) is stored in the KBMember join 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 KBMember record for its creator.

Sharing a Knowledge Base

  1. Open Knowledge Base β†’ select a KB you own
  2. Click the πŸ‘₯ icon beside the KB name
  3. In the Share modal: type a username, pick a role, click Invite
  4. Members can be re-roled or removed at any time

Async Document Indexing

Documents are indexed asynchronously so uploads return instantly.

With Celery + Redis (recommended for production)

Set CELERY_BROKER_URL and CELERY_RESULT_BACKEND in .env:

CELERY_BROKER_URL=redis://localhost:6379/0
CELERY_RESULT_BACKEND=redis://localhost:6379/0

Start the worker:

celery -A src.worker.celery_app.celery_app worker --loglevel=info --concurrency=2

Features: persistent queue, survives server restarts, automatic retry (up to 2Γ— with 30 s delay), per-task status tracking.

Without Redis (BackgroundTasks fallback)

Leave both CELERY_* vars empty. Indexing runs inside FastAPI's BackgroundTasks β€” zero extra infrastructure, fine for local development.

FAISS Quantization

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.


Chat Modes

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

NDJSON stream format

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": "..." }

API Reference

Authentication

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

Chat

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

Knowledge Bases & Documents

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

KB Members

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

Admin (admin role required)

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

System

Method Endpoint Description
GET /health Health check
GET /docs Swagger UI

Configuration

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

Supported File Types

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.


Development

# 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/

Adding a new LLM provider

  1. Create src/infrastructure/adapters/myprovider_llm_adapter.py implementing LLMPort
  2. Add a branch in src/infrastructure/adapters/llm_provider_factory.py
  3. Add static fallback models in src/api/chat.py
  4. Add the provider tab to web/src/pages/Settings.jsx

Roadmap

  • 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

License

MIT License β€” see LICENSE for details.


Built with FastAPI Β· React Β· LangChain Β· FAISS Β· Sentence Transformers Β· Celery

Releases

No releases published

Packages

 
 
 

Contributors