Retrieval-Augmented Generation for Domain-Specific Assistance: a Legal Case Study
Abstract
Retrieval-Augmented Generation (RAG) has emerged as an effective paradigm for grounding language-model outputs in verifiable sources while maintaining fluency. However, applying RAG to knowledge-critical domains such as law presents unique challenges: long documents with dense citations, jurisdictional variations, and stringent requirements for traceability and accuracy. We present NyayaDoot, a novel RAG-based legal assistant that addresses these challenges through three key contributions: (1) a hierarchical document segmentation strategy specifically designed for Indian legal texts that preserves statutory structure and cross-references; (2) a citation-first generation paradigm that enforces provenance tracking at the architectural level rather than as a post-hoc constraint; and (3) a comprehensive safety framework with automated escalation triggers for high-risk queries. Our system combines SentenceTransformers all-MiniLM-L12-v2 embeddings with a FAISS index and a constrained answer composer. We evaluate NyayaDoot on a curated benchmark of 500 legal queries spanning statutes, case law, and procedural questions. The system achieves Top-1 retrieval accuracy of 0.87 (95% CI: 0.84–0.90), Top-3 accuracy of 0.94, MRR of 0.90, and citation precision of 0.91, outperforming baseline approaches including BM25 and Doc2Vec. Mean response latency is 0.8 s on commodity hardware. A user study with 30 participants (15 law students, 15 general users) demonstrates high perceived usefulness (4.2/5.0) and citation clarity (4.1/5.0). Our ablation studies show that section-level segmentation contributes +12% to retrieval accuracy compared with document-level indexing, and cross-encoder reranking adds +3% precision at rank-1. We discuss deployment considerations, ethical safeguards, and limitations, and provide reproducibility details below.