Retrieva Labs

Insights9 min read

Building an Enterprise Legal AI Platform: Triple Search, Anonymization and RAG

How I built Datagreffe Justice: triple-search retrieval over 50,000+ court decisions, 98% PII detection, 100% compliance and sub-2-second cited answers.

Muhammad Mubashir

Founder & CEO, Retrieva Labs

  • RAG
  • Legal AI
  • Anonymization
  • Elasticsearch
  • Claude API

The problem

A legal-tech platform needed to make more than 50,000 French-language court decisions useful to legal professionals. Traditional keyword search was failing: lawyers needed semantic understanding, exact citations and the full chain of appeals, not a list of keyword matches.

Every decision also contained personal data. Nothing could be indexed or published until parties, witnesses, addresses, identification numbers and financial details were removed, with extra protection for minors and vulnerable people, and in line with the OHADA legal standards that apply across several jurisdictions.

The architecture

The system needed four core capabilities: document ingestion, anonymization, retrieval and AI-powered answers with source citations. The work ran across three consecutive engagements, each extending the platform.

Document pipeline

Every decision goes through a multi-stage pipeline. Text extraction handles PDFs and Word documents. A chunking strategy splits documents into 512-token chunks with a 50-token overlap to preserve context across boundaries. Embeddings power semantic search, and Claude handles anonymization and generation.

Triple-search architecture

No single search method was good enough for legal research, so retrieval combines three:

  • Keyword search (BM25) catches exact legal terms, article numbers and case references.
  • Semantic vector search on Pinecone finds passages that mean the same thing in different words.
  • Structured metadata and decision-chain search on Elasticsearch filters by court, date and jurisdiction, and follows a case through its appeals.

The results are fused and ranked together. This hybrid approach retrieved 15% better than any single method on its own.

Multi-jurisdiction anonymization

I built an anonymization engine using Claude, guided by jurisdiction-specific rules, that detects names, addresses, ID numbers and financial data before any document is indexed or sent to a model. Minors and vulnerable parties get stricter rules and dedicated checks.

The engine reached 98% PII detection accuracy, and the platform met 100% of its data-protection and OHADA compliance requirements. Because anonymization happens before indexing, compliance never depends on a downstream filter remembering to do its job.

Key technical decisions

Why Pinecone alongside Elasticsearch? Pinecone handles vector search at very large scale with sub-second latency. With 512-token chunks, 50,000 documents produce roughly 200,000 vectors, which Pinecone serves comfortably, while Elasticsearch does what it does best: keyword and structured search.

Why Claude Sonnet? Legal French is complex. In my testing, Claude Sonnet outperformed GPT-4 on French legal comprehension, particularly for OHADA compliance language.

Why access control at query time? Three-tier role-based access control decides what each user can retrieve, so permissions are enforced on every search, not only in the interface.

Results

  • 50,000+ court decisions processed and indexed
  • 98% PII detection accuracy across jurisdictions
  • 100% data-protection and OHADA compliance
  • 80% reduction in document creation time with the AI generation module
  • Sub-2-second end-to-end responses at 95%+ retrieval confidence
  • Around 23 documented API endpoints behind three-tier access control

Lessons learned

Chunk size matters more than model choice. I tested 256, 512 and 1,024-token chunks, and 512 with overlap worked best for legal documents with dense, structured paragraphs.

Always build an evaluation set before optimizing. I created 200 legal question-and-answer pairs with a lawyer and ran every architecture change against them. That prevented several regressions that would otherwise have reached users.

Taking on new projects

Let’sbuild.

Have an AI project in mind? Let’s make it real.

Book a free 30-minute strategy call with our founder. You’ll leave with a clear view of the right architecture, timeline and next step, whether or not we work together.

  • Reply within 24 hours
  • NDA before you share anything confidential
  • You own the code, prompts and documentation
  • Hours overlap with US, UK, EU and Gulf teams
Or get an instant AI plan with the Project Scoper
Book a free strategy call