Case study · AI

LexBase: private legal knowledge assistant: grounded answers from a firm's own documents, with nothing sent to outside embedding services

A multi-tenant retrieval-augmented generation system for law firms. Each firm indexes its own PDFs, searches them with hybrid vector and keyword retrieval, and generates cited summaries. Built at ILMOTECH as part of the engineering training programme.

Client
Internal: ILMOTECH engineering programme
Timeline
2026
Role
Design, mentoring and review, ILMOTECH
Stack
FastAPI, PostgreSQL, pgvector, sentence-transformers, Groq, React, TypeScript
A legal research question answered from the firm's own documents, with every claim carrying a numbered citation back to a source passage

The challenge

Law firms sit on thousands of pages of contracts, opinions and precedents that are hard to search and impossible to ask questions of. Off-the-shelf AI tools solve the search problem by sending documents to third-party services, which is exactly what a firm handling client-confidential material cannot do.

LexBase was built to answer a specific question: can a small team deliver useful, grounded AI search over private documents without client data ever leaving the firm's own infrastructure?

Approach

Embeddings are generated locally with a sentence-transformer model, so indexing costs nothing per document and no text is sent to an external embedding API. Retrieval is hybrid: vector similarity and full-text keyword search are fused with reciprocal rank scoring, which catches both the paraphrased question and the exact statutory phrase.

Generation is optional and role-gated. Lawyers and associates can ask for a summary of the retrieved passages, and the answer cites its sources by document and page. Paralegals get search without generation. Query suggestions come from a TF-IDF model over the firm's own corpus, again with no model call.

Every firm is a tenant with isolated documents, users and logs. Roles are enforced on every endpoint in the backend; the frontend only mirrors them for navigation.

Architecture

  • FastAPI backend on Python 3.12 with SQLAlchemy and Alembic migrations.
  • PostgreSQL 16 with pgvector for an HNSW vector index and a GIN full-text index side by side.
  • PyMuPDF for page-level extraction and token-aware recursive chunking with overlap.
  • A hosted LLM API for generation at low temperature, swappable for a self-hosted model.
  • React 19 single-page app with JWT auth, silent refresh and role-aware routes.
  • Per-IP rate limiting on login and search.

Results

LexBase runs as a complete system: upload, index, hybrid search, cited generation and team management, with tenant isolation and role enforcement in place. It was built as a training project, so it has not been deployed for a paying firm; it is the reference implementation ILMOTECH starts from when a client needs private RAG over their own documents.

Back to all work
Next projectMulti-tenant UK compliance and HR platform for licensed sponsors

Have a similar challenge?

Book a call and we will walk through how this would apply to your situation.