Skip to content

dlwhyte/rag-chatbot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RAG Chatbot

A simple Retrieval-Augmented Generation (RAG) chatbot that lets you upload PDF documents and ask questions about their contents. Built with Flask, OpenAI, and an in-memory vector store.

How it works

  1. Upload a PDF — the app extracts text, splits it into overlapping chunks, and generates embeddings via OpenAI.
  2. Ask a question — the app embeds your query, finds the most relevant chunks by cosine similarity, and sends them as context to GPT-4o-mini.
  3. Get a grounded answer — the LLM responds using only the retrieved context.

A Poem

The Road Not Taken — Robert Frost

Two roads diverged in a yellow wood, And sorry I could not travel both And be one traveler, long I stood And looked down one as far as I could To where it bent in the undergrowth;

Then took the other, as just as fair, And having perhaps the better claim, Because it was grassy and wanted wear; Though as for that the passing there Had worn them really about the same,

And both that morning equally lay In leaves no step had trodden black. Oh, I kept the first for another day! Yet knowing how way leads on to way, I doubted if I should ever come back.

I shall be telling this with a sigh Somewhere ages and ages hence: Two roads diverged in a wood, and I — I took the one less traveled by, And that has made all the difference.

Prerequisites

  • An OpenAI API key with access to gpt-4o-mini and text-embedding-3-small.
  • Python 3.10+ (for local setup) or Docker (for containerised setup).

Setting your API key

Export the key in your terminal before running the app:

export OPENAI_API_KEY=sk-your-key-here

On Windows (PowerShell):

$env:OPENAI_API_KEY = "sk-your-key-here"

Local setup

# 1. Create and activate a virtual environment
python -m venv venv
source venv/bin/activate        # macOS / Linux
# venv\Scripts\activate         # Windows

# 2. Install dependencies
pip install -r requirements.txt

# 3. Set your API key (see above)

# 4. Start the app
python app.py

Open http://localhost:5000 in your browser.

Docker setup

# Build the image
docker build -t rag-chatbot .

# Run the container (pass your API key)
docker run -p 5000:5000 -e OPENAI_API_KEY=sk-your-key-here rag-chatbot

Open http://localhost:5000 in your browser.

Usage

  1. Click Choose PDF and select a PDF file.
  2. Click Upload — wait for the "Successfully processed" message.
  3. Type a question in the input bar and press Enter or click Send.
  4. Upload additional PDFs at any time to expand the knowledge base.
  5. Click Clear docs to remove all indexed documents and start fresh.

Project structure

rag-chatbot/
├── app.py              # Flask application and RAG logic
├── templates/
│   └── index.html      # Chat web interface
├── requirements.txt    # Python dependencies
├── Dockerfile          # Container definition
└── README.md           # This file

About

Chatbot RAG Vibe Coding

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors