| title | ComplianceRAG |
|---|---|
| emoji | π |
| colorFrom | blue |
| colorTo | indigo |
| sdk | gradio |
| app_file | app.py |
| pinned | false |
| license | mit |
Live demo: [Open the Space](https://huggingface.co/spaces/Faraz618/ComplianceRAG)

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.
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.
- Ingestion β Upload a
.txtor.pdf, or use the included sample compliance document. The document is split into overlapping chunks. - Retrieval Agent β Embeds the chunks with
sentence-transformersand indexes them with FAISS. On a query, retrieves the top-k most relevant chunks. - 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]. - 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
- 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.
ββββββββββββββββ βββββββββββββββββββββ ββββββββββββββββββββββ
β 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.
- 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
- Click "Load Sample Document" or upload your own
.txt/.pdf - Ask a question about the document
- Watch the three-agent pipeline run: Retrieval β Generation β Critic
- Check the groundedness score and citation breakdown
- Try asking something the document doesn't cover β watch the confidence flag drop to π΄ and see why
- 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
Built by Faraz Mubeen Haider β AI Engineer focused on agentic RAG systems, LLM evaluation, and production-grade AI applications.