Skip to content

lsvishaal/constructure-rag

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ—οΈ Constructure RAG - Full Stack

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.


πŸš€ Quick Start

# Start everything with one command
make run

Services 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

πŸ“¦ Prerequisites

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

βœ… Assignment Requirements

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

Bonus Features

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

πŸ›οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                     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  β”‚          β”‚
β”‚     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜          β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Key Technical Decisions

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

πŸ“ Project Structure

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

πŸ› οΈ Make Commands

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

πŸ”§ Environment Variables

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

πŸ” API Reference

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

πŸ§ͺ Testing

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 -v

Test Coverage: 40 tests across authentication, PDF parsing, chunking, embeddings, RAG pipeline, and evaluation.


🎯 Development Approach

This project was built using TDD methodology:

  1. Red - Write failing tests first
  2. Green - Implement minimum code to pass
  3. 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)

πŸ“š Documentation

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

πŸ“ Watermark

CONSTRUCTURE_RAG_VISHAAL_LS_2025


Built for Constructure AI Technical Assignment | December 2025

About

Production-grade RAG system for construction document intelligence - FastAPI, Next.js, Ollama

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors