A local Document QA system that allows users to upload PDF documents and ask questions about their content using a Retrieval Augmented Generation (RAG) approach. This project uses a lightweight LLM to perform inference directly on your machine.
- PDF Document Upload: Upload PDF files to be processed for question answering.
- Context-Aware QA: Ask questions specifically about the uploaded document.
- Local Inference: Uses
LiquidAI/LFM2-1.2B-RAGmodel running locally (default: CPU). - FastAPI Backend: robust and fast API for handling requests.
- Simple Web Interface: Includes a basic static frontend for testing.
- Language: Python 3.13+
- Framework: FastAPI
- ML Libraries: PyTorch, Transformers, Accelerate
- PDF Processing: pypdf
- Server: Uvicorn
- Python 3.13 or higher
- uv (recommended) or pip
-
Clone the repository:
git clone <repository-url> cd document-qa-system
-
Install dependencies using
uv:uv sync
Or using
pip:pip install .
Run the application using the main entry point:
python main.pyThe server will start at http://0.0.0.0:8000.
Open your browser and navigate to:
http://localhost:8000
-
POST
/api/upload- Upload a PDF file.
- Returns a
doc_id.
-
POST
/api/ask- Body:
{"doc_id": "string", "question": "string"} - Returns the answer generated by the model.
- Body:
Configuration constants are located in app/constants/config.py:
MODEL_NAME: Defaults toLiquidAI/LFM2-1.2B-RAGDEVICE: Defaults tocpu(can be changed tocudaif available)
document-qa-system/
├── app/
│ ├── constants/ # Configuration and constants
│ ├── static/ # Frontend static files
│ ├── inference.py # ML model and QA logic
│ └── main.py # FastAPI application definition
├── data/ # Example data
├── main.py # Application entry point
├── pyproject.toml # Project dependencies
└── README.md # Project documentation
