TL;DR
LegalRAG introduces an advanced, bilingual Retrieval-Augmented Generation (RAG) framework designed specifically for low-resource legal documents like the Bangladesh Police Gazettes. By implementing an intelligent "Relevance Check" and "Query Refinement" loop powered by a lightweight LLM, the system filters out irrelevant context and rewrites vague queries before generating a final answer. This approach significantly improves retrieval precision and response accuracy, outperforming conventional RAG pipelines across both automated and human evaluations.
What Problem Does This Paper Address?
Applying Natural Language Processing (NLP) to the legal domain is notoriously difficult due to dense, unstructured text and complex terminology. This challenge is severely compounded in low-resource language settings. The authors focus on the Bangladesh Police Gazettes—official government publications that are highly unstructured and bilingual, containing a mix of English and Bangla.
Standard "vanilla" RAG pipelines often fail in this environment. They struggle to retrieve the correct text chunks due to the linguistic nuances of Bangla, and they blindly pass irrelevant or noisy context to the generation phase, leading to incomplete or hallucinated answers. LegalRAG aims to bridge this gap by making legal information retrieval robust and accessible, even for low-resource, bilingual regulatory texts.
Methods
The authors propose an Advanced RAG pipeline that introduces a critic mechanism into the standard retrieval flow.
- Document Processing: The bilingual PDFs are converted to images and processed using Tesseract OCR. The text is chunked using a recursive character splitter and embedded using
BAAI/bge-m3, a powerful multilingual embedding model. Chunks are stored in a ChromaDB vector database. - The Critique Loop (The Core Novelty): Instead of directly passing the top retrieved text chunks to the final generator LLM, LegalRAG introduces an intermediate layer powered by a computationally efficient model, Llama 3.2 (3B). This model performs two tasks:
- Relevance Check: It evaluates whether the retrieved text chunks actually contain the information needed to answer the user's query.
- Query Refinement: If the chunks are deemed irrelevant, the model refines (rewrites) the user's query to better capture its intent while preserving the original meaning.
- Iteration: The system uses the refined query to search the vector database again. This refinement cycle repeats for a maximum of $n=3$ iterations.
- Response Generation: Once relevant chunks are validated, they are passed alongside the query to a larger generative LLM (the authors experiment with Mixtral 8x7B, Llama 3.1 8B, and Gemma 2 9B) to produce the final answer.
Datasets
Because no standard benchmark exists for this domain, the authors curated a new evaluation dataset:
- Source Documents: 13 official Bangladesh Police Gazettes (2016–2023), comprising 81 pages of mixed English (65%) and Bangla (35%) text.
- Evaluation Dataset: 168 question-answer pairs generated using GPT-4o and rigorously cross-checked by human legal experts. The dataset is intentionally diverse, covering factual questions, temporal changes, statistical reasoning, grammatical/spelling errors, and out-of-context distractions.
Key Insights and Ideas
- Small Models Make Great Gatekeepers: Using a lightweight 3B model for the relevance check keeps the pipeline computationally efficient while preventing the final generator from being overwhelmed by noisy, irrelevant context.
- Bilingual Robustness: The pipeline proved highly robust regardless of whether the instruction prompts were given in English or Bangla. This indicates that modern multilingual embedding spaces can effectively align low-resource languages with high-resource ones.
- The Vulnerability to Out-of-Scope Queries: While the advanced pipeline significantly reduced errors for valid questions, both vanilla and advanced RAG frameworks still struggle when faced with completely out-of-context questions, sometimes generating incorrect answers with high confidence.
Key Results
The Advanced RAG framework consistently outperformed the Vanilla RAG across all tested language models, evaluated via both human scoring (1–5 scale) and semantic cosine similarity:
- Llama 3.1 (8B) emerged as the top performer. With the Advanced RAG pipeline, its human evaluation score jumped from 3.41 to 3.70, and its mean cosine similarity improved from 0.76 to 0.82.
- Ablation Studies:
- Temperature: Testing across multiple temperatures (0.1, 0.4, 0.7, 1.0) revealed that a low sampling temperature of 0.1 yielded the highest precision, which is vital for strict legal QA applications.
- Prompt Language: Performance remained stable whether the underlying prompt instructions were written in Bangla or English, confirming the system's multilingual flexibility.
Limitations and Future Work
The primary limitation is the system's handling of out-of-context queries; it struggles to definitively recognize when a query cannot be answered by the document corpus. Furthermore, base LLMs inherently lack deep exposure to specialized legal terminology during their initial pre-training.
The authors suggest that future work should focus on fine-tuning LLMs on a much larger, dedicated corpus of low-resource government documents and developing advanced NLP filtering techniques specifically designed to reject out-of-scope questions.
Summary updated