Case study · 2026
Mizan
A chatbot that answers questions about Moroccan law from the official texts only, cites the exact article and links the official PDF. It drops into any website as a small widget, with an animated character that thinks, talks, smiles or refuses.
- 2026
- Angular
- FastAPI
- Gemini
- pgvector

- 1,170
- articles indexed from the official texts
- 3
- official codes: labour, family, constitution
- 2
- searches fused: meaning and exact words
- 1
- tag to add it to any website
The problem
The law is public, but it lives in long PDFs, and general chatbots happily invent articles. Mizan only answers from the official texts (Code du travail, Code de la famille, Constitution), cites the exact article and links the official page. When nothing relevant is found, it says so instead of making something up. Its answers are information from the texts, not legal advice.
Finding the right article
The official PDFs are split into 1,170 passages, one per article, stored in PostgreSQL with pgvector. A question is first rewritten into French legal keywords, then two searches run side by side, one by meaning (multilingual-e5-large embeddings, computed locally) and one by exact words (Postgres full-text), and their results are fused with RRF.
Answers that cite
Gemini Flash writes the answer from the passages found, streamed to the widget word by word (server-sent events), with fallbacks when a model is busy. Only the sources the answer actually cites are returned.
Locked down
The API key stays on the server. Input is validated, requests are rate-limited per minute and per day, a filter catches prompt injection, and a canary token stops the answer if the instructions ever leak.
A character on any website
The front end is Angular, packaged as a Web Component (<mizan-chat>) in its own Shadow DOM, so one tag adds it to any site. Mizan, the character, is a Lottie animation with one segment per state: idle, listening, thinking, talking, happy, sad, refusing.
Stack
Angular, lottie-web, Python, FastAPI, Gemini, PostgreSQL with pgvector, multilingual-e5-large. Open source under the MIT licence; swap the documents and the prompt and it becomes a chatbot for any field.