Production-grade RAG system for construction document intelligence
A complete document Q&A system built with FastAPI, Next.js, and Ollama. Upload construction PDFs, ask questions in natural language, and receive AI-powered answers with source citations.
# Start everything with one command
make runServices Available:
| Service | URL |
|---|---|
| Frontend | http://localhost:3000 |
| Backend API | http://localhost:8000 |
| API Documentation | http://localhost:8000/docs |
| Streamlit UI | http://localhost:8501 |
| Qdrant Dashboard | http://localhost:6333/dashboard |
Login Credentials:
Email: testingcheckuser1234@gmail.com
Password: constructure2024
| Requirement | Version | Purpose |
|---|---|---|
| Docker & Docker Compose | Latest | Container orchestration |
| Node.js | 18+ | Frontend development |
| Python | 3.12+ | Backend (optional, for local dev) |
| UV | Latest | Python package manager |
| Part | Requirement | Status | Implementation |
|---|---|---|---|
| 0 | Deployment & Testability | β | Docker Compose + Makefile automation |
| 1 | Document Ingestion | β | PyMuPDF @ 30 pages/sec, Qdrant vector storage |
| 2 | RAG Q&A Chat | β | Ollama llama3.2, citations with page references |
| 3 | Structured Extraction | β | Door schedules, wage determination tables |
| 4 | Evaluation Harness | β | 10 test queries, automatic scoring |
| Feature | Status | Description |
|---|---|---|
| Multi-mode Chat | β | qa, extraction, sources_only modes |
| Response Caching | β | LRU cache with 1-hour TTL |
| Streamlit Demo | β | Progress bars for ingestion, interactive chat |
| Next.js Frontend | β | Modern React UI with Framer Motion animations |
| JWT Authentication | β | Secure token-based auth with Argon2 hashing |
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β CLIENT LAYER β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
β β Next.js β β Streamlit β β cURL/API β β
β β Frontend β β Demo UI β β Testing β β
β ββββββββ¬βββββββ ββββββββ¬βββββββ ββββββββ¬βββββββ β
βββββββββββΌβββββββββββββββββΌβββββββββββββββββΌββββββββββββββββββββββ
β β β
ββββββββββββββββββΌβββββββββββββββββ
β HTTP/REST + JWT Auth
ββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββ
β FASTAPI BACKEND β
β ββββββββββββ ββββββββββββ ββββββββββββ ββββββββββββ β
β β /auth β β /docs β β /chat β β /eval β β
β β JWT β β upload β β RAG β β harness β β
β ββββββ¬ββββββ ββββββ¬ββββββ ββββββ¬ββββββ ββββββ¬ββββββ β
βββββββββΌβββββββββββββΌβββββββββββββΌβββββββββββββΌβββββββββββββββββββ
β β β β
βββββββββΌβββββββββββββΌβββββββββββββΌβββββββββββββΌβββββββββββββββββββ
β SERVICE LAYER β
β PDF Parser β Chunker β Embeddings β Vector Store β RAG Pipeline β
β (PyMuPDF) (300w) (BGE-small) (Qdrant) (+ Cache) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
ββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββ
β DATA LAYER β
β βββββββββββββββββββββ βββββββββββββββββββββ β
β β QDRANT β β OLLAMA β β
β β 384-dim vectors β β llama3.2:latest β β
β β Cosine similarityβ β Local inference β β
β βββββββββββββββββββββ βββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
| Component | Choice | Rationale |
|---|---|---|
| Chunking | 300 words, 75 overlap | Optimal for dense construction specs |
| Embeddings | BAAI/bge-small-en-v1.5 | 384 dims, ONNX-based, fast local inference |
| Vector DB | Qdrant | Cosine similarity, production-ready |
| LLM | Ollama llama3.2 | Local inference, no API costs |
| Caching | LRU + TTL | 10x speedup on repeated queries |
constructure-rag/
βββ Makefile # Build automation
βββ backend/
β βββ docker-compose.yml # Service orchestration
β βββ Dockerfile # Multi-stage build
β βββ streamlit_app.py # Demo UI with progress tracking
β βββ src/
β β βββ api/ # FastAPI routes
β β βββ core/ # Configuration
β β βββ models/ # Pydantic schemas
β β βββ services/ # Business logic
β βββ tests/ # 40+ tests, TDD-driven
βββ frontend/
βββ app/ # Next.js 15 App Router
β βββ chat/ # Main chat interface
β βββ login/ # Authentication page
βββ components/ # React components
β βββ chat/ # Chat UI components
β βββ extraction/ # Table displays
β βββ ui/ # shadcn/ui components
βββ lib/ # Hooks, utilities, API client
| Command | Description |
|---|---|
make run |
Start all services (backend + frontend) |
make run-backend |
Start Docker services only |
make run-frontend |
Start Next.js dev server |
make down |
Stop all services |
make build |
Build containers |
make build-clean |
Fresh rebuild (no cache) |
make test |
Run backend tests |
make logs |
Follow backend logs |
make clean-all |
Full reset |
Backend (backend/.env):
SECRET_KEY=your-secret-key-here
LLM_PROVIDER=ollama
OLLAMA_BASE_URL=http://ollama:11434
OLLAMA_MODEL=llama3.2:latest
QDRANT_URL=http://qdrant:6333
TEST_USER_EMAIL=testingcheckuser1234@gmail.com
TEST_USER_PASSWORD=constructure2024| Endpoint | Method | Description |
|---|---|---|
/api/v1/auth/login |
POST | OAuth2 login, returns JWT |
/api/v1/auth/me |
GET | Current user info |
/api/v1/documents |
GET | List indexed documents |
/api/v1/documents/upload |
POST | Upload and index PDF |
/api/v1/documents/ingest |
POST | Bulk ingest from Assets/ |
/api/v1/chat |
POST | RAG query (qa/extraction/sources_only) |
/api/v1/evaluation/run |
POST | Run evaluation harness |
Built with Test-Driven Development (Red β Green β Refactor):
# Run all tests
make test
# Run with coverage
cd backend && uv run pytest --cov=src -v
# Run specific test file
cd backend && uv run pytest tests/unit/test_auth.py -vTest Coverage: 40 tests across authentication, PDF parsing, chunking, embeddings, RAG pipeline, and evaluation.
This project was built using TDD methodology:
- Red - Write failing tests first
- Green - Implement minimum code to pass
- Refactor - Optimize while keeping tests green
Key development phases:
- Phase 1: PDF parsing & chunking (PyMuPDF, 30 pages/sec)
- Phase 2: Embeddings & vector storage (Qdrant)
- Phase 3: RAG pipeline with caching
- Phase 4: Structured extraction (door schedules, wage tables)
- Phase 5: Evaluation harness (10 queries, auto-scoring)
- Phase 6: Frontend (Next.js 15 + Framer Motion)
| Document | Location | Description |
|---|---|---|
| Backend README | backend/README.md |
Detailed backend documentation |
| Frontend README | frontend/README.md |
Frontend architecture & setup |
| Architecture | backend/docs/ARCHITECTURE.md |
System design diagrams |
| Testing Guide | backend/docs/TESTING_GUIDE.md |
Manual testing procedures |
CONSTRUCTURE_RAG_VISHAAL_LS_2025
Built for Constructure AI Technical Assignment | December 2025