Author: Sanjay Chauhan | GitHub
A Next.js web application that uses RAG (Retrieval-Augmented Generation) to answer questions based on the National Electrical Code (NEC).
Note
Project Note: This is a Proof of Concept (POC) / MVP. The vectorized database itself is not included in this repo because the NEC is proprietary. This repo demonstrates the architecture, UI, and RAG implementation.
This application demonstrates how to build a domain-specific chatbot using modern AI tools. It ingests complex technical documentation (NEC) and allows users to query it using natural language, providing accurate answers with citations.
Key Capabilities:
- "What is the minimum working space for 600V equipment?" -> Returns exact section and table.
- "explain grounding requirements for pools" -> Summarizes relevant articles.
- "calculating conductor ampacity" -> Retrieves adjustment factors.
The landing page with suggested questions to get started.
User asks a question and receives an answer with sources.
Viewing the full context of a cited NEC section.
A modern RAG stack connecting a frontend UI to a vector search engine and LLM:
graph TD
User([User]) -->|Natural Language Query| UI[Next.js UI]
UI -->|API Request| API[API Route]
subgraph RagFlow [RAG Pipeline]
direction TB
API -->|Query| Embed[OpenAI Embeddings]
Embed -->|Vector| Chroma[(ChromaDB)]
Chroma -->|Relevant Sections| LLM[Claude 3.5 Sonnet]
API -.->|Prompt| LLM
end
LLM -->|Answer + Citations| API
API -->|Streamed Response| UI
style User fill:#fff,stroke:#333,stroke-width:2px,color:#000
style UI fill:#ffff,stroke:#333,stroke-width:2px,color:#000
style Chroma fill:#2563eb,stroke:#fff,stroke-width:2px,color:#fff
style LLM fill:#d97706,stroke:#fff,stroke-width:2px,color:#fff
- Frontend: Next.js 14 (App Router), TypeScript, Tailwind CSS, shadcn/ui.
- Embeddings: OpenAI
text-embedding-3-smallfor vectorizing queries. - Vector DB: ChromaDB (running in Docker) for high-performance similarity search.
- LLM: Anthropic Claude 3.5 Sonnet for answer synthesis and code interpretation.
- Semantic Search: Understands intent, not just keywords.
- Context Window: Retrieves top-k relevant code chunks to feed the LLM.
- Source Citation: Always cites the specific NEC Article/Section used for the answer.
- Confidence Scores: Displays the top 3 sources with confidence percentages based on vector similarity.
- Streaming Responses: Real-time text generation for a responsive feel.
- Dark Mode: Sleek, developer-friendly interface.
- Responsive Design: Works on desktop and mobile.
- Custom Ingestion Pipeline: Scripts to parse and vectorize PDF content (not included in repo).
- Docker Integration: Database runs containerized for easy local development.
- Server Actions: Leveraging Next.js server side capabilities for secure API handling.


