A Python-based Retrieval-Augmented Generation (RAG) system for document question-answering. Built with FastAPI, HuggingFace transformers, and FAISS vector search. Includes both REST API and web interface.
- Document ingestion (PDF, TXT, DOCX, MD)
- FAISS-based vector indexing with persistent storage
- HuggingFace transformer models for embeddings and generation
- FastAPI REST API with exact specification compliance
- Streamlit web interface for interactive document management
- Context highlighting in responses
- Dynamic document uploading
- Comprehensive logging and monitoring
- Python 3.10+
- HuggingFace account token (for gated models)
git clone https://github.com/levgiorg/DocuRAG.git
cd DocuRAG
pip install -r requirements.txtcp .env.example .env
# Edit .env and add your HuggingFace token:
# HF_TOKEN=your_huggingface_token_herepython start_api.pyThe API will be available at http://localhost:8000 with documentation at http://localhost:8000/docs
python start_app.pyAccess the web interface at http://localhost:8502
curl -X POST "http://localhost:8000/ask" \
-H "Content-Type: application/json" \
-d '{"question": "What is the main topic of the document?"}'Response:
{
"answer": "The main topic is...",
"sources": ["document1.pdf", "document2.txt"]
}curl -X POST "http://localhost:8000/upload" \
-F "[email protected]"curl -X GET "http://localhost:8000/documents"The system uses YAML configuration files in the configs/ directory:
model_config.yaml: Model settings (LLM, embeddings, device)retrieval_config.yaml: Retrieval parameters (chunk size, top-k)app_config.yaml: Application settings (file limits, history)
- Document Processor: Multi-format parsing and intelligent chunking
- Vector Store: FAISS-based similarity search with metadata filtering
- RAG Engine: Query processing, retrieval orchestration, response generation
- HF Generator: HuggingFace transformers integration with context highlighting
- FastAPI: REST API endpoints with automatic validation
- Streamlit UI: Optional web interface for document management
DocuRAG/
├── src/
│ ├── document_processor.py # Document parsing and chunking
│ ├── vector_store.py # FAISS vector operations
│ ├── rag_engine.py # Main RAG orchestration
│ ├── hf_response_generator.py # HuggingFace integration
│ └── utils.py # Shared utilities
├── configs/ # Configuration files
├── api.py # FastAPI application
├── app.py # Streamlit interface
├── start_api.py # API launcher
├── start_app.py # UI launcher
├── requirements.txt # Dependencies
└── .env.example # Environment template
# Install test dependencies
pip install pytest
# Run tests
pytest tests/ -v
# System integration test
python test_system.py-
Start the API server:
python start_api.py
-
Upload a document:
curl -F "[email protected]" http://localhost:8000/upload -
Ask a question:
curl -X POST http://localhost:8000/ask \ -H "Content-Type: application/json" \ -d '{"question": "What are the key findings?"}'
Model Loading Issues:
- Ensure HF_TOKEN is set in
.env - Check internet connection for model download
- Verify sufficient disk space (~2GB for model)
Memory Issues:
- Reduce
hf_max_lengthin model config - Use CPU instead of GPU if memory limited
- Process smaller document batches
API Connection:
- Check if port 8000 is available
- Verify FastAPI server started successfully
- Check logs for detailed error messages