RAG / Legal AI · Independent project
Law Agent: Multilingual Legal RAG Application
Dmitri Derevjanko built Law Agent, a multilingual legal RAG application that answers questions about Estonian law with source citations.
- 181k chunks
- 16k+ legal records
- ET / EN / RU
Open live demo Back to portfolio
Problem
Generic chat models can sound fluent on legal questions while citing the wrong statute, mixing versions of the law, or inventing provisions. People looking up Estonian law need answers tied to the text in force, not a plausible summary.
Solution
Law Agent is a source-grounded legal assistant. It retrieves statutory chunks from a maintained Estonian law corpus, answers in Estonian, English, or Russian, and shows the provisions used. Weak evidence makes the system more conservative instead of more confident.
System Architecture
Primary data and decision flow
- Riigi Teataja Versioned Estonian statutes provide the canonical legal source.
- Ingestion Scheduled jobs normalize structure and split statutes into legal chunks.
- PostgreSQL + pgvector Text, metadata, versions, and embeddings stay in one queryable corpus.
- Version-aware retrieval Semantic search filters for the law in force on the requested date.
- Grounded generation Strict confidence rules constrain multilingual model responses.
- Cited UI FastAPI serves answers with quoted and inspectable legal provisions.
- Docker
- Redis
- GitHub Actions
- Nginx
- TLS
- Backups and smoke checks
- Ingest Estonian statutes from Riigi Teataja, normalize structure, and split them into searchable legal chunks.
- Store embeddings in PostgreSQL with pgvector and refresh the corpus on a schedule instead of one-off reindexing.
- Retrieve by semantic match plus the law in force on the requested date, including current-law filtering.
- Generate answers that prefer quoted excerpts and direct citations; downgrade certainty when support is thin.
- Expose the product through a multilingual UI with citation inspection, corpus stats, and a public benchmark against a generic GPT baseline.
- Run behind Nginx with Docker, GitHub Actions, Redis, structured logging, backups, and smoke checks.
Role and Ownership
Sole product and engineering owner. Dmitri designed the retrieval architecture, implemented ingestion and serving, built the multilingual interface, and owns deployment and corpus maintenance.
Technical Decisions
- Used PostgreSQL with pgvector so statute metadata, versions, and embeddings stay in one queryable system.
- Made law version and effective date part of retrieval instead of treating the corpus as timeless text.
- Added strict confidence behaviour so weak evidence produces a conservative response rather than an unsupported answer.
- Kept citations and quoted provisions visible in the product so users can inspect the source instead of trusting model prose.
Technologies
- FastAPI
- PostgreSQL
- pgvector
- Redis
- OpenAI API
- Docker
- GitHub Actions
- Nginx
Result and Impact
A public legal RAG demo with 181k chunks over 16k+ legal records, automatic corpus updates, citation-first answers, and a benchmark that compares grounded replies with generic model output.
Limitations
- This is a personal demo of a legal RAG system, not a law firm, not legal advice, and not a substitute for a qualified lawyer.
- Coverage is Estonian statutory material in the indexed corpus, not every commentary, court decision, or private contract.
- Retrieval and model limits still apply; users should open the cited provision before relying on an answer.
Live demo and source
Live demo: https://counsel.dmitriderevjanko.com/
Source code: Private. The live demo is the public artifact for this project.
Portfolio case study: https://dmitriderevjanko.com/projects/law-agent/
This is one of 10+ independent public projects by Dmitri Derevjanko. 100+ additional workflows were delivered professionally, mostly under confidentiality, and are not documented here.