Case study / RAG & Agents

Business Law RAG AI Assistant.

A retrieval-augmented assistant that answers only from its documents, cites the exact page, refuses what it cannot support, and checks its own answers for faithfulness.

Team project · Tech Tribe, GenAI Hackathon (week 26), 4 contributors

  • GPT-4o mini
  • text-embedding-3-small
  • FAISS
  • BM25
  • FastMCP
  • Gradio
  • PyMuPDF

View the repository ↗Read: Building RAG systems you can trust

Legal questions need answers you can verify. This assistant answers questions about business law using only a private PDF textbook, cites the exact page for every claim, refuses questions the documents cannot answer, and asks for clarification when a question is ambiguous.

469
pages indexed from one business-law textbook
466
searchable chunks
19/19
evaluation questions passed
$0.13
total API cost across 681 model calls

How it works

  1. 01ExtractPyMuPDF pulls text page by page and flags low-text pages
  2. 02Chunk and embed800-character sentence-boundary chunks with overlap, embedded with text-embedding-3-small into a FAISS index
  3. 03Reformulatefollow-up questions are rewritten into standalone queries using the chat history
  4. 04Hybrid retrievalFAISS and BM25 each return their top 20, fused with Reciprocal Rank Fusion into the best 5 excerpts
  5. 05GenerateGPT-4o mini answers from labelled excerpts with a versioned system prompt at temperature 0
  6. 06Judgean LLM-as-judge lists every claim and checks it against the excerpts before the answer is shown

The multi-agent mode

A second interface splits the work between three agents: an internal researcher that searches the textbook, an external fact-checker that searches the web through an MCP server, and a synthesizer that combines both and clearly separates what came from the corpus and what came from the web. A person can then approve, rewrite, or rephrase the answer, and approved web findings can be added back into the index.

How it was evaluated

The test set covers four kinds of question, because a trustworthy assistant has to behave well beyond the easy cases:

  • Factual: 11 of 11 answered from the documents
  • Cross-reference: 3 of 3 answered by combining several passages
  • Out of scope: 3 of 3 correctly refused
  • Ambiguous: 2 of 2 handled by clarifying or answering broadly

Every answered question was also judged faithful to its sources by the LLM judge.

A pass here means the assistant behaved correctly for the question type: answered, refused, or clarified. It is a behaviour check rather than a comparison with reference answers.

What I would do next

  • Add OCR so diagrams and image-only pages become searchable.
  • Grow the evaluation set and score answers against reference answers, not only behaviour.
  • Use the retrieval score as a confidence threshold for refusing out-of-scope questions earlier.

View the repository ↗Read: Building RAG systems you can trust