Skip to content

abdulsamad00529/rag-doc-chatbot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📚 RAG Document Chatbot

Chat with your PDF documents using AI — answers grounded in your documents, with exact source citations.

Python LangChain Groq FAISS Streamlit License


What is RAG?

RAG (Retrieval-Augmented Generation) is a technique that gives a language model access to your own documents at query time. When you ask a question, the system first searches your document library for the most relevant passages, then passes those passages to the LLM as context. This means the AI answers from your content, not from its training data — eliminating hallucinations and providing citable sources.


Features

  • Multi-PDF upload — upload one or several PDFs at once
  • Local embeddingsall-MiniLM-L6-v2 runs entirely on CPU, no API cost
  • FAISS vector search — blazing-fast similarity search, fully in-memory
  • Groq LLM — free-tier llama3-8b-8192 inference, sub-second latency
  • Source citations — every answer shows the exact file and page it came from
  • Conversation memory — multi-turn chat; follow-up questions work naturally
  • Strict grounding — the model is instructed to say "I cannot find this" rather than guess

Quick Start

1. Get a free Groq API key

  1. Go to console.groq.com
  2. Sign up (no credit card required)
  3. Navigate to API Keys → Create API Key
  4. Copy the key — it starts with gsk_

2. Install dependencies

pip install -r requirements.txt

First run downloads the all-MiniLM-L6-v2 model (~90 MB). Subsequent runs use the cache.

3. (Optional) Generate sample PDFs

python generate_samples.py

4. Run the app

streamlit run app.py

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


How It Works

┌─────────────┐    ┌──────────────────┐    ┌─────────────────┐    ┌──────────────┐
│  Upload PDF │───▶│  Chunk & Embed   │───▶│  FAISS Vector   │───▶│  Groq LLM   │
│  Documents  │    │  (MiniLM-L6-v2)  │    │  Store (local)  │    │  (llama3-8b) │
└─────────────┘    └──────────────────┘    └────────┬────────┘    └──────┬───────┘
                                                     │                    │
                                              ┌──────▼──────┐            │
                                              │  Top-4 most │            │
                                              │  relevant   │───────────▶│
                                              │  chunks     │  context   │
                                              └─────────────┘            │
                                                                  ┌──────▼───────┐
                                                                  │  Answer +    │
                                                                  │  Citations   │
                                                                  └──────────────┘

Demo

Upload the sample PDFs in sample_docs/ and try asking:

  • "What are the three types of AI?"
  • "How is a decision tree different from a neural network?"
  • "When was the term Artificial Intelligence coined?"

Project Structure

rag-doc-chatbot/
├── app.py              # Streamlit UI — chat interface, sidebar, session state
├── rag_chain.py        # LangChain RAG pipeline — chain + source formatting
├── vectorstore.py      # PDF loading, chunking, FAISS embedding & retrieval
├── generate_samples.py # One-time script to create demo PDFs
├── requirements.txt    # Pinned dependencies
├── .env.example        # Environment variable template
└── sample_docs/
    ├── ai_overview.pdf
    └── ml_concepts.pdf

Why Groq?

Groq's LPU (Language Processing Unit) hardware delivers 10× faster inference than GPU-based providers. The free tier gives you ~14,400 requests/day with llama3-8b-8192 — more than enough for development and demos — with no credit card required.


License

MIT © 2024

About

Chat with your PDF documents using RAG. Built with LangChain, FAISS vector store, Groq LLM, and Streamlit. Every answer cites its source.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages