Skip to content

mritunjayk-ops/DocQuery-App

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DocQuery App

DocQuery is a document query application that uses Retrieval-Augmented Generation (RAG) to provide accurate answers to questions based on your documents. It supports PDF files, text files, and images with OCR capabilities.

Features

  • Multiple Document Types: Support for PDFs, text files, and images (using OCR)
  • Advanced Text Processing: Extracts, chunks, and indexes document content
  • Vector Search: Fast similarity search using FAISS
  • Open Source LLMs: Uses Hugging Face models for embeddings and text generation
  • Optional Groq Integration: Can use Groq's API for faster inference
  • REST API: Simple API for document upload and querying

System Architecture

docquery_app/
├── app.py                 # Main FastAPI application
├── extractors/            # Document extraction modules
│   ├── pdf_extractor.py   # PDF processing
│   ├── txt_extractor.py   # Plain text processing
│   └── ocr_extractor.py   # OCR for images and scanned PDFs
├── embeddings/            # Embedding generation and storage
│   └── embedder.py        # Creates and manages embeddings
├── rag/                   # RAG implementation
│   └── rag_chain.py       # Retrieval and answer generation
├── utils/                 # Utility functions
│   └── file_utils.py      # File handling utilities
├── requirements.txt       # Python dependencies
└── README.md              # This file

Setup

  1. Clone the repository:

    git clone https://github.com/your-username/docquery-app.git
    cd docquery-app
  2. Create a virtual environment:

    python -m venv venv
    source venv/bin/activate  # On Windows: venv\Scripts\activate
  3. Install dependencies:

    pip install -r requirements.txt
  4. Set up environment variables: Create a .env file in the project root with the following:

    # API Keys
    HUGGINGFACE_TOKEN=your_huggingface_token_here
    # GROQ_API_KEY=your_groq_api_key_here  # Uncomment if using Groq
    
    # Model configuration
    MODEL_NAME=mistralai/Mistral-7B-Instruct-v0.2
    MODEL_PROVIDER=huggingface  # Options: huggingface, groq
    EMBEDDING_MODEL=sentence-transformers/all-MiniLM-L6-v2
    
    # Application settings
    DEBUG=True
    LOG_LEVEL=INFO
    MAX_DOCUMENT_SIZE_MB=10
    CHUNK_SIZE=512
    CHUNK_OVERLAP=50
    
    # OCR settings (if using)
    TESSERACT_PATH=/usr/bin/tesseract  # Update based on your system
    
  5. Run the application:

    python app.py

OCR Setup (Optional)

For OCR functionality, you need to install Tesseract:

  • Linux:

    sudo apt-get install tesseract-ocr
  • macOS:

    brew install tesseract
  • Windows: Download and install from Tesseract GitHub

API Usage

Upload a Document

curl -X POST "http://localhost:8000/upload" \
  -H "accept: application/json" \
  -H "Content-Type: multipart/form-data" \
  -F "file=@/path/to/your/document.pdf"

Query Documents

curl -X POST "http://localhost:8000/query" \
  -H "Content-Type: application/json" \
  -d '{"question":"What is the main topic of the document?"}'

Clear Documents

curl -X DELETE "http://localhost:8000/documents"

Using Different Models

The application is configured to use Mistral 7B by default, but you can change to other models:

  1. For local Hugging Face models:

    • Update the MODEL_NAME in your .env file
    • Set MODEL_PROVIDER=huggingface
  2. For Groq API:

    • Get an API key from Groq
    • Add your GROQ_API_KEY to the .env file
    • Set

About

DocQuery is an intelligent, end-to-end Retrieval-Augmented Generation (RAG) application that lets users upload PDF, TXT, or image files (JPG, PNG, JPEG), extract readable text, edit it if needed, and ask questions directly about the document content.

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages