RAG / Legal AI · Independent project

Law Agent: Multilingual Legal RAG Application

Author: Dmitri Derevjanko · Tallinn, Estonia · 2025-11 · updated 2026-08

Dmitri Derevjanko built Law Agent, a multilingual legal RAG application that answers questions about Estonian law with source citations.

Law Agent dashboard showing a source-backed legal answer with citations
Law Agent: live system built by Dmitri Derevjanko.

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

  1. Riigi Teataja Versioned Estonian statutes provide the canonical legal source.
  2. Ingestion Scheduled jobs normalize structure and split statutes into legal chunks.
  3. PostgreSQL + pgvector Text, metadata, versions, and embeddings stay in one queryable corpus.
  4. Version-aware retrieval Semantic search filters for the law in force on the requested date.
  5. Grounded generation Strict confidence rules constrain multilingual model responses.
  6. Cited UI FastAPI serves answers with quoted and inspectable legal provisions.
Infrastructure layer
  • Docker
  • Redis
  • GitHub Actions
  • Nginx
  • TLS
  • Backups and smoke checks
  1. Ingest Estonian statutes from Riigi Teataja, normalize structure, and split them into searchable legal chunks.
  2. Store embeddings in PostgreSQL with pgvector and refresh the corpus on a schedule instead of one-off reindexing.
  3. Retrieve by semantic match plus the law in force on the requested date, including current-law filtering.
  4. Generate answers that prefer quoted excerpts and direct citations; downgrade certainty when support is thin.
  5. Expose the product through a multilingual UI with citation inspection, corpus stats, and a public benchmark against a generic GPT baseline.
  6. 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

Technologies

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

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.

Other independent projects by Dmitri Derevjanko