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.
