arunSeervi/offline-ai-docs
CPU-First Offline AI Document Intelligence Platform
An offline-first document processing pipeline that transforms unstructured documents (PDFs, DOCXs, and images) into structured, validated relational database profiles. All operations run entirely on local CPU resources with zero network dependencies.
[!IMPORTANT] Offline Compliance: This application does not connect to external APIs (no OpenAI, no Anthropic, no Gemini). All OCR, embeddings, vector indexing, and LLM inference run locally on the host's CPU.
๐ Key Features
- 100% Offline execution: Zero HTTP calls to third-party services.
- CPU-Optimized Inference: Utilizes quantized GGUF models via
llama.cppandonnxruntimeCPU threads. - Decoupled AI Pipeline: Swap components (OCR, embedder, vector store, LLM) without altering business logic.
- Strict JSON Outputs: Validated against configurable Pydantic schemas with a single-retry recovery mechanism.
- Relational Storage: SQLite database for documents, chunk relationships, extracted entities, and metadata.
- Interactive Side-by-Side Canvas: React/Vite dashboard illustrating text block maps alongside extracted database fields.
๐ ๏ธ Tech Stack & Constraints
๐ Project Architecture
The repository enforces a clean, modular structure:
offline_first/
โโโ .specify/ # GitHub Spec Kit templates and constitution
โ โโโ memory/
โ โโโ constitution.md # Engineering principles and coding standards
โ โโโ specification.md # Product features specification
โ โโโ plan.md # Technical implementation blueprints
โโโ backend/ # FastAPI python app
โ โโโ api/
โ โ โโโ v1/
โ โ โโโ endpoints/ # REST API route handlers
โ โโโ core/ # Single-responsibility AI and DB modules
โ โ โโโ config/ # System settings and environment variables
โ โ โโโ ocr/ # Native layout parsing and Tesseract engine
โ โ โโโ chunking/ # Recursive text splitting logic
โ โ โโโ embedding/ # ONNX model loader and vector computation
โ โ โโโ rag/ # FAISS vector database and retriever
โ โ โโโ llm/ # llama.cpp client and prompt grammar
โ โ โโโ schemas/ # Pydantic structures for validation
โ โ โโโ storage/ # Local file persistence
โ โ โโโ services/ # Decoupled processing pipelines
โ โ โโโ database/ # Relational models and session managers
โ โโโ tests/ # Pytest unit suites
โ โโโ main.py # Backend Entrypoint
โโโ frontend/ # React + Vite client app
โ โโโ src/
โ โ โโโ components/ # Reusable canvas widgets (DocumentViewer)
โ โ โโโ pages/ # Views (Upload, Status, Search)
โ โ โโโ App.tsx # Root page containing layout rules
โ โ โโโ index.css # Styling entrypoint with Tailwind directives
โ โโโ postcss.config.js # PostCSS config with @tailwindcss/postcss
โ โโโ tailwind.config.js # Tailwind scan paths configuration
โโโ docs/ # Architectural specs and API documentation
โโโ scripts/ # Command utilities
โ โโโ setup.sh # Install and synchronize packages
โ โโโ run.sh # Run dev servers
โโโ models/ # Weight store for GGUF and ONNX models๐ง Prerequisites & Setup
1. System Requirements
- Python:
3.13.* - Node.js:
>= 20.0.0 - uv: Python packaging CLI
- Tesseract: Local OCR binaries (required only for image files/scanned PDFs)
- Debian/Ubuntu:
sudo apt-get install tesseract-ocr - macOS:
brew install tesseract
2. Initialization
Run the project bootstrap script:
./scripts/setup.shThis script will build the Python virtual environment using uv sync and install frontend npm packages.
3. Placing Model Weights
Download and copy required local model weights to the models/ directory before starting the application:
- Qwen2.5-1.5B-Instruct-GGUF (Q4KM): Download the weights from HuggingFace and place them as
models/qwen2.5-1.5b-instruct-q4_k_m.gguf. - all-MiniLM-L6-v2 ONNX: Execute the download script to automatically fetch and configure ONNX weights:
uv run scripts/download_models.py๐ Running the Application
Option A: Running Both Servers Simultaneously (Recommended)
Start both frontend and backend development environments together:
./scripts/run.shOption B: Running the Servers Separately
If you prefer to run or debug the components individually, open two terminal sessions:
Terminal 1: Backend Server
Start the FastAPI application on port 8000:
uv run uvicorn backend.main:app --host 127.0.0.1 --port 8000 --reloadTerminal 2: Frontend Server
Start the Vite dev server on port 5173:
cd frontend
npm run dev- FastAPI Backend starts on: http://127.0.0.1:8000
- Vite Frontend starts on: http://localhost:5173
๐งช Static Quality Gates & Testing
We enforce strict validation checks. Run these before pushing changes:
# Apply code styling
uv run black backend
uv run isort backend
# Run linters and checks
uv run ruff check backend
uv run mypy backend
# Run security checks
uv run bandit -r backend --exclude backend/tests
# Run unit test suites
uv run pytest
# Execute all pre-commit hooks manually
uv run pre-commit run --all-files๐ License
This project is licensed under the GNU Affero General Public License v3.0 - see the LICENSE file for details.
