Skip to content

schauh11/nec-rag-chat

Repository files navigation

NEC RAG Chatbot – AI-Powered Electrical Code Assistant

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.

Overview

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.

Screenshots

Home Screen

The landing page with suggested questions to get started.

Home Screen

Asking a Question

User asks a question and receives an answer with sources.

Question and Answer

Expanded Source

Viewing the full context of a cited NEC section.

Expanded Source

System Architecture

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
Loading
  • Frontend: Next.js 14 (App Router), TypeScript, Tailwind CSS, shadcn/ui.
  • Embeddings: OpenAI text-embedding-3-small for 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.

Features

Smart Retrieval

  • 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.

Modern User Experience

  • Streaming Responses: Real-time text generation for a responsive feel.
  • Dark Mode: Sleek, developer-friendly interface.
  • Responsive Design: Works on desktop and mobile.

Technical Highlights

  • 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.

About

RAG chatbot for the National Electrical Code using Next.js, ChromaDB, and Claude AI

Topics

Resources

License

Stars

Watchers

Forks

Contributors