A sophisticated AI-powered document analysis system that enables users to upload PDF documents and ask intelligent questions about their content. Built with modern AI technologies including Groq's ultra-fast inference, semantic search, and advanced document processing.
- Multi-format Support: PDF, DOCX, and email files (.eml)
- Large File Handling: Support for documents up to 200MB
- Fast Extraction: PyMuPDF with pdfplumber fallback for optimal performance
- Smart Chunking: Intelligent text segmentation preserving context
- Groq Integration: Ultra-fast inference with Llama 3.1 8B Instant model
- Semantic Search: FAISS-powered vector similarity search
- Context-Aware Responses: Maintains document context across conversations
- Multiple AI Models: Support for various embedding models
- Intelligent Caching: Document and model caching with TTL
- Async Processing: Concurrent request handling
- Rate Limiting: Built-in protection against abuse
- Memory Optimization: Efficient resource management
- Bearer Token Authentication: Secure API access
- Input Validation: Comprehensive security checks
- Non-root Execution: Docker security best practices
- Environment Isolation: Secure configuration management
- Web Interface: Modern, responsive chat-based UI
- REST API: Full programmatic access with OpenAPI documentation
- Docker Support: Containerized deployment ready
Complete documentation is available in the docs/ directory:
- Project Structure - Detailed module and directory organization
- Developer Guide - For developers setting up the project
- Deployment Guide - Production deployment instructions
- User Guide - End-user documentation
- API Documentation - Complete API reference
- Docker Deployment - Docker setup and management
- Docker Hub Guide - Docker Hub integration
- Architecture Improvements - Refactoring roadmap
- Phase 1 Complete - Architecture foundation summary
- Codebase Organization - Current cleanup status
- Quick Reference - Developer quick reference
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β Web Interface β β REST API β β Docker β
β (Flask) β β (FastAPI) β β Container β
βββββββββββ¬ββββββββ ββββββββββ¬ββββββββββ βββββββββββ¬ββββββββ
β β β
βββββββββββββββββββββββΌβββββββββββββββββββββββββ
β
βββββββββββββΌββββββββββββ
β Core Engine β
β - Document Parser β
β - Embedding Engine β
β - Vector Search β
β - AI Integration β
βββββββββββββ¬ββββββββββββ
β
βββββββββββββββββββββββΌββββββββββββββββββββββ
β β β
βββββββΌββββββ βββββββββββΌβββββββββ ββββββββΌβββββββ
β PyMuPDF β β SentenceTransf. β β Groq API β
β PDFPlumberβ β FAISS β β Llama 3.1 β
βββββββββββββ ββββββββββββββββββββ βββββββββββββββ
- Python 3.11 or higher
- Git
- Groq API key (Get one here)
git clone https://github.com/your-username/intelligent-query.git
cd intelligent-query# Create virtual environment
python -m venv venv
# Activate virtual environment
# Windows:
.\venv\Scripts\activate
# macOS/Linux:
source venv/bin/activatepip install --upgrade pip
pip install -r requirements.txt# Copy environment template
cp .env.example .env
# Edit .env file and add your Groq API key
# GROQ_API_KEY=your_groq_api_key_herepython run_flask.pyOpen your browser and go to: http://localhost:5000
python -c "import uvicorn; uvicorn.run('src.app:app', host='0.0.0.0', port=3000)"API Documentation: http://localhost:3000/docs
python test_setup.py- Upload Document: Drag and drop a PDF file or click to browse
- Wait for Processing: The system will extract and index the document
- Ask Questions: Type your questions in the chat interface
- Get Answers: Receive AI-powered responses based on document content
All API requests require a Bearer token:
curl -H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
http://localhost:3000/healthcurl -X POST "http://localhost:3000/hackrx/run" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"documents": "https://example.com/document.pdf",
"questions": [
"What is the main topic of this document?",
"What are the key findings?"
]
}'{
"answers": [
"The main topic of this document is artificial intelligence and machine learning applications in healthcare.",
"The key findings include improved diagnostic accuracy and reduced processing time."
]
}# Build and run with Docker Compose
docker-compose up --build -d
# Check status
docker-compose ps
# View logs
docker-compose logs -f# Build image
docker build -t intelligent-query .
# Run container
docker run -d \
--name intelligent-query-app \
-p 5000:5000 \
--env-file .env \
-v $(pwd)/uploads:/app/uploads \
intelligent-query| Variable | Description | Default | Required |
|---|---|---|---|
GROQ_API_KEY |
Groq API key for AI inference | - | β |
SECRET_KEY |
Flask secret key | Generated | β |
PORT |
Application port | 3000 | β |
MAX_FILE_SIZE |
Maximum upload size (bytes) | 16777216 | β |
DEBUG |
Enable debug mode | False | β |
HACKRX_BEARER_TOKEN |
API authentication token | - | β |
# In src/app.py, modify get_sentence_transformer()
model = SentenceTransformer('all-MiniLM-L6-v2') # Fast
model = SentenceTransformer('all-mpnet-base-v2') # Balanced
model = SentenceTransformer('BAAI/bge-large-en-v1.5') # Accurate# Document cache configuration
MAX_CACHE_SIZE = 10 # Number of documents to cache
CACHE_TTL = 3600 # Cache time-to-live in seconds- Document Processing: ~30-60 seconds for 100-page PDF
- Question Answering: ~2-5 seconds per question
- Concurrent Users: Supports 10+ simultaneous users
- Memory: ~2-4GB RAM for optimal performance
- Storage: ~1GB for models and cache
- CPU: Multi-core recommended for concurrent processing
- Use SSD storage for faster model loading
- Increase RAM for larger document caches
- Enable GPU for faster embedding generation (optional)
- Use CDN for static assets in production
# Environment setup test
python test_setup.py
# API client test
python test_openai_client.py
# Import tests
python test_web_app_imports.py
# Performance benchmark
python test/benchmark.py# Test health endpoint
curl http://localhost:3000/health
# Test with sample document
python scripts/test_openrouter.pyProblem: ModuleNotFoundError or import issues
Solution:
# Ensure virtual environment is activated
.\venv\Scripts\activate # Windows
source venv/bin/activate # macOS/Linux
# Reinstall dependencies
pip install -r requirements.txtProblem: "API key not configured" error Solution:
# Check .env file exists and contains valid key
cat .env | grep GROQ_API_KEY
# Test API key
python test_openai_client.pyProblem: Out of memory errors Solution:
- Reduce
MAX_CACHE_SIZEin configuration - Use smaller embedding models
- Process smaller documents
- Increase system RAM
Problem: "Port already in use" error Solution:
# Find process using port
netstat -ano | findstr :5000 # Windows
lsof -i :5000 # macOS/Linux
# Kill process or change port in .envEnable debug logging:
# Set environment variable
export DEBUG=True # Linux/macOS
set DEBUG=True # Windows
# Or modify .env file
DEBUG=Trueintelligent-query/
βββ src/ # Source code
β βββ app.py # FastAPI application
β βββ web_app.py # Flask web interface
β βββ new_app.py # Optimized FastAPI version
βββ scripts/ # Utility scripts
β βββ setup-docker.bat # Docker setup (Windows)
β βββ test_*.py # Test scripts
βββ docs/ # Documentation
βββ test/ # Test files
βββ uploads/ # File upload directory
βββ requirements.txt # Python dependencies
βββ Dockerfile # Docker configuration
βββ docker-compose.yml # Multi-container setup
βββ .env.example # Environment template
# In src/app.py, add new extraction function
def extract_text_from_new_format(file_path):
# Implementation here
pass
# Update download_and_extract_text function
elif ext in ['.new_ext']:
return extract_text_from_new_format(tmp_path)# Add new model in get_sentence_transformer()
def get_custom_model():
return SentenceTransformer('your-custom-model')# In src/app.py
@app.post("/new-endpoint")
async def new_endpoint():
# Implementation here
pass- Follow PEP 8 for Python code
- Use type hints where possible
- Add docstrings for functions
- Keep functions focused and small
- Use meaningful variable names
# Production environment variables
FLASK_ENV=production
DEBUG=False
SECRET_KEY=your_strong_secret_key
GROQ_API_KEY=your_api_key# docker-compose.prod.yml
services:
app:
build: .
restart: always
ports:
- "80:5000"
environment:
- FLASK_ENV=production
volumes:
- ./uploads:/app/uploadsRailway.app:
# Install Railway CLI
npm install -g @railway/cli
# Deploy
railway login
railway init
railway upHeroku:
# Create Heroku app
heroku create your-app-name
# Set environment variables
heroku config:set GROQ_API_KEY=your_key
# Deploy
git push heroku mainAWS/GCP/Azure:
- Use Docker container deployment
- Configure load balancer for scaling
- Set up persistent storage for uploads
- Configure environment variables securely
- Load Balancing: Use nginx or cloud load balancers
- Database: Consider PostgreSQL for persistent storage
- Caching: Redis for distributed caching
- Monitoring: Implement health checks and logging
- Security: HTTPS, rate limiting, input validation
# Check application health
curl http://localhost:3000/health
# Monitor Docker containers
docker-compose ps
docker-compose logs -f- Response time per request
- Document processing time
- Cache hit/miss ratios
- Memory and CPU usage
- API error rates
Logs are written to:
- Console output
app.log(FastAPI)web_app.log(Flask)
We welcome contributions! Please see CONTRIBUTING.md for guidelines.
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
Please include:
- Environment details (OS, Python version)
- Steps to reproduce
- Expected vs actual behavior
- Error messages and logs
This project is licensed under the MIT License - see the LICENSE file for details.
- Groq for ultra-fast AI inference
- Hugging Face for transformer models
- FAISS for efficient similarity search
- PyMuPDF for fast PDF processing
- FastAPI and Flask for web frameworks
- π User Guide - Complete user manual with best practices
- π API Documentation - Comprehensive API reference
- π Deployment Guide - Deploy to any platform
- π οΈ Developer Guide - Architecture and development
- π€ Contributing Guidelines - How to contribute
- π Changelog - Version history and updates
- π― Getting Started - Set up in 5 minutes
- π‘ Usage Examples - Common use cases
- π³ Docker Deployment - Containerized setup
- π§ Configuration - Environment setup
- π§ͺ Testing - Quality assurance
- π Documentation: Complete Documentation Suite
- π Issues: GitHub Issues
- π¬ Discussions: GitHub Discussions
- π§ Email: support@your-domain.com
- Multi-document comparison
- Document summarization
- Custom model fine-tuning
- Real-time collaboration
- Advanced analytics dashboard
- Multi-modal analysis (text + images)
- Voice interaction
- Mobile app
- Enterprise SSO integration
Made with β€οΈ by the Intelligent Query Team
Transform your documents into intelligent conversations!