Skip to content

Repository files navigation

πŸ€– Document Q&A System

Production-ready RAG application for intelligent document understanding using multimodal AI, vector search and LLMs.

Chat with your documents (PDF, DOCX, Images), leverage powerful RAG, and toggle between local (Ollama) and cloud (Gemini) AI models.

Python 3.10+ License: MIT Streamlit


✨ Key Features

πŸ“š Multi-Format Document Support

  • Text Documents: PDF, DOCX, TXT, Markdown, CSV
  • Images: PNG, JPG, JPEG, BMP, TIFF, WEBP (with OCR + Vision AI)
  • Web Content: Scrape and index URLs
  • Multiple Sources: Combine different document types in one knowledge base

🧠 Flexible AI Providers

  • Local (Ollama): 100% private, free, runs on your machine
  • Cloud (Gemini): 5-10x faster, free tier available (60 req/min)
  • Easy Toggle: Switch between providers with one setting
  • Hybrid Mode: Use different providers for different tasks

🎯 Powerful Features

  • Multi-Project Management: Create isolated knowledge bases
  • Persistent Conversations: Full chat history with search
  • Source Attribution: See which documents answered each question
  • Image Understanding: OCR text extraction + AI vision analysis
  • Export Capabilities: JSON, CSV, PDF export formats
  • Improved Retrieval: Hybrid search (semantic + keyword matching)

πŸš€ Modern Interface

  • Streamlit Web UI: Beautiful, intuitive interface
  • Project Dashboard: Manage multiple knowledge bases
  • Real-time Progress: See document processing status
  • History & Search: Find past conversations instantly

πŸš€ Quick Start

Prerequisites

  • Python: 3.10 or higher
  • Ollama: For local AI models (optional if using Gemini)
  • RAM: 8GB minimum, 16GB recommended
  • Storage: 10GB free space

Installation (5 Minutes)

1. Install Ollama (Optional - for local models)

# Linux/WSL
curl -fsSL https://ollama.com/install.sh | sh

# macOS
brew install ollama

# Start Ollama
ollama serve

# Pull models (in another terminal)
ollama pull qwen2.5:14b           # Q&A model
ollama pull nomic-embed-text      # Embeddings
ollama pull llava:7b              # Vision (optional)

2. Clone and Setup

# Clone repository
git clone https://github.com/YOUR_USERNAME/document_q_n_a.git
cd document_q_n_a

# Create virtual environment
python3 -m venv env
source env/bin/activate  # Windows: env\Scripts\activate

# Install dependencies
pip install -r requirements.txt

# Configure environment
cp .env.example .env
nano .env  # Add your API keys (optional)

3. Run the Application

# Activate environment
source env/bin/activate

# Start the app
streamlit run app.py

# Open browser to: http://localhost:8501

That's it! πŸŽ‰


βš™οΈ Configuration

Quick Setup (Local Only)

For local-only setup, no API keys needed. Just ensure Ollama is running:

LLM_PROVIDER=local
VISION_PROVIDER=local

Cloud Setup (Faster Responses)

Get 5-10x faster responses with Google Gemini (free tier):

  1. Get API key: https://makersuite.google.com/app/apikey
  2. Update .env:
LLM_PROVIDER=gemini
VISION_PROVIDER=gemini
GOOGLE_API_KEY=your_api_key_here

Hybrid Setup (Best of Both)

LLM_PROVIDER=gemini    # Fast Q&A
VISION_PROVIDER=local  # Private image processing

Full Configuration Options

See .env.example for all available settings including:

  • Model selection
  • Chunk sizes
  • Rate limits
  • Storage paths
  • LangSmith tracking (optional)

πŸ“– Usage Guide

Creating Your First Knowledge Base

  1. Create Project

    • Go to "Knowledge Base" tab
    • Click "Create New Project"
    • Name it and add description
  2. Add Documents

    • Upload files (PDF, DOCX, images, etc.)
    • Or add URLs to scrape
    • Wait for processing (see progress bar)
  3. Start Chatting

    • Go to "Chat" tab
    • Ask questions about your documents
    • See source attribution for each answer
  4. Review History

    • Go to "History" tab
    • Search past conversations
    • Export to JSON/CSV/PDF

Image Processing

The system can extract text from images AND understand visual content:

Upload image.png β†’ 
  β”œβ”€ OCR (Tesseract) β†’ Extract text
  β”œβ”€ Vision AI β†’ Describe image content
  └─ Combined β†’ Full understanding

Supported formats: PNG, JPG, JPEG, BMP, TIFF, WEBP, GIF

Provider Comparison

Feature Local (Ollama) Cloud (Gemini)
Speed 20-45 sec/query 2-5 sec/query
Cost Free forever Free tier (60/min)
Privacy 100% private Data sent to Google
Internet Not required Required
Quality Excellent Excellent
Images LLaVA (slow) Gemini Vision (fast)

πŸ—οΈ Architecture

Tech Stack

  • LLM Framework: LangChain
  • Local Models: Ollama (Qwen 2.5, LLaVA)
  • Cloud Models: Google Gemini 2.5 Flash
  • Vector DB: ChromaDB
  • Database: SQLite (SQLAlchemy ORM)
  • UI: Streamlit
  • OCR: Tesseract, EasyOCR
  • Document Processing: PyPDF, python-docx, BeautifulSoup

How RAG Works

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ User Questionβ”‚
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
       β”‚
       v
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Hybrid Search        β”‚  1. Semantic search (vector similarity)
β”‚ (Semantic + Keyword) β”‚  2. Keyword matching (BM25)
β”‚                      β”‚  3. Merge & re-rank results
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
       β”‚
       v
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Retrieved Chunks β”‚  Top 10 most relevant passages
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
       β”‚
       v
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ LLM Generation   β”‚  Qwen 2.5 or Gemini
β”‚ (with context)   β”‚  β†’ Grounded answer
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
       β”‚
       v
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Answer + Sources β”‚  With document attribution
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Project Structure

document_q_n_a/
β”œβ”€β”€ app.py                      # Streamlit UI
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ config.py               # Configuration management
β”‚   β”œβ”€β”€ database.py             # SQLAlchemy models
β”‚   β”œβ”€β”€ cloud_providers.py      # Gemini API wrapper
β”‚   β”œβ”€β”€ document_processor.py   # Document parsing
β”‚   β”œβ”€β”€ image_processor.py      # OCR + Vision AI
β”‚   β”œβ”€β”€ vector_store.py         # ChromaDB operations
β”‚   β”œβ”€β”€ qa_chain.py             # RAG implementation
β”‚   β”œβ”€β”€ improved_retrieval.py   # Hybrid search
β”‚   β”œβ”€β”€ web_scraper.py          # URL fetching
β”‚   β”œβ”€β”€ export_manager.py       # Export functionality
β”‚   └── session_manager.py      # Project management
β”œβ”€β”€ data/                       # Application data
β”‚   β”œβ”€β”€ app.db                  # SQLite database
β”‚   └── projects/               # Project vector stores
β”œβ”€β”€ docs_backup/                # Documentation backups
β”œβ”€β”€ requirements.txt            # Python dependencies
β”œβ”€β”€ .env.example                # Configuration template
└── README.md                   # This file

🎯 Performance

Response Times

Task Local (Ollama) Cloud (Gemini)
Q&A 20-45 seconds 2-5 seconds
Image Vision 3-12 seconds 1-3 seconds
OCR 0.5-2 seconds 0.5-2 seconds
Document Upload 1-5 seconds 1-5 seconds

Resource Usage

  • CPU: Qwen 2.5:14b uses all available cores
  • RAM: ~6-8GB for model + application
  • Disk: ~5GB for models + your documents
  • GPU: Optional (3-5x speedup if available)

πŸ”§ Troubleshooting

Ollama Connection Issues

# Check if Ollama is running
curl http://localhost:11434/api/tags

# Start Ollama
ollama serve

# Verify models are pulled
ollama list

Slow Performance

  • Use Gemini for 5-10x faster responses (set LLM_PROVIDER=gemini)
  • Use GPU if available (Ollama auto-detects)
  • Reduce model size: Try qwen2.5:7b instead of 14b

Image Processing Not Working

# Install Tesseract OCR
# Ubuntu/Debian:
sudo apt-get install tesseract-ocr

# macOS:
brew install tesseract

# Windows: Download from https://github.com/UB-Mannheim/tesseract/wiki

"No module named 'src'"

# Make sure you're in the project directory
cd document_q_n_a

# Activate virtual environment
source env/bin/activate

πŸ›£οΈ Roadmap

βœ… Completed (Current Version)

  • Multi-format document support
  • Image processing (OCR + Vision)
  • Cloud provider integration (Gemini)
  • Hybrid search (semantic + keyword)
  • Project management
  • Conversation history
  • Export functionality

🚧 Planned Features

  • Phase 1 (Next 2-4 weeks):

    • Text-to-Image generation (Stable Diffusion)
    • Speech-to-Text (Whisper)
    • Text-to-Speech (Coqui TTS)
  • Phase 2 (1-2 months):

    • Video analysis
    • Audio processing
    • Code assistant
    • Advanced analytics dashboard
  • Phase 3 (Future):

    • Multi-user support
    • User authentication
    • API endpoints
    • Mobile app

See AI_SERVICE_EXPANSION_PLAN.md for details.


πŸ“„ License

MIT License - see LICENSE file for details.

Feel free to use for personal or commercial projects!


πŸ™ Acknowledgments

Built with these amazing open-source projects:


πŸ“ž Support

  • Documentation: See docs_backup/ for detailed guides
  • Issues: Open an issue on GitHub
  • Questions: Check documentation or open a discussion

⭐ Star History

If you find this project useful, please consider giving it a star!


Ready to start? Follow the Quick Start guide above! πŸš€

About

Production-ready RAG application for intelligent document understanding using multimodal AI, vector search and LLMs.

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Sponsor this project

Packages

Contributors

Languages