Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

15 Commits
Β 
Β 

Repository files navigation

title ComplianceRAG
emoji πŸ”Ž
colorFrom blue
colorTo indigo
sdk gradio
app_file app.py
pinned false
license mit

ComplianceRAG β€” Multi-Agent RAG with Live Groundedness Scoring

Live demo: [Open the Space](https://huggingface.co/spaces/Faraz618/ComplianceRAG) image

A small, self-contained Retrieval-Augmented Generation system that answers questions from a set of documents β€” but instead of just returning an answer, it shows you how grounded that answer actually is in the source material, which sentence it came from, and flags low-confidence answers for human review.

This was built to demonstrate the part of RAG systems that's usually invisible: the evaluation and trust layer, not just the retrieval-and-generate pipeline.

Why this exists

Most RAG demos show retrieval working. They rarely show what happens when retrieval fails β€” when the answer drifts from the source, or the model fills a gap with something that sounds right but isn't backed by the document. This project makes that failure mode visible and measurable instead of hiding it.

How it works

  1. Ingestion β€” Upload a .txt or .pdf, or use the included sample compliance document. The document is split into overlapping chunks.
  2. Retrieval Agent β€” Embeds the chunks with sentence-transformers and indexes them with FAISS. On a query, retrieves the top-k most relevant chunks.
  3. Generation Agent β€” Sends the retrieved chunks + question to an LLM (via the Hugging Face Inference API) to produce an answer with inline citations like [1], [2].
  4. Critic / Evaluation Agent β€” Independently re-checks the generated answer against the retrieved chunks using sentence-level similarity scoring, and produces:
    • A groundedness score (0–1): how well-supported the answer is by the retrieved text
    • A citation accuracy check: whether each [n] citation actually points to a chunk that supports the claim near it
    • A confidence flag: 🟒 Grounded / 🟑 Partially grounded / πŸ”΄ Low confidence β€” needs human review
  5. Human-in-the-loop view β€” Low-confidence answers are visually flagged and the underlying retrieved chunks are shown side-by-side with the answer, so a reviewer can verify in seconds without re-reading the whole document.

Architecture

 β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
 β”‚   Document    β”‚ ──▢  β”‚   Retrieval Agent   β”‚ ──▢ β”‚   Generation Agent  β”‚
 β”‚  (chunked +   β”‚      β”‚  (FAISS + sentence- β”‚     β”‚  (LLM via HF API,   β”‚
 β”‚   embedded)   β”‚      β”‚   transformers)     β”‚     β”‚   cited answer)     β”‚
 β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                                              β”‚
                                                              β–Ό
                                                  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                                                  β”‚     Critic Agent        β”‚
                                                  β”‚  (groundedness scoring, β”‚
                                                  β”‚   citation validation)  β”‚
                                                  β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                                              β”‚
                                                              β–Ό
                                                  🟒 / 🟑 / πŸ”΄ + flagged for review

This separation β€” retrieval, generation, and an independent critic that checks the generation against the retrieval β€” is a small-scale version of the orchestrator/specialist/critic pattern used in production multi-agent systems.

Tech stack

  • Gradio β€” UI and app framework
  • sentence-transformers (all-MiniLM-L6-v2) β€” embeddings for retrieval and for groundedness scoring
  • FAISS β€” vector search
  • Hugging Face Inference API β€” LLM generation (no local GPU required)
  • PyPDF β€” PDF text extraction

Try it yourself

  1. Click "Load Sample Document" or upload your own .txt/.pdf
  2. Ask a question about the document
  3. Watch the three-agent pipeline run: Retrieval β†’ Generation β†’ Critic
  4. Check the groundedness score and citation breakdown
  5. Try asking something the document doesn't cover β€” watch the confidence flag drop to πŸ”΄ and see why

What I'd build next

  • Swap single-document FAISS for a proper vector DB (ChromaDB/Pinecone) to support multi-document corpora
  • Add hybrid retrieval (BM25 + dense) for queries with exact keyword requirements (clause numbers, names)
  • Persist a ground-truth Q&A set and track groundedness drift over time (the evaluation-as-CI/CD pattern)
  • Add a second specialist agent for numeric/date claims specifically, since those are where hallucination is costliest in compliance contexts

Author

Built by Faraz Mubeen Haider β€” AI Engineer focused on agentic RAG systems, LLM evaluation, and production-grade AI applications.

LinkedIn Β· GitHub

About

Multi-agent RAG with a critic agent that scores groundedness and flags hallucinations in real time. FAISS + sentence-transformers + Gradio.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors