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.
- 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
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
-
Clone the repository:
git clone https://github.com/your-username/docquery-app.git cd docquery-app -
Create a virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Set up environment variables: Create a
.envfile 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 -
Run the application:
python app.py
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
curl -X POST "http://localhost:8000/upload" \
-H "accept: application/json" \
-H "Content-Type: multipart/form-data" \
-F "file=@/path/to/your/document.pdf"curl -X POST "http://localhost:8000/query" \
-H "Content-Type: application/json" \
-d '{"question":"What is the main topic of the document?"}'curl -X DELETE "http://localhost:8000/documents"The application is configured to use Mistral 7B by default, but you can change to other models:
-
For local Hugging Face models:
- Update the
MODEL_NAMEin your.envfile - Set
MODEL_PROVIDER=huggingface
- Update the
-
For Groq API:
- Get an API key from Groq
- Add your
GROQ_API_KEYto the.envfile - Set