Ismail Ben Alla

Juridia

Multilingual Legal RAG

RAG · Jul 2024 · Completed

Fast question answering and search over 100,000+ Arabic and French legal documents.

Built withFastAPIPostgreSQLQdrantLlamaIndexReactBM25 + cross-encoder

Juridia — overview

Overview

Legal documents written in both Arabic and French are hard to search well: keyword search alone misses relevant texts, and embeddings alone are not precise enough for legal questions.

At Juridia I designed and deployed a production retrieval-augmented generation (RAG) system over more than 100,000 legal documents, built with FastAPI, LlamaIndex, PostgreSQL, and Qdrant, with a search interface offering keyword, semantic, and metadata search.

Combining BM25 with dense retrieval and multilingual embeddings, then reranking with a cross-encoder, improved retrieval precision by 18 to 22% while keeping average query latency below 350 ms. The main lesson: retrieval quality depends on the whole ranking pipeline, not on embeddings alone. The client implementation is private, so only this technical summary is shared.

The question

How can multilingual retrieval stay fast and precise across a large, domain-specific legal corpus?

Key features

How it works

  1. Index

    Documents are indexed for both keyword search and multilingual semantic search, using PostgreSQL and the Qdrant vector database.

  2. Hybrid retrieval

    A query is matched with both BM25 keyword search and dense semantic search, with metadata filters available.

  3. Rerank

    A cross-encoder reorders the candidates so the most relevant passages come first.

  4. Answer and serve

    Retrieval-augmented answers are served by a FastAPI service built with LlamaIndex, behind the React search interface.

Tech stack

What I learned

Limitations