All projects

AI assistant on Moroccan law

A prototype assistant that answers legal questions from the texts of the law, designed so it can later run fully local.

Personal project · Python, FastAPI, Ollama, LangChain, ChromaDB

How it flows

Preparing the texts

  1. Legal textsimported and split (Built)
  2. Numerical representationscomputed locally with Ollama (Built)
  3. Vector databaseChromaDB, on the machine (Built)

Answering a question

  1. Questionasked from a command-line client (Built)
  2. FastAPI serverreceives the question (Built)
  3. Passage searchthe closest ones, in ChromaDB (Built)
  4. Language modelonline by default (Gemini or OpenAI), Ollama possible locally (External service)
  5. Answeror "I do not have the information" (Built)
The path of a question in the prototype. The language model is online by default.

The need

In law, an answer is only worth something if it rests on the texts. A language model alone answers from memory; this project answers from the documents.

What I built

A complete pipeline: documents are split, turned into numerical representations (embeddings) computed locally with Ollama, then stored in ChromaDB. A FastAPI server exposes the engine. For each question, the assistant retrieves the relevant passages and answers from them. The language model is configurable: online by default (Gemini or OpenAI, which then receives the question and the retrieved passages), or Ollama locally. The model's instructions are tuned for legally precise answers.

Why this approach

Answering from the documents limits made-up answers. This is a prototype: the language model is online by default, but the application is designed to run fully local one day, which matters for confidential documents.

Demo

Six questions, with a French voice-over (1 min 42) and English subtitles. The prototype's answers, not legal advice.

Screens

Architecture and flows

The prototype's components

  • Command-line client (Built)
  • n8nnot built yet (Possible, not enabled)
  • Legal texts (Users and data)
  • FastAPI server/chat, /ingest, /health, /config (Built)
  • RAG engineretrieval, JSON protocol, history (Built)
  • ChromaDBpersisted vector store (Users and data)
  • Ollamanumerical representations, locally (Built)
  • Language model provideronline by default: Gemini or OpenAI; Ollama locally (External service)
The prototype's components. The language model is online by default; n8n is not built yet.

Time given back

Illustrative scenario

This is not a measured result: it is what the project could give back, given the assumptions below.

For a firm, the time given back would come from looking up a text or an answer in its documentation, done by the assistant instead of searched by hand.

What it rests on

  • The current search time for each question: to be measured with the firm.
  • The number of questions asked each week: to be confirmed.
  • The firm's documents to include: to be defined together.

Technologies

Other projects

A task like this one?

Describe it in a few words. I reply with precise questions.

Describe my task