CoolFace
Apppublic

aryan-01001/knowledgebase

sourceHugging Faceupdated 4mo agoView on Hugging Face
0likes
App README

๐Ÿ“ 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 fastembed to run all-MiniLM-L6-v2 locally 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

mermaid
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

ComponentTechnology
FrameworkFastAPI (Python 3.10+)
PDF LoadingLangChain โ€” PyPDFLoader + RecursiveCharacterTextSplitter
Embeddingsfastembed โ€” ONNX runtime, all-MiniLM-L6-v2, no PyTorch
Vector Storefaiss-cpu โ€” IndexFlatL2, persisted to disk
Sparse Searchrank-bm25 โ€” BM25 Okapi, persisted to disk
FusionReciprocal Rank Fusion (RRF, k=60)
Language ModelGroq API โ€” llama-3.3-70b-versatile, SSE streaming

Frontend

ComponentTechnology
FrameworkReact 19 + Vite
StylingVanilla CSS โ€” Linear/Notion-inspired tinted neutrals
HTTP ClientAxios with upload progress hooks
PDF RenderingReact-PDF with web worker support
StreamingNative EventSource / SSE

๐Ÿ“‚ 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

powershell
cd backend
python -m venv venv
.\venv\Scripts\Activate.ps1
pip install -r requirements.txt

Create backend/.env:

env
GROQ_API_KEY=your_groq_api_key_here

Start the server:

powershell
uvicorn app.main:app --reload

API runs at http://127.0.0.1:8000 โ€” docs at http://127.0.0.1:8000/docs.

2. Frontend

powershell
cd frontend
npm install
npm run dev

Open http://localhost:5173.

For production, set in frontend/.env:

env
VITE_API_URL=https://your-backend.onrender.com

๐Ÿš€ Production Deployment

Backend โ†’ Hugging Face Spaces (Docker Space)

  1. 1.Push repo to GitHub.
  2. 2.Go to Hugging Face Spaces and click Create new Space.
  3. 3.Settings:
  4. 4.Space name: your-rag-backend
  5. 5.License: mit (or your choice)
  6. 6.Select the Space SDK: Docker -> Blank
  7. 7.Space hardware: Free (Provides 16GB RAM and 2 vCPUs)
  8. 8.Under "Space settings", add your Repository Secret: GROQ_API_KEY
  9. 9.Since your code is on GitHub, you can link it directly or push your code to the Hugging Face git remote. Ensure the backend folder contains the Dockerfile.
  10. 10.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 the backend directory.

(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

  1. 1.Create a Project on Vercel:
  2. 2.Root Directory: frontend
  3. 3.Framework: Vite
  4. 4.Output: dist
  5. 5.Add Environment Variable: VITE_API_URL = your Render backend URL.
  6. 6.Deploy.