Skip to content

sundaram2021/rag-system

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PDF RAG Research Tool

A simple yet powerful Retrieval-Augmented Generation (RAG) system built with Node.js, Groq API, and local embeddings. Upload PDF documents and ask questions about their content with real-time streaming responses.

Features

  • PDF Upload & Processing: Upload multiple PDF documents (up to 50MB each)
  • AI-Powered Q&A: Ask questions and get intelligent answers based on your documents
  • Smart Search: Uses vector embeddings to find relevant information
  • Source Citations: See which parts of your documents were used in answers
  • Real-time Streaming: Watch responses generate in real-time
  • Cost-Effective: Free local embeddings + Groq's fast, affordable LLM
  • Clean UI: Modern, intuitive web interface

Tech Stack

  • Backend: Node.js + Express + Socket.IO
  • Frontend: HTML5 + CSS3 + Vanilla JavaScript
  • PDF Parsing: pdf-parse
  • Embeddings: @xenova/transformers (local, free)
  • Vector Storage: In-memory with cosine similarity
  • LLM: Groq API (openai/gpt-oss-20b)

Prerequisites

Quick Start

  1. Clone or download this project

  2. Install dependencies:

    npm install
  3. Set up environment variables:

    • Edit .env file
    • Add your Groq API key:
      GROQ_API_KEY=your_actual_groq_api_key_here
      PORT=3000
      
  4. Start the server:

    npm start
  5. Open your browser:

    • Navigate to http://localhost:3000

Usage

Upload a PDF

  1. Click the upload area or drag & drop a PDF file
  2. Click "Upload & Process"
  3. Wait for processing (first-time embedding model download may take a moment)
  4. Your PDF is now ready for queries!

Ask Questions

  1. Type your question in the chat input
  2. Press Enter or click Send
  3. Watch the response stream in real-time
  4. See source citations at the bottom of each answer

Manage Data

  • View document statistics in the sidebar
  • Clear all data with "Clear All Data" button
  • Upload multiple PDFs to expand your knowledge base

Configuration

Chunking Settings

Edit src/ragService.js to adjust:

  • chunkSize: 1000 (characters per chunk)
  • chunkOverlap: 200 (overlap between chunks)
  • topK: 3 (number of chunks to retrieve)

Model Settings

Edit server.js to change:

  • Groq model: openai/gpt-oss-20b
  • Temperature: 0.7 (higher = more creative)
  • Max tokens: 2048

Project Structure

groq-rag-system/
├── package.json          # Dependencies
├── .env                  # Environment variables
├── server.js            # Express server + Socket.IO
├── src/
│   ├── pdfService.js     # PDF text extraction
│   ├── embeddingService.js # Local embeddings
│   ├── vectorStore.js    # In-memory vector DB
│   └── ragService.js     # RAG orchestration
└── public/
    ├── index.html        # Frontend UI
    ├── style.css         # Styling
    └── script.js         # Client-side logic

How It Works

  1. Upload PDF: Extract text from uploaded PDF
  2. Chunk Text: Split text into smaller, manageable chunks
  3. Generate Embeddings: Convert chunks to vector embeddings (local, free)
  4. Store Vectors: Save embeddings in memory with metadata
  5. Query Process:
    • Convert question to embedding
    • Find similar chunks using cosine similarity
    • Retrieve top-k relevant chunks
    • Send chunks + question to Groq LLM
    • Stream response back to user

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published