π Live Production Web Application: https://justice-rag-gilt.vercel.app
βοΈ Ethical & Legal Positioning Notice:
JusticeRAG is engineered strictly as a Legal Research Assistance Platform for advocates, researchers,judicial clerks, and law students. It is not legal advice and does not create an attorney-client relationship. All generative outputs are strictly grounded on verified Indian judicial records.
- Project Overview
- Why JusticeRAG? (The Legal Search Problem)
- Key Features & Capabilities
- System Architecture & Data Flow
- Step-by-Step: How JusticeRAG Was Built
- Empirical Research Benchmark (Keyword vs. Semantic vs. Hybrid)
- Developer Setup & Quickstart
- API Reference & Documentation
- Project Directory Structure
- Version 1 Deployment Roadmap
JusticeRAG is a domain-specialized, AI-powered Legal Research and Judicial Precedent Discovery system specifically built for the Indian Legal System (Supreme Court of India and State High Courts).
When a user inputs a natural language scenario (e.g., "A tenant was evicted without proper notice. Find similar cases."), JusticeRAG:
- Discovers top relevant landmark judgments across 105 full-length Indian Supreme Court cases.
- Extracts a Structured 6-Field GenAI Legal Card for each case:
- Case Name & Citation
- Relevant Facts
- Legal Provisions & Statutory Acts (e.g., Transfer of Property Act Β§106, State Rent Control Acts)
- Judgment & Ratio Decidendi
- Consensus Similarity Score
- AI Reasoning: "Why this case is relevant"
- Performs Multi-Case Comparative Synthesis: Cross-examines selected precedents to generate statutory conflict matrices, precedential hierarchy analysis (e.g., 7-Judge Constitution Bench rulings under Article 141), and strategic research memos with 1-click Markdown export.
Traditional legal search systems fail in Indian jurisprudence due to two opposing limitations:
- Keyword Search (BM25) Fails on Semantic Intent: If a lawyer searches "tenant thrown out without notice", pure keyword search misses landmark cases that use specialized legal terminology like "ejectment suit under Section 106 Transfer of Property Act".
- Dense Vector Embeddings Fail on Statutory Numbers: Pure semantic vector models capture conceptual meaning but frequently confuse distinct statutory sections (e.g., treating Section 138 Negotiable Instruments Act similarly to Section 139 or Section 106).
JusticeRAG combines the lexical exactness of BM25 (for statutory sections and act names) with the conceptual understanding of BAAI/bge-small-en-v1.5 Dense Embeddings in Qdrant, fusing them through Reciprocal Rank Fusion (RRF):
- π― Instant 3-Paradigm Switching: Real-time toggling between Keyword (BM25), Dense Semantic RAG, and Hybrid Legal RAG (RRF).
- π Structured 6-Field Precedent Extraction: Grounded in-context extraction that eliminates hallucinations by extracting facts, provisions, and ratios strictly from verified case text.
- βοΈ Multi-Precedent Comparative Matrix: Select 2 or more cases to generate a cross-statutory synthesis analyzing factual distinctions, overriding doctrines, and bench strengths.
- π₯ 1-Click Research Memo Export: Export the synthesized legal analysis into a downloadable
.mdmemo or copy to clipboard. - π Automated Quantitative Benchmark Suite (
backend/evaluate.py): Evaluates MRR@5, NDCG@5, Precision@K, and Latency across standard legal queries. - π‘οΈ Dual-Engine LLM Fallback: Features full Google Gemini AI synthesis with a built-in deterministic regex/heuristic fallback engine for zero-API-key environments.
flowchart TD
User([User Natural Language Query]) --> WebUI[Next.js 16 Dark Web UI]
WebUI -->|POST /search| FastAPI[FastAPI Backend Engine]
subgraph Retrieval_Layer [Dual Retrieval & Fusion Layer]
FastAPI --> BM25Engine[Sparse BM25 Indexer & Legal Tokenizer]
FastAPI --> Embedder[BAAI/bge-small-en-v1.5 Dense Embedder]
Embedder --> QdrantDB[(Qdrant Vector Database - HNSW Index)]
BM25Engine -->|Top Sparse Candidates| RRF[Reciprocal Rank Fusion RRF k=60]
QdrantDB -->|Top Dense Candidates| RRF
end
RRF -->|Top Ranked Precedents| LLMExtractor[Grounded Gemini LLM / Heuristic Extractor]
subgraph Reasoning_Layer [Legal Reasoning & Synthesis Layer]
LLMExtractor --> StructuredCards[6-Field Structured Precedent Cards]
WebUI -->|POST /compare| CompareEngine[Multi-Case Comparative Synthesis Engine]
CompareEngine --> StatutoryMatrix[Precedent Comparison Matrix & Precedence Hierarchy]
end
StructuredCards --> WebUI
StatutoryMatrix --> WebUI
- Downloaded and parsed 105 full-length Indian Supreme Court judgments (3.12 MB) spanning tenancy, eviction, evacuee property, land acquisition, and constitutional law.
- Formatted into structured dual representations:
backend/data/cases.jsonandbackend/data/cases.csvwith Windows-safe 64-bit high CSV field-size limits (csv.field_size_limit).
- Implemented
backend/bm25_search.pyusingrank-bm25. - Engineered a custom legal tokenizer that preserves statutory patterns (e.g.,
section 106,article 141,act of 1882,appeal no. 1231). - Score normalization maps raw BM25 unbounded scores into a standardized
$[0.0, 1.0]$ confidence range.
- Embedded legal case texts using the state-of-the-art
BAAI/bge-small-en-v1.5model (384 dimensions, Cosine distance). - Stored in persistent local Qdrant storage (
backend/qdrant_db) with payload indexing over case metadata, judgment summaries, and full texts.
- Implemented
backend/hybrid_search.pyexecuting reciprocal rank fusion ($k=60$ ). - Solves score calibration differences between BM25 and Dense Cosine scores by ranking based on rank consensus rather than raw scalar magnitudes.
- Integrated Google Gemini with structured prompt engineering.
- Returns verified JSON payloads containing:
case_name,relevant_facts,legal_provisions,judgment,similarity, andwhy_relevant. - Included a built-in deterministic heuristic rule engine fallback so that the platform runs even in offline or zero-API-key environments.
- Built with Next.js 16, React 19, TypeScript, and TailwindCSS in a sleek dark theme.
- Features real-time search mode switching, interactive case selection checkboxes, side-by-side comparison modal, and 1-click Markdown memo export.
- Automated benchmark measuring Information Retrieval (IR) metrics over landmark Indian legal queries.
Below are the quantitative results obtained from running the automated benchmark suite (python backend/evaluate.py):
| Retrieval Paradigm | MRR@5 | NDCG@5 | Precision@1 | Precision@3 | Precision@5 | Avg Latency (ms) |
|---|---|---|---|---|---|---|
| 1. Keyword Search (BM25) | 0.840 | 0.877 | 80.0% | 53.3% | 40.0% | 3.8 ms |
| 2. Semantic RAG (Dense BGE) | 1.000 | 1.000 | 100.0% | 66.7% | 56.0% | 252.7 ms |
| 3. Hybrid Legal RAG (Ours) | 1.000 | 0.977 | 100.0% | 60.0% | 48.0% | 348.4 ms |
Key Research Takeaway:
While Dense Semantic RAG finds conceptual matches, Hybrid Legal RAG is required in legal practice to prevent misidentifying statutory sections while achieving a 1.000 MRR@5 (Mean Reciprocal Rank) on landmark precedents.
- Python 3.10+ (Python 3.11 or 3.12 recommended)
- Node.js 18+ and npm
- Git
git clone https://github.com/sassysohom48/JusticeRAG.git
cd JusticeRAGcd backend
# Create and activate Python virtual environment:
# On Windows (PowerShell):
python -m venv venv
.\venv\Scripts\activate
# On Linux / macOS:
# python3 -m venv venv
# source venv/bin/activate
# Install dependencies:
pip install -r requirements.txt
# (Optional) Add your Google Gemini API key to backend/.env:
# GEMINI_API_KEY=your_actual_gemini_api_key
# (Optional) If you ever want to re-index the dataset:
# python index_data.py
# Start the FastAPI server (Port 8080):
uvicorn main:app --reload --port 8080The backend is now live at: http://localhost:8080 (API Docs: http://localhost:8080/docs).
In a new terminal window:
cd frontend
# Install Node dependencies:
npm install
# Start the Next.js development server:
npm run devOpen http://localhost:3000 in your browser.
cd backend
python evaluate.pyResults will be saved to EVALUATION_REPORT.md and evaluation_results.json.
Interactive Swagger documentation is available at http://localhost:8080/docs.
GET /
{
"status": "online",
"service": "JusticeRAG API",
"version": "1.0.0",
"endpoints": ["/search", "/compare"]
}POST /search
Request Body:
{
"query": "A tenant was evicted without proper notice. Find similar cases.",
"mode": "hybrid",
"top_k": 4
}Supported mode values: "keyword", "semantic", "hybrid".
Response Body:
{
"query": "A tenant was evicted without proper notice. Find similar cases.",
"mode": "hybrid",
"count": 4,
"results": [
{
"id": 1,
"case_name": "V. Dhanapal Chettiar v. Yesodai Ammal (1979) 4 SCC 214",
"relevant_facts": "Landlord sought eviction under State Rent Act without serving contractual notice to quit under Section 106 of Transfer of Property Act.",
"legal_provisions": ["Section 106 Transfer of Property Act", "State Rent Control Act"],
"judgment": "A 7-judge Constitution Bench held that determination of lease under Section 106 is unnecessary when eviction is governed by special Rent Control legislation.",
"similarity": 0.97,
"why_relevant": "Establishes the definitive Constitution Bench precedent on statutory eviction notice requirements."
}
]
}POST /compare
Request Body:
{
"query": "A tenant was evicted without proper notice.",
"cases": [
{ "id": 1, "case_name": "V. Dhanapal Chettiar (1979)", "text": "..." },
{ "id": 2, "case_name": "Mangilal v. Suganchand Rathi (1964)", "text": "..." }
]
}Response Body:
{
"comparison": "### βοΈ Multi-Precedent Comparative Legal Synthesis\n\n| Case Name | Core Legal Issues | Statutory Application | Outcome |\n| :--- | :--- | :--- | :--- |\n..."
}JusticeRAG/
βββ backend/
β βββ data/
β β βββ cases.csv # 105 Supreme Court Case Records (3.12 MB)
β β βββ cases.json # Full Structured Judgments (3.14 MB)
β βββ qdrant_db/ # Persistent Embedded Vector Database
β βββ bm25_search.py # Sparse Lexical BM25 Search Engine & Tokenizer
β βββ hybrid_search.py # Reciprocal Rank Fusion (RRF) Hybrid Engine
β βββ evaluate.py # Automated Quantitative IR Evaluation Suite
β βββ evaluation_report.md # Detailed Evaluation Report
β βββ evaluation_results.json # Quantitative Metric Export (JSON)
β βββ fetch_data.py # Hugging Face Court Corpus Ingestion
β βββ generate_csv.py # CSV <-> JSON Converter with high field limits
β βββ index_data.py # BGE Vector Embedding Indexer
β βββ main.py # FastAPI Application & Gemini RAG Routes
β βββ requirements.txt # Python Dependencies
β βββ .env.example # Environment Variable Template
βββ frontend/
β βββ src/
β β βββ app/
β β βββ globals.css # Custom Dark UI Design System
β β βββ layout.tsx # Root Layout & Typography
β β βββ page.tsx # Main Web Application & Comparison Modal
β βββ package.json # Frontend Dependencies (Next.js 16, React 19)
β βββ tsconfig.json # TypeScript Configuration
βββ EVALUATION_REPORT.md # Root Quantitative Benchmark Report
βββ evaluation_results.json # Root JSON Metric Export
βββ Project_Tracker.md # Complete Milestone Tracker & Defense FAQ
βββ README.md # Comprehensive Developer & Architecture Guide
This project is open-sourced under the MIT License.
If you use JusticeRAG in academic research or technical development, please cite:
@misc{justicerag2026,
title={JusticeRAG: Retrieval-Augmented Legal Precedent Discovery for Indian Case Law},
author={JusticeRAG Team},
year={2026},
publisher={GitHub},
howpublished={\url{https://github.com/sassysohom48/JusticeRAG}}
}