Skip to content

ritup04/hallucinationRAG

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🧠 Hallucination Detector — RAG + Groq Chat Assistant

A complete end‑to‑end application that detects hallucinations in text using a Retrieval‑Augmented Generation (RAG) pipeline and provides an AI-powered chat assistant using Groq LLMs.


🚀 Overview

This project allows users to:

✔ Paste text or upload a PDF/TXT file
✔ Perform hallucination detection using a custom RAG pipeline
✔ Extract claims from text and validate them using retrieved evidence
✔ Chat with an AI assistant powered by Groq
✔ Use a clean, modern, WhatsApp-like chat UI


🏗️ System Architecture

1. Ingestion Layer

  • Extracts text from PDFs or TXT files
  • Splits content into manageable chunks
  • Normalizes and prepares text for indexing

2. Indexing Layer (FAISS)

  • Converts each document chunk into embeddings
  • Stores embeddings in a FAISS vector index
  • Enables high‑speed similarity search

3. RAG Pipeline

Consists of:

  1. Claim Extraction
  2. Retriever (top‑k chunk retrieval)
  3. LLM‑based Verification
  4. Fact‑checking Verdict (Supported / Refuted / NEI)

4. Groq‑Powered Chat Assistant

  • Uses the Groq SDK
  • Low-latency inferencing
  • Provides conversational capabilities

📂 Project Structure

hallucination-detector/
│
├── .env
├── .gitignore
├── README.md
├── requirements.txt
│
├── data/
│   ├── corpora/
│   │   └── test.txt.jsonl
│   ├── uploads/              # runtime uploaded files
│   │   └── test.txt
│   ├── metadata.json
│   └── vector_index.faiss    # FAISS index generated
│
├── models/                   # (optional) huggingface models if downloaded
│
├── src/
│   ├── chunking/
│   │   ├── chunker.py
│   │   └── tokenizer_utils.py
│   │
│   ├── config/
│   │   ├── __init__.py
│   │   ├── paths.py
│   │   ├── settings_loader.py
│   │   └── settings.yaml
│   │
│   ├── embedder/
│   │   ├── __init__.py
│   │   └── embedder.py
│   │
│   ├── generator/
│   │   ├── __init__.py
│   │   ├── chat_generator.py
│   │   ├── generator.py
│   │   ├── groq_generator.py
│   │   └── modes.py
│   │
│   ├── index/
│   │   ├── __init__.py
│   │   └── index_builder.py
│   │
│   ├── ingest/
│   │   └── ingest_pipeline.py
│   │   └── chunker.py
│   │   └── pdf_parser.py
│   │   └── text_parser.py
│   │
│   ├── rag_pipeline/
│   │   ├── __init__.py
│   │   └── pipeline.py
│   │
│   ├── retriever/
│   │   ├── __init__.py
│   │   └── retriever.py
│   │
│   ├── ui/
│   │   ├── __init__.py
│   │   └── streamlit_app.py
│   │
│   └── verifier/
│       ├── __init__.py
│       ├── claim_extractor.py
│       └── verifier.py
│
└── architecture.png
└── system_design.png

📌 Features

🔍 1. Hallucination Detection

  • Uses claim extraction
  • Retrieves factual evidence
  • Applies NLI (Natural Language Inference)
  • Produces verdicts:
    • SUPPORTED
    • REFUTED
    • NOT ENOUGH INFO

🤖 2. Chat Assistant

  • Groq-powered conversational agent
  • Supports contextual memory
  • WhatsApp-like UI
  • Fast, low-latency responses

📄 3. PDF & TXT File Support

  • Extracts text using PyPDF2
  • Automatically processes chunks

🎨 4. Modern UI

  • Center‑aligned layout
  • WhatsApp-style chat bubbles
  • Animated send button
  • Clean dark theme

🛠️ Installation

1. Clone the Repository

git clone https://github.com/ritup04/hallucinationRAG.git
cd hallucinationRAG

2. Install Requirements

pip install -r requirements.txt

3. Setup Environment Variables

Create a .env file:

GROQ_API_KEY=your_key_here
GROQ_MODEL=llama3-8b-8192
CUDA_VISIBLE_DEVICES=-1

4. Run the App

streamlit run src/ui/streamlit_app.py

📘 How It Works

🔹 Step 1 — User Uploads Text

Paste input or upload a file.

🔹 Step 2 — Text Gets Split Into Chunks

Chunking improves retrieval quality.

🔹 Step 3 — Embeddings Computed

Using Sentence Transformers.

🔹 Step 4 — FAISS Index Search

Top relevant evidence chunks retrieved.

🔹 Step 5 — LLM Fact Verification

Groq or HF models determine if claims are factual.


🧪 Example Output

Claim: Lumeria is a real country.
Verdict: ❌ REFUTED
Evidence: No factual records found.


📬 Contact

For queries, suggestions, or feedback, please contact:

GitHub: ritup04
Email: ritupal1626@gmail.com

About

A RAG-based system that detects hallucinations by extracting claims, retrieving evidence, and verifying accuracy. Includes a fast Groq-powered chat assistant and a clean UI for seamless factuality checking.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages