A production-grade Retrieval Augmented Generation (RAG) app for coding documents.
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/*
git clone <your-repo>
cd rag-project
pip install -r requirements.txtcp .env.example .env
# Edit .env and add your GEMINI_API_KEYGet free Gemini API key: https://aistudio.google.com
Option A β Two terminals:
# Terminal 1: Backend
uvicorn backend.main:app --reload --port 8000
# Terminal 2: Frontend
streamlit run frontend/app.pyOption B β Single script:
chmod +x start.sh
./start.shOption C β Docker:
docker-compose up --build- π Frontend: http://localhost:8501
- π API Docs: http://localhost:8000/docs
| 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 |
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
| 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 |
| 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 |