Skip to content

Latest commit

Β 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 

Repository files navigation

πŸ€– RAG Coding Assistant

A production-grade Retrieval Augmented Generation (RAG) app for coding documents.

πŸ—οΈ Architecture

frontend/ (Streamlit)
    β”œβ”€β”€ app.py              ← Login/Register gate + navigation
    β”œβ”€β”€ api_client.py       ← HTTP client for backend
    └── pages/
        β”œβ”€β”€ chat.py         ← Multi-session chat UI
        β”œβ”€β”€ documents.py    ← Upload & manage documents
        └── settings.py     ← User settings

backend/ (FastAPI)
    β”œβ”€β”€ main.py             ← App entry point
    β”œβ”€β”€ rag.py              ← Core RAG engine
    β”œβ”€β”€ config.py           ← All configuration
    β”œβ”€β”€ models.py           ← SQLAlchemy DB models
    β”œβ”€β”€ database.py         ← Async DB connection
    β”œβ”€β”€ auth.py             ← JWT authentication
    β”œβ”€β”€ schemas.py          ← Pydantic schemas
    └── routers/
        β”œβ”€β”€ auth.py         ← /api/auth/*
        β”œβ”€β”€ documents.py    ← /api/documents/*
        └── chat.py         ← /api/chat/*

⚑ Quick Start

1. Clone & Install

git clone <your-repo>
cd rag-project
pip install -r requirements.txt

2. Configure

cp .env.example .env
# Edit .env and add your GEMINI_API_KEY

Get free Gemini API key: https://aistudio.google.com

3. Run

Option A β€” Two terminals:

# Terminal 1: Backend
uvicorn backend.main:app --reload --port 8000

# Terminal 2: Frontend
streamlit run frontend/app.py

Option B β€” Single script:

chmod +x start.sh
./start.sh

Option C β€” Docker:

docker-compose up --build

4. Open


πŸ”‘ Features

Feature Details
Auth JWT login/register, per-user data isolation
File Support PDF, TXT, MD, DOCX, CSV + URL scraping
Hybrid Search Semantic (ChromaDB) + BM25 keyword search
Reranking CrossEncoder for precision retrieval
Chat History Multi-turn conversations with session memory
Multi-session Create, switch, delete chat sessions
Source Viewer See exactly which chunks were used
Streaming Token-by-token response streaming endpoint
Docker Full containerized deployment

🧠 RAG Pipeline

Upload PDF
  β†’ PyMuPDF parse
  β†’ Sentence-aware chunking (500 chars, 50 overlap)
  β†’ SentenceTransformer embed (all-MiniLM-L6-v2)
  β†’ ChromaDB store (per-user collection)

User Question
  β†’ Embed question
  β†’ ChromaDB semantic search (top 10)
  β†’ BM25 keyword scoring
  β†’ Combine scores (60% semantic + 40% BM25)
  β†’ CrossEncoder rerank (top 5)
  β†’ Build prompt with context + history
  β†’ Gemini generate answer
  β†’ Return answer + sources

🌐 API Endpoints

Method Endpoint Description
POST /api/auth/register Create account
POST /api/auth/login Login β†’ token
GET /api/auth/me Current user
POST /api/documents/upload Upload file
POST /api/documents/url Scrape URL
GET /api/documents/ List documents
DELETE /api/documents/{id} Delete document
GET /api/chat/sessions List sessions
POST /api/chat/sessions New session
POST /api/chat/sessions/{id}/messages Send message
GET /api/chat/sessions/{id}/messages Get history
POST /api/chat/sessions/{id}/stream Stream response

πŸš€ Deploy Free

Platform Service Command
Streamlit Cloud Frontend Connect GitHub repo
Railway.app Backend railway up
Render.com Full stack Deploy via dashboard
Hugging Face Spaces Streamlit UI Upload to Space

About

electlion

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors