Skip to content

saadkhan2003/Documind_AI_Document_Assistant

Repository files navigation

🤖 Documind - AI Document Assistant

Documind Banner

Transform your documents into intelligent conversations

React FastAPI Python LangChain ChromaDB

FeaturesDemoInstallationUsageArchitectureDeployment


📋 Table of Contents


🌟 Overview

Documind is an intelligent AI-powered document assistant that enables you to have natural conversations with your documents. Upload PDFs, ask questions, and get accurate answers backed by source citations using advanced Retrieval-Augmented Generation (RAG) technology.

Why Documind?

  • 🎯 Accurate Answers: Get precise information from your documents with source citations
  • 💬 Natural Conversations: Chat with your documents as if talking to an expert
  • 🔒 Secure & Private: User-specific document storage with JWT authentication
  • 📚 Multiple Documents: Manage and chat with multiple documents independently
  • 🚀 Fast & Efficient: Built with modern async frameworks for optimal performance
  • 💾 Persistent History: All conversations are saved and retrievable

✨ Features

🔐 Authentication & Security

  • User Registration & Login with JWT token-based authentication
  • Password Hashing using bcrypt for secure credential storage
  • Protected Routes ensuring only authenticated users access resources
  • User Isolation - each user can only access their own documents

📄 Document Management

  • PDF Upload with drag-and-drop interface
  • Automatic Processing - documents are chunked and embedded automatically
  • Document-Specific Chats - each document has its own conversation thread
  • Delete Documents - easy document management
  • Multi-Document Support - upload and manage multiple documents

💬 Intelligent Chat

  • RAG-Powered Responses using vector similarity search
  • Context-Aware Answers based on document content
  • Source Citations with exact page references
  • Chat History persisted per document per user
  • Real-Time Streaming for responsive user experience

🎨 Modern UI/UX

  • ChatGPT-Inspired Interface for familiar user experience
  • Responsive Design works on desktop and mobile
  • Dark Mode Ready (optional feature)
  • Interactive Sidebar for document navigation
  • Markdown Support for formatted responses

🛠️ Tech Stack

Backend

  • FastAPI - Modern, fast web framework for building APIs
  • LangChain - Framework for developing LLM applications
  • ChromaDB - Vector database for embeddings
  • OpenAI API - (via OpenRouter) for LLM completions
  • Sentence Transformers - Free local embeddings
  • SQLite - Lightweight database for user data and chat history
  • JWT - JSON Web Tokens for secure authentication

Frontend

AI/ML

  • LangChain - Orchestration framework
  • ChromaDB - Vector store for semantic search
  • Sentence Transformers - all-MiniLM-L6-v2 for embeddings
  • OpenRouter - Access to multiple LLMs (GPT-4, Claude, etc.)

🏗️ Architecture

┌─────────────────────────────────────────────────────────────┐
│                         Frontend (React)                     │
│  ┌──────────────┐  ┌──────────────┐  ┌──────────────┐      │
│  │   Auth UI    │  │  Document    │  │  Chat UI     │      │
│  │              │  │  Management  │  │              │      │
│  └──────────────┘  └──────────────┘  └──────────────┘      │
└─────────────────────────────────────────────────────────────┘
                            │ HTTP/REST
┌─────────────────────────────────────────────────────────────┐
│                      Backend (FastAPI)                       │
│  ┌──────────────┐  ┌──────────────┐  ┌──────────────┐      │
│  │ Auth Routes  │  │  API Routes  │  │ RAG Service  │      │
│  │   (JWT)      │  │              │  │              │      │
│  └──────────────┘  └──────────────┘  └──────────────┘      │
│                            │                                 │
│  ┌──────────────┐  ┌──────────────┐  ┌──────────────┐      │
│  │   SQLite     │  │   ChromaDB   │  │  LLM Client  │      │
│  │  (Users,     │  │  (Vectors)   │  │ (OpenRouter) │      │
│  │   History)   │  │              │  │              │      │
│  └──────────────┘  └──────────────┘  └──────────────┘      │
└─────────────────────────────────────────────────────────────┘

Data Flow

  1. User uploads PDF → Processed into chunks → Embedded with Sentence Transformers → Stored in ChromaDB
  2. User asks question → Embedded with same model → Similar chunks retrieved from ChromaDB
  3. Retrieved context + Question → Sent to LLM via OpenRouter → Response streamed back
  4. Chat history → Saved to SQLite → Loaded when document is selected

🚀 Installation

Prerequisites

  • Python 3.11+
  • Node.js 16+ and npm
  • Git

1. Clone the Repository

git clone https://github.com/saadkhan2003/Documind---AI-Document-Assistant.git
cd Documind---AI-Document-Assistant

2. Backend Setup

# Install Python dependencies
pip install -r requirements.txt

# Create .env file
# Copy the example below and add your API keys

Create a .env file in the root directory:

# OpenRouter API Key (get from https://openrouter.ai/)
OPENROUTER_API_KEY=your_openrouter_api_key_here

# JWT Secret (generate a random string)
JWT_SECRET_KEY=your_secret_key_here_use_openssl_rand_hex_32

# Optional: Change default model
LLM_MODEL=openai/gpt-3.5-turbo

3. Frontend Setup

cd frontend
npm install

4. Database Initialization

The SQLite database will be created automatically on first run. The schema includes:

  • users - User accounts
  • user_documents - Document metadata and ownership
  • chat_history - Conversation history per document

⚙️ Configuration

Backend Configuration

Edit src/utils/config.py to customize:

# Embedding Model (free, runs locally)
EMBEDDING_MODEL = "all-MiniLM-L6-v2"

# LLM Model (via OpenRouter)
LLM_MODEL = os.getenv("LLM_MODEL", "openai/gpt-3.5-turbo")

# Chunk Settings
CHUNK_SIZE = 1000
CHUNK_OVERLAP = 200

# Vector Store
CHROMA_PERSIST_DIR = "./vectorstore"

Frontend Configuration

Edit src/index.js or create .env in frontend folder:

REACT_APP_API_URL=http://localhost:8000

💻 Usage

Starting the Application

Terminal 1 - Backend:

# From project root
python -m uvicorn src.api.main:app --reload --host 0.0.0.0 --port 8000

Terminal 2 - Frontend:

# From frontend folder
cd frontend
npm start

The application will open at http://localhost:3000

Using Documind

  1. Register/Login

    • Open the application
    • Create a new account or login
    • You'll be redirected to the main interface
  2. Upload Documents

    • Drag and drop a PDF file or click to browse
    • Wait for processing (automatic chunking and embedding)
    • Document appears in the sidebar
  3. Start Chatting

    • Click on a document to select it
    • Type your question in the chat input
    • Get AI-powered answers with source citations
    • Chat history is automatically saved
  4. Manage Documents

    • Switch between documents by clicking them
    • Delete documents you no longer need
    • Each document maintains its own chat history

📚 API Documentation

Authentication Endpoints

POST /auth/register
POST /auth/login
POST /auth/token

Document Endpoints

POST /upload          # Upload PDF document
GET  /documents       # Get user's documents
DELETE /documents/{doc_id}  # Delete document

Chat Endpoints

POST /query           # Ask question about document
GET  /chat_history/{doc_id}  # Get chat history

Interactive API Docs

Visit http://localhost:8000/docs for interactive Swagger documentation.


🌐 Deployment

Deploy on Render

  1. Backend Deployment

    • Connect your GitHub repository
    • Use render.yaml configuration
    • Add environment variables (OPENROUTER_API_KEY, JWT_SECRET_KEY)
    • Deploy!
  2. Frontend Deployment

    • Deploy to Netlify or Vercel
    • Use netlify.toml configuration
    • Set REACT_APP_API_URL to your backend URL
    • Build and deploy!

Deploy on Railway

# Install Railway CLI
npm install -g @railway/cli

# Login and deploy
railway login
railway init
railway up

Environment Variables for Production

# Backend
OPENROUTER_API_KEY=your_production_key
JWT_SECRET_KEY=strong_random_secret
DATABASE_URL=your_production_db_url (optional)
CORS_ORIGINS=https://your-frontend-url.com

# Frontend
REACT_APP_API_URL=https://your-backend-url.com

📖 Project Structure

.
├── src/
│   ├── api/              # API routes and endpoints
│   │   ├── main.py       # Main FastAPI application
│   │   └── auth_routes.py # Authentication endpoints
│   ├── core/             # Core functionality
│   │   ├── embeddings.py # Embedding generation
│   │   ├── llm_client.py # LLM interaction
│   │   └── vectorstore.py # Vector database operations
│   ├── models/           # Data models
│   │   └── database.py   # SQLite models and operations
│   ├── processors/       # Document processors
│   │   └── pdf_processor.py # PDF parsing and chunking
│   ├── services/         # Business logic
│   │   └── rag_service.py # RAG implementation
│   └── utils/            # Utilities
│       ├── auth.py       # JWT and authentication
│       ├── chunking.py   # Text chunking strategies
│       └── config.py     # Configuration management
├── frontend/
│   ├── public/           # Static assets
│   └── src/
│       ├── App.js        # Main React component
│       ├── Auth.js       # Authentication components
│       ├── AuthContext.js # Auth state management
│       └── index.js      # Entry point
├── data/                 # Uploaded documents
├── vectorstore/          # ChromaDB persistence
├── requirements.txt      # Python dependencies
├── netlify.toml         # Netlify configuration
├── render.yaml          # Render configuration
└── README.md            # This file

🤝 Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Development Guidelines

  • Follow PEP 8 for Python code
  • Use ESLint/Prettier for JavaScript code
  • Write meaningful commit messages
  • Add tests for new features
  • Update documentation as needed

🐛 Troubleshooting

Common Issues

Backend won't start:

# Check if port 8000 is already in use
netstat -ano | findstr :8000
# Kill the process or use a different port

Frontend can't connect to backend:

  • Verify backend is running on http://localhost:8000
  • Check CORS settings in main.py
  • Ensure .env has correct REACT_APP_API_URL

Embedding generation is slow:

  • First run downloads the model (~80MB)
  • Subsequent runs are much faster
  • Consider using GPU acceleration if available

OpenRouter API errors:

  • Verify your API key is correct
  • Check your OpenRouter account has credits
  • Try a different model if one is unavailable

📝 License

This project is licensed under the MIT License - see the LICENSE file for details.


🙏 Acknowledgments


📧 Contact

Saad Khan - @saadkhan2003

Project Link: https://github.com/saadkhan2003/Documind---AI-Document-Assistant


⭐ Star this repo if you find it helpful!

Made with ❤️ using React, FastAPI, and LangChain

About

Documind is an intelligent AI document assistant that enables natural conversations with your PDF documents. Powered by advanced RAG (Retrieval-Augmented Generation) technology, it combines React, FastAPI, LangChain, and ChromaDB to deliver accurate answers with source citations. Click on the link for live demo.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors