Skip to content

Rehman110-F/docmind

Repository files navigation

DocMind — RAG Chat Application

A full-stack Retrieval-Augmented Generation (RAG) application that lets users upload PDF documents and have intelligent conversations about them, powered by Google Gemini and FastAPI.

Python FastAPI React PostgreSQL Gemini


Features

  • PDF Upload & Processing — Upload any PDF and it gets converted into vector embeddings via FAISS
  • Conversational AI — Chat with your document using Google Gemini 2.5 Flash
  • Full Auth System — JWT-based authentication with signup and login
  • Persistent Chat History — All conversations saved to PostgreSQL, resumable anytime
  • ChatGPT-like Sidebar — Switch between multiple document chats
  • React Frontend — Clean, dark-themed UI built with Vite + React

Tech Stack

Layer Technology
Frontend React 18, Vite
Backend FastAPI, Python 3.12
AI Model Google Gemini 2.5 Flash
Vector Store FAISS
Database PostgreSQL 16
ORM SQLAlchemy + Alembic
Auth JWT (PyJWT) + bcrypt

Project Structure

docmind/
├── app.py                  # FastAPI main application
├── config.py               # Environment config
├── requirements.txt        # Python dependencies
│
├── api/
│   ├── auth.py             # Signup & login routes
│   └── security.py         # JWT token validation
│
├── dbsetup/
│   ├── db_config.py        # Database connection
│   ├── models.py           # SQLAlchemy models
│   └── migrations/         # Alembic migrations
│
├── dependencies/
│   ├── prepare_pdf.py      # PDF → FAISS vector index
│   └── prepare_prompt.py   # RAG prompt builder
│
└── frontend/               # React application
    └── src/
        └── App.jsx         # Main UI component

Getting Started

Prerequisites

  • Python 3.12
  • Node.js 20+
  • PostgreSQL 16
  • Google Gemini API key — get one at aistudio.google.com

1. Clone the Repository

git clone https://github.com/YOUR_USERNAME/docmind.git
cd docmind

2. Set Up Python Environment

python -m venv gemni_env
source gemni_env/bin/activate
pip install -r requirements.txt

3. Set Up PostgreSQL

sudo -u postgres psql
CREATE DATABASE rag_app;
CREATE USER your_user WITH PASSWORD 'your_password';
GRANT ALL PRIVILEGES ON DATABASE rag_app TO your_user;
\q

4. Configure Environment Variables

Create a .env file in the root directory:

DATABASE_URL=postgresql://your_user:your_password@localhost/rag_app
SECRET_KEY=your_super_secret_key_here
ALGORITHEM=HS256
API_KEY=your_google_gemini_api_key
PORT=8000

5. Run Database Migrations

alembic upgrade head

6. Start the Backend

python app.py

Backend runs at http://localhost:8000 Swagger docs at http://localhost:8000/docs

7. Set Up and Start the Frontend

cd frontend
npm install
npm run dev

Frontend runs at http://localhost:5173


API Endpoints

Auth

Method Endpoint Description
POST /api/v1/user/auth/signup Register new user
POST /api/v1/user/auth/login Login, returns JWT token

Chat

Method Endpoint Description
POST /api/upload Upload a PDF, creates a chat session
POST /api/chat Send a message in a session
GET /api/chat/sessions Get all sessions for the user
GET /api/chat/{session_id}/messages Get full message history

How It Works

User uploads PDF
      ↓
PDF split into chunks → embedded into vectors → saved as FAISS index (named by session_id)
      ↓
User sends a message
      ↓
Relevant chunks retrieved from FAISS → injected into Gemini prompt
      ↓
Gemini responds using document context
      ↓
Both messages saved to PostgreSQL
      ↓
User can resume any past conversation from the sidebar

Environment Variables Reference

Variable Description
DATABASE_URL PostgreSQL connection string
SECRET_KEY Secret key for signing JWT tokens
ALGORITHEM JWT algorithm (e.g. HS256)
API_KEY Google Gemini API key
PORT Port for uvicorn (default 8000)

License

MIT License — feel free to use and modify.

About

Full-stack RAG application — chat with your PDF documents using Google Gemini, FastAPI, FAISS, and React

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors