← All work
NLP · RAG · Legal tech · 2026

Searchable case law with local LLMs

Hundreds of thousands of passages from Mexican federal court rulings, made searchable with hybrid retrieval and answered with literal citations by a model that runs locally.

RAGBM25bge-m3Qwenllama.cppInformation extraction
Bar chart: nDCG@10 and precision@10 for keyword search, hybrid with Qwen3 embeddings and hybrid with bge-m3 embeddings.
First comparison of retrievers on a small hand-checked set of six questions. The hybrid with bge-m3 won, and became the default; six questions is a sanity check, not a benchmark.
364,521indexed passages from ten district courts
1,161rulings summarised into structured argument cards
99%agreement of our ruling segmentation with the official outcome field
100% localno document leaves the machine

The problem

Federal district courts in Mexico City publish their rulings, but as thousands of long documents with no structure. A lawyer preparing a case wants to know how these courts have decided arguments like theirs, with the exact paragraph to cite.

How it works

  1. Rulingspublic court documents
  2. Textextraction + section segmentation
  3. IndexBM25 + bge-m3 embeddings
  4. Cardslocal LLM fills a structured schema
  5. Answerretrieval + literal citations

Design choices

  • Structure first. Text extraction keeps footnotes apart by font size; each ruling is segmented into its legal sections (background, admissibility, merits, outcome).
  • Hybrid retrieval. Keyword search (BM25) and dense embeddings, compared side by side on a hand-labelled question set before choosing.
  • Argument cards. A local LLM fills a fixed schema per ruling (claims, arguments, outcome), checked against hand-written gold cards.
  • Answers cite, never paraphrase. Every answer points to the literal passage and ruling it comes from.
  • Consistency checks for free. Comparing each ruling's reasoning with its operative part flagged 2 of 656 rulings whose reasoning concludes one way and whose decision goes the other.
About the data. The corpus and the collection process are not published. Screens shown are anonymised. The dataset can be shared on request for research purposes.