Back to projects
System Design & Architecture
Deep Dive Engineering Case Study

Hiraya - AI-Powered Campus Assistant

Smart campus companion with RAG architecture

Accuracy:80%
Speed Increase:90%
Active Users:100+
React.jsNext.jsTypeScriptSQLPrisma ORMTailwindCSSRAG ArchitectureNLP

System Design & Network Topology

Hiraya - AI-Powered Campus Assistant Architecture Diagram
Click to enlarge diagram
Eraser Architecture Spec
2-Minute Architecture Summary

“Hiraya is an AI Campus Assistant for NIT Hamirpur that eliminates hallucinations using Retrieval-Augmented Generation. By compiling Hugging Face transformers locally in Node.js with PostgreSQL pgvector, I achieved a zero-cost embedding architecture and overcame Vercel serverless bundle limits through custom Webpack binary pruning.”

Problem Statement & Business Need

University students frequently struggle to find accurate, up-to-date information regarding campus rules, placements, and exam notices scattered across PDFs. Hiraya is an AI Campus Assistant for NIT Hamirpur using strict Retrieval-Augmented Generation (RAG) to provide verified, hallucination-free streamed answers from a maintainer knowledge base.

High-Level Architecture & Flow

Full-stack Next.js (React 19) architecture. Frontend consumes server-sent token streams from LangChain and Groq LLM (Llama 3.1). The backend generates 384-dimensional text embeddings in-process using local Hugging Face ONNX models, stores vectors in PostgreSQL via pgvector and Prisma ORM, and executes fast cosine similarity retrieval.

Core Engineering Responsibilities & Contributions

Zero-Cost RAG Pipeline

Engineered a local in-process embedding pipeline using @huggingface/transformers (all-MiniLM-L6-v2), eliminating external embedding API costs completely.

Vector Database Integration

Integrated pgvector with PostgreSQL and Prisma to execute real-time cosine distance similarity queries on chunked campus data.

Streaming UI/UX

Built a responsive chat interface that decodes and renders text streams token-by-token directly from Groq and LangChain.

Secure Ingestion System

Developed a protected API route allowing maintainers to chunk and inject raw notices and PDF text directly into the knowledge base.

Key Architectural Decisions & Trade-Offs (Why X over Y)

Why Local Embeddings (transformers.js)?

External APIs like OpenAI introduce recurring costs and network round trips. Running all-MiniLM-L6-v2 locally in WebAssembly/ONNX reduced embedding costs to $0 and cut retrieval latency.

Why pgvector over Pinecone/Milvus?

For a campus system, a specialized vector DB adds unnecessary operational complexity. PostgreSQL with pgvector allowed relational and vector data to live together in a single Prisma schema.

Why Groq + Llama 3.1?

Groq LPU hardware generates tokens at extraordinary speeds. Combined with Next.js Edge streaming, it provides instantaneous response times.

Production Challenges & How They Were Solved

BOTTLENECK

Serverless 250MB Bundle Limit on Vercel

Resolution:

The onnxruntime-node library ships with ~513MB of multi-OS binaries. Added Webpack outputFileTracingExcludes in next.config.ts to aggressively strip CUDA, macOS, and Windows binaries down to ~130MB.

BOTTLENECK

Serverless Cold Starts on Read-Only Filesystems

Resolution:

Vercel serverless filesystems are read-only. Configured the 90MB Hugging Face model cache to download into /tmp/ and maintained an in-process singleton for warm execution.

Scalability & 100k Concurrent Users Roadmap

  • 01.Migrate from serverless to persistent Docker containers (AWS ECS/Railway) to keep the 90MB embedding model permanently warm in memory.
  • 02.Integrate Upstash Redis caching for frequently asked student questions (e.g., library timings, fee deadlines).
  • 03.Incorporate multi-modal document parsing for scanned campus circulars.

Key System Highlights

  • 80% response accuracy with NLP
  • 90% faster information retrieval
  • RAG architecture implementation
  • 100% context-aware responses