aryan-01001/knowledgebase
๐ Enterprise Document Search & Knowledge Base Workspace
A high-performance, citation-backed Retrieval-Augmented Generation (RAG) platform designed for engineering teams and internal documentation hubs. Inspired by the clean, information-dense visual languages of Notion, Linear, GitHub, and Confluence, this platform enables teams to index PDFs, run hybrid semantic + keyword searches across deep technical documentation, and extract citation-backed syntheses.
Clicking any citation immediately focuses the integrated PDF Modal Viewer exactly on the page where the source evidence was found.
๐ Key Capabilities
- Hybrid Search (RRF): Merges dense semantic vectors (FAISS via
fastembed) and sparse keyword matches (BM25 Okapi) using Reciprocal Rank Fusion (RRF) for optimal retrieval precision. - Lightweight ONNX Embeddings: Uses
fastembedto runall-MiniLM-L6-v2locally via ONNX runtime โ no PyTorch required, ~150MB RAM footprint. - Real-Time Token Streaming: Answers stream token-by-token via Server-Sent Events (SSE) using Groq's streaming API.
- Precise Citation Backing: Every answer is strictly grounded on uploaded documents with page-level citation anchors (
[1],[2],[3]). - Disk Persistence: FAISS indices, BM25 registries, and chunk metadata persist to
backend/data/indices/and survive server restarts. - Professional Workspace UI: Clean, tinted neutral palette modelled after Linear, GitHub, and Confluence โ no AI chatbot aesthetics.
๐๏ธ System Architecture
graph TD
subgraph Ingestion ["1. Document Ingestion"]
PDF[PDF Upload] --> Loader[PyPDFLoader]
Loader --> Splitter[RecursiveCharacterTextSplitter\nchunk_size=800, overlap=200]
Splitter --> Chunks[Text Chunks + Metadata]
Chunks --> Embed[fastembed ONNX\nall-MiniLM-L6-v2]
Embed --> FAISS[(FAISS Index\nPersisted to Disk)]
Chunks --> BM25Build[BM25Okapi Indexer]
BM25Build --> BM25[(BM25 Index\nPersisted to Disk)]
end
subgraph Retrieval ["2. Retrieval & Fusion"]
Q[User Query] --> VecSearch[FAISS Vector Search\nTop-10]
Q --> KwSearch[BM25 Keyword Search\nTop-10]
FAISS -.-> VecSearch
BM25 -.-> KwSearch
VecSearch --> RRF[Reciprocal Rank Fusion\nk=60]
KwSearch --> RRF
RRF --> Top5[Top 5 Fused Chunks]
end
subgraph Generation ["3. Generation & Streaming"]
Top5 --> Prompt[Context-Enriched Prompt]
Q --> Prompt
Prompt --> Groq[Groq SSE Stream\nllama-3.3-70b-versatile]
Groq --> SSE[Server-Sent Events]
end
subgraph UI ["4. React Workspace Client"]
SSE --> Stream[Typewriter Stream]
Stream --> Citations[Click Citation]
Citations --> PDF2[PDF Modal Viewer\nZoom + Paging]
end๐ ๏ธ Tech Stack
Backend
Frontend
๐ Project Structure
Production-Rag/
โโโ backend/
โ โโโ app/
โ โ โโโ generator.py # Groq LLM prompts & SSE streaming
โ โ โโโ ingest.py # PDF parsing, chunking, FAISS + BM25 persistence
โ โ โโโ main.py # FastAPI routes (upload, search, documents, delete)
โ โ โโโ reranker.py # RRF score-based sorting (no CrossEncoder)
โ โ โโโ retrieval.py # fastembed ONNX embeddings, FAISS + BM25 + RRF
โ โโโ data/
โ โ โโโ documents/ # Uploaded PDFs served as static files
โ โ โโโ indices/ # FAISS .index + BM25 .pkl + chunks.json per doc
โ โโโ .env # GROQ_API_KEY
โ โโโ Procfile # Render start command
โ โโโ requirements.txt # Minimal Python dependencies
โโโ frontend/
โ โโโ src/
โ โ โโโ App.jsx # Main workspace panel + search console
โ โ โโโ App.css # Layout and card styles
โ โ โโโ ChatMessage.jsx # Query / Synthesis timeline entries
โ โ โโโ index.css # CSS variables, color tokens, scrollbars
โ โ โโโ PdfModal.jsx # PDF viewer modal with zoom + paging
โ โ โโโ Sidebar.jsx # File explorer + upload zone
โ โ โโโ SourcesPanel.jsx# Extracted evidence reference panel
โ โ โโโ Typewriter.jsx # SSE token streaming printer
โ โโโ .env # VITE_API_URL (set to backend URL for prod)
โ โโโ vite.config.js
โโโ readme.mdโ๏ธ Running Locally
1. Backend
cd backend
python -m venv venv
.\venv\Scripts\Activate.ps1
pip install -r requirements.txtCreate backend/.env:
GROQ_API_KEY=your_groq_api_key_hereStart the server:
uvicorn app.main:app --reloadAPI runs at http://127.0.0.1:8000 โ docs at http://127.0.0.1:8000/docs.
2. Frontend
cd frontend
npm install
npm run devOpen http://localhost:5173.
For production, set in frontend/.env:
VITE_API_URL=https://your-backend.onrender.com๐ Production Deployment
Backend โ Hugging Face Spaces (Docker Space)
- Push repo to GitHub.
- Go to Hugging Face Spaces and click Create new Space.
- Settings:
- Space name:
your-rag-backend - License:
mit(or your choice) - Select the Space SDK:
Docker->Blank - Space hardware:
Free(Provides 16GB RAM and 2 vCPUs) - Under "Space settings", add your Repository Secret:
GROQ_API_KEY - Since your code is on GitHub, you can link it directly or push your code to the Hugging Face git remote. Ensure the
backendfolder contains theDockerfile. - Note: Because the Space starts from the root, ensure your Dockerfile is placed at the root or configure the Space to build from
backend/Dockerfile. The provided Dockerfile assumes it's run from thebackenddirectory.
(Alternative: You can simply copy the contents of your `backend` folder into the Hugging Face Space file editor if you don't want to use git).
Frontend โ Vercel
- Create a Project on Vercel:
- Root Directory:
frontend - Framework:
Vite - Output:
dist - Add Environment Variable:
VITE_API_URL= your Render backend URL. - Deploy.
