PROJECT 02 / Legal AI & verified retrieval
Statute Finder India.
Making AI-generated legal references verifiable by design.
A legal retrieval system combining hybrid search with deterministic citation validation and source-linked statutory text.
THE APPLICATION RESULT
THE HIGHLIGHTED SOURCE PDF
² In one documented local-model (Qwen 2.5 7B) run: every displayed quotation resolved in its source PDF. This is not legal accuracy. Informational, not legal advice.
01 / OVERVIEW
The model should not write the law.
Statute Finder India is a standalone legal information discovery prototype. A user describes an incident, optionally with a date, and the system retrieves candidate provisions from five statutes. The model only selects from those candidates and offers explanations; the application does the rest.
- The LLM selects opaque candidate IDs, never section numbers or quotations.
- The server removes invalid and repeated IDs, then resolves each citation from stored records.
- It re-reads the extracted PDF page text at stored character offsets and verifies the quotation.
- The interface shows the source PDF page with the quotation highlighted, and keeps model-written reading aids visibly separate from verbatim text.
READ THIS FIRST
This is informational, not legal advice, and no claim of legal accuracy is made. Verifying that a quotation exists in the source is a different thing from the answer being relevant or correctly interpreted.
02 / THE PROBLEM
A plausible answer is not a checkable one.
A fluent legal answer can cite a section that does not exist, or quote text that is not in the statute. The question here is narrower: can a retrieval system connect an incident description to candidate provisions while preserving a path back to the original source that a reader can inspect?
The corpus covers the BNS, the Motor Vehicles Act, the IT Act, the Arms Act and the Tamil Nadu Harassment of Women Act. For incidents before 1 July 2024 the application routes through a historical IPC mapping table; it does not contain the original IPC corpus.
03 / ARCHITECTURE
Retrieval, selection, verification.
Indexing: PyMuPDF section-aware parsing, then source hash, page and character provenance, then chunking and BGE-small embeddings via fastembed, then PostgreSQL with pgvector. Query: exact cosine search and BM25, combined with per-act and global reciprocal rank fusion, then structured Pydantic output where the LLM selects candidate IDs, then deterministic validation, then quote verification against the source PDF, then display with a highlighted source page. FastAPI serves the application.
Quotes, citations, page numbers and source URLs come from stored database records. The validator rejects candidate IDs outside the retrieved set, and a source quotation can be re-read from its PDF offsets.
04 / DECISIONS & TRADE-OFFS
Keep provenance out of the model.
Deterministic citation validation.
The model selects from retrieved records. It does not author the quotation, section reference or page number.
Trade-off. The model has less freedom: it cannot cite anything outside the retrieved candidates, even when it is right.
Exact search for a small corpus.
At this size an approximate index would add recall loss without a demonstrated speed benefit, so I used exact cosine search. No HNSW index is used.
Trade-off. Exact cosine does not scale to a much larger corpus the way an approximate index would.
Hybrid retrieval with rank fusion.
Vector search and BM25 are combined with per-act and global reciprocal rank fusion, because layperson wording often misses statutory phrasing.
Trade-off. Two retrievers and a fusion step are more to tune; BM25 parameters here are untuned defaults.
Make verification visible.
The application shows the cited PDF page with the quote highlighted so the reader can inspect the source instead of trusting the explanation.
Trade-off. Showing source pages adds interface weight, and a verified quote can still be irrelevant.
Date routing is deterministic: incidents before 1 July 2024 are treated under the IPC, mapped through a comparison table that is not an official publication, and incidents from that date under the BNS.
05 / DEBUGGING
Where the pipeline actually broke.
- Missing headings and overbroad footnote filtering in section-aware parsing silently dropped real sections.
- Table-of-contents checks were needed so contents pages were not mistaken for statute text.
- Weak text search was replaced with BM25 after full-text search failed on realistic queries.
- Invalid or repeated candidate IDs from the model are removed by the server, with a visible notice.
- Insufficient facts now produce a clarifying question with conditional candidates instead of a guess.
06 / TESTING & EVALUATION
Verification is not legal accuracy.
The project has 41 AI-assisted evaluation cases (33 with an expected section) and 102 passing automated tests in the captured CI run.
| Mode | hit@3 | Note |
|---|---|---|
| Keyword (BM25) | 12/33 | - |
| Vector | 21/33 | - |
| Hybrid (default) | 22/33 | The shipped default |
| Hybrid + query rewrite | 26/33 | Experimental; tuned on the same data, so not held-out |
In one local run with Qwen 2.5 7B, all 57 displayed quotations resolved in their source PDFs and no unretrieved ID was shown. It declined 7 of 8 out-of-scope cases and displayed the expected section in 21 of 33 cases. Only 26 of 56 displayed sections were labelled gold or acceptable.
WHAT THIS DOES NOT SHOW
The labels were drafted by an AI agent, are unreviewed by counsel, and come from a single non-deterministic run. The hosted model used by the public demo was not fully benchmarked. A real quotation can still be irrelevant or misapplied.
07 / DEPLOYMENT
Containerised, with the public demo kept off this page.
The repository includes Docker, Render and Neon configuration. The demo's current health has not been verified for this site, so it is not linked here; the source and this case study are the supported way to review the work.
Free-tier cold starts and model-provider rate limits would affect any hosted demo.
08 / LIMITATIONS
Explicit boundaries matter.
- A valid quotation does not mean the section is relevant or the legal interpretation is correct.
- Model-written summaries can reverse meaning even when the quoted source text is genuine.
- The corpus is five statutes, not a legal database, with no automatic amendment tracking and incomplete historical source text.
- Scanned PDFs are not handled, and retrieval remains sensitive to wording.
- The interface can expose raw missing values, such as “Punishment: null” in the capture above.
09 / NEXT STEPS
What I would do next.
- Make the source text primary and the generated reading aid secondary.
- Improve section selection and cross-reference handling for penalty provisions.
- Evaluate on a held-out set, with labels reviewed by a qualified lawyer, and benchmark the hosted model.
- Present missing values clearly instead of showing raw nulls.
These are planned improvements; none is claimed as already fixed.
Read the source and documentation on GitHubWORK WITH ME
Need something like this built?
I take on focused tasks as well as larger implementations. Tell me what you are trying to build.
06GET IN TOUCH
Let's build something
that works.
Open to full-time engineering roles. Relocation across India is fine.
View résuméFocused tasks or full builds. Tell me what you are trying to ship.
See what I can build