Case study, 2026

Constitution.ng: legal AI that cites the section, or doesn’t answer

Constitution.ng answers plain-language questions about Nigeria’s Constitution and 19 federal Acts. Every part of every answer cites the provision it comes from, with the source wording beside it, and an answer the system can’t tie to its evidence is withheld rather than shown. I designed, built and evaluated all of it, from ingestion and retrieval to the interface and hosting.

Role
Sole engineer, Emelar Republik
When
2026, live
Retrieval
95% top-1, 100% top-5 on 40 held-out questions
Stack
Python, FastAPI, PostgreSQL and pgvector, bge-m3, DeepSeek, React, Cloudflare Workers and R2, Railway
Constitution.ng home page: Explore Nigeria's Constitution, with a search box and suggested questions
The Constitution.ng home page.

The problem with asking a chatbot about the law

A general-purpose language model will answer a constitutional question confidently whether or not it’s right. For legal text that’s the wrong failure: a plausible answer with no source is worse than no answer, because the reader can’t check it.

Retrieval that doesn’t lean on one signal

Each question goes to three retrievers at once: dense vector search over bge-m3 embeddings in pgvector, PostgreSQL full-text search, and a hand-curated topic guide that maps everyday phrasing to sections. Reciprocal-rank fusion combines them. An exact reference such as “Section 35(4)” skips the model entirely and goes straight to the stored text.

Results are reloaded from the canonical provision records and their text hashes re-checked, so the model only ever sees wording that is actually published. Keeping vectors in PostgreSQL means publishing or rolling back a corpus release is one transaction, with no separate vector store to keep in step.

Citations the model can’t invent

The drafting model has to cite evidence IDs on every block of its answer, and the server, not the model, turns those IDs into citations. Each draft passes deterministic checks and then a separate model verifier. If an answer can’t be tied to its evidence, it isn’t published.

That fails closed. Readers see more “I can’t answer that” and fewer confident mistakes, which is the right trade for legal text.

Measured, with the caveats written down

Retrieval is measured at section level. On a 40-question held-out set, the right section ranks first 95% of the time and in the top five every time. On the 57-question set the topic guide was built against, top-1 rose from 82% to 98%. CI gates an offline ranking check, backend tests with an 87% branch-coverage floor, Playwright tests and Worker tests.

I also publish what the numbers don’t prove. The held-out result was adopted with the held-out scores visible, so it is an optimistic estimate, and the 200-answer human review planned before launch hasn’t been done yet. Public answers went live as a dated, documented exception, with the safeguards that justify it.

Five languages, honestly labelled

Questions can be asked in English, Nigerian Pidgin, Yorùbá, Hausa or Igbo. Retrieval and validation run once, in English. Answers are then translated, checked and, for Yorùbá, Hausa and Igbo, judged by back-translation, falling back to English on any failure. Translations are labelled Beta because they haven’t yet had native-speaker review.

Built to run on a small budget

Every paid model call is reserved before it is made and settled afterwards, so spending limits hold under concurrency and provider timeouts. A Cloudflare Worker serves the interface and caches public pages at the edge; the FastAPI service, chat worker and PostgreSQL run on Railway, and source PDFs sit in R2. Answers stream over server-sent events with replay, so a dropped connection picks up where it left off.

Each of these choices, and what it costs, is recorded as an architecture decision record in the public repository.

Need an engineer who can own work like this? Write to me.

amosgodwin500@gmail.com