This project is a document query assistant that combines a FastAPI backend with a Gradio frontend, featuring OCR capabilities. It uses LangChain and Ollama for document processing and conversational AI, with a focus on secure inter-service communication.
- Document Processing: Support for multiple file formats including PDF, DOCX, TXT, HTML with OCR capabilities
- Interactive Chat: Context-aware chatbot interface for querying document content
- Secure Architecture: Isolated service communication with Docker networks
- OCR Integration: Automated text extraction from images and scanned PDFs
- LLM Integration: Powered by Ollama with optimized RAG configuration
.
├── front/
│ ├── interface.py # Main Gradio application
│ ├── chat.py # Chat functionality
│ ├── ingest.py # Document ingestion
│ ├── Dockerfile
│ ├── requirements.txt
├── back/
│ ├── routes/
│ │ ├── chat.py # Chat endpoints
│ │ ├── ingest.py # Ingestion endpoints
│ ├── utils/
│ │ ├── app_langchain/
│ │ │ ├── data_parser.py
│ │ │ ├── process_vector.py
│ ├── config.py # Application configuration
│ ├── Dockerfile
│ ├── requirements.txt
├── docker-compose.yml
├── .env.example
The application uses isolated Docker networks for security:
front-back: Communication between frontend and backendback-ollama: Communication between backend and Ollama- External access only to frontend (7860) and backend API (8000)
- Docker and Docker Compose
- Git
- Clone the Repository
git clone https://github.com/sybtra/document-query-assistant.git
cd document-query-assistant- Configure Environment
Create a
.envfile:
API_URL=http://backend:8000
DB_NAME=/app/data/chroma
APP_MODEL=llama2
MODEL_BASE_URL=http://ollama:11434- Build and Run
docker compose up --build- Frontend Interface: http://localhost:7860
- API Documentation: http://localhost:8000/docs
- Endpoint:
POST /ingest/{collection_name} - Purpose: Upload and process documents
- Supported Formats:
- Text:
.txt,.json - Documents:
.pdf,.docx,.doc - Web:
.html,.htm - Images (via OCR):
.png,.jpg,.jpeg,.tiff,.bmp
- Text:
- Endpoint:
POST /chat/{collection_name} - Purpose: Process queries against ingested documents
- Features:
- Context-aware responses
- RAG-optimized configuration
- Conversation memory
fastapi
uvicorn
python-multipart
langchain
langchain_community
langchain_core
langchain_chroma
langchain_ollama
pytesseract
pdf2image
python-magic
python-dotenv
loguru
gradio
python-dotenv
requests
-
Frontend
- Port: 7860
- Network: front-back
- Dependencies: backend
-
Backend
- Port: 8000
- Networks: front-back, back-ollama
- Volumes: chroma_data
-
Ollama
- Internal Port: 11434
- Network: back-ollama
- Volumes: ollama_data
-
Connection Refused
- Verify network configurations in docker-compose.yml
- Check service health status
- Ensure correct environment variables
-
File Processing Errors
- Verify file format support
- Check OCR configuration
- Ensure sufficient permissions
- Regular model updates via Ollama
- Vector store maintenance
- Log monitoring
MIT License