Skip to content

A lightweight Document Q&A chatbot using RAG. Built from scratch with FastAPI, pgvector, and local (Ollama) or remote (OpenAI) LLMs.

Notifications You must be signed in to change notification settings

ajujohn2009/rag-chatbot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DocsChat - RAG Document Assistant

The document Q&A application using RAG. Upload documents, ask questions, get answers backed from the uploaded document content.

Implementation Note

Built without LangChain or similar frameworks - all RAG components implemented from scratch using direct API calls to demonstrate understanding of core concepts:

  • Custom document chunking logic
  • Direct integration with Sentence Transformers for embeddings
  • Manual vector similarity search with pgvector
  • Direct LLM API calls (OpenAI, Ollama)
  • Custom streaming response handling

Features

  • Switch between OpenAI (gpt-4o-mini) and Ollama (qwen2.5:7b) models
  • Upload/delete documents (PDF, DOCX, TXT)
  • Ask questions about uploaded documents
  • Clear chat history
  • Light/dark theme toggle
  • Source citations for AI responses

Tech Stack

Backend:

  • FastAPI
  • PostgreSQL + pgvector
  • Sentence Transformers (embeddings)
  • SQLAlchemy

Frontend:

  • Vanilla JavaScript
  • Server-Sent Events (SSE streaming responses)

AI:

  • Ollama (local LLM)
  • OpenAI API (optional)

Setup

Prerequisites:

  • Docker & Docker Compose
  • 8GB RAM (for Ollama)
  • OpenAI API key

Install:

# Clone repo
git clone https://github.com/yourusername/rag-chatbot.git
cd rag-chatbot

# Create .env file
cp .env.example .env

# Edit .env and add your OpenAI API key

.env configuration:

POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_DB=doc_rag_db
POSTGRES_HOST=db
POSTGRES_PORT=5432
OPENAI_MODEL=gpt-4o-mini
OPENAI_API_KEY=your-openai-api-key-here

Start services:

docker-compose build
docker-compose up

Access:

Note: First startup takes 10-15 minutes while Ollama downloads the model (~2.8GB)

Usage

  1. Go to Documents tab
  2. Upload your files
  3. Switch to Chat tab
  4. Ask questions
  5. View answers with source citations

Development

View logs:

docker-compose logs -f api

Access database:

docker-compose exec db psql -U postgres -d doc_rag_db

How It Works

  1. Documents split into chunks (~1200 chars, 150 char overlap)
  2. Each chunk converted to 384-dimensional vector
  3. Vectors stored in PostgreSQL with pgvector
  4. User question embedded and similar chunks retrieved
  5. LLM generates answer using retrieved chunks
  6. Response streamed back in real-time

About

A lightweight Document Q&A chatbot using RAG. Built from scratch with FastAPI, pgvector, and local (Ollama) or remote (OpenAI) LLMs.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors