LegalOSS147.7ktracked
Legal AI & NLP

sb-legalMaintained

suhasbhairav/sb-legal

Bhairyam - The Open Source Sovereign Chat AI workspace for UK Legal Teams

GitHub
Legal AI & NLPai-agentsartificial-intelligencellm

Bhairyam

License: MIT UK legal AI Private workspace PDF and Word review Local AI PostgreSQL pgvector

Bhairyam is a private UK legal AI workspace for solicitors, barristers, in-house counsel, paralegals, and legal operations teams.

It helps a legal team upload matter documents, ask questions in plain English, find relevant passages, extract cited cases and legislation, and produce source-grounded answers for UK legal work.

Bhairyam AI sign-in landing page

Matter-based chat · PDF and Word review · UK case and legislation extraction · Drafts and agreements · Source-grounded answers · Private local AI · Mobile responsive

What Bhairyam Is For

Bhairyam is built for UK legal teams that need a controlled AI workspace around their own matter files.

Typical use cases:

Legal workflow How Bhairyam helps
Initial matter review Upload pleadings, correspondence, judgments, bundles, advice notes, and evidence files, then ask what the matter is about.
Legal research from uploaded documents Ask questions against the matter record and receive answers grounded in uploaded sources.
Case and legislation extraction See cases, neutral citations, CPR references, and legislation detected from each document.
Drafts and agreements Turn a chat prompt into a structured legal draft, review note, checklist, or comparison document.
Source checking Review the exact document chunks used to support an answer.
Chronology building Maintain matter events and key factual timelines.
Issues lists Track legal issues detected or added for a matter.
Evidence review Link propositions to supporting or contradicting evidence.
Document workspace Open the workspace view to inspect uploaded documents, sources, authorities, history, chronology, issues, and evidence.
Mobile work Use the interface on desktop, tablet, or mobile.

Current Features

Matter Workspace

  • Create and use legal matters.
  • Keep research, documents, authorities, issues, chronology, and evidence organised by matter.
  • Keep answers scoped to the selected matter rather than mixing unrelated client files.

Legal Chat

  • Ask questions in natural language.
  • Receive source-grounded answers from uploaded matter documents.
  • Answers include document labels such as [D1], [D2], and [D3].
  • If the AI generation step is slow, Bhairyam returns a fast extractive answer from the best retrieved passages.

Document Upload

  • Upload PDF files.
  • Upload Word/DOCX files.
  • Upload text-based legal material.
  • Uploaded files are stored locally.
  • Text is extracted and indexed automatically.
  • Document chunks are embedded for matter-specific retrieval.

Authorities And Citations

  • Extracts UK neutral case citations where detected.
  • Extracts legislation references.
  • Extracts CPR references.
  • Creates Case Law UK links for supported neutral citations.
  • Shows authorities detected from documents.

Drafts And Agreements

  • Toggle Drafts & Agreements mode inside the existing chat.
  • Choose a drafting or review skill.
  • Prompt in plain English.
  • Download a neatly formatted .docx file.
  • Use skills for commercial, finance, corporate, employment, real estate, and general transaction work.
  • Edit the local skills.md library through the draft-skills API when a firm wants to customise its own workflows.

Included drafting and review skills:

  • BPO agreement review
  • Commercial lease review
  • Compare documents
  • Corporate approvals review
  • Conditions precedent checklist draft
  • Credit agreement review
  • Design partner agreement draft
  • Design partner agreement review
  • Data processing agreement draft
  • Data processing agreement review
  • Draft from template
  • Employment agreement review
  • Extract key terms
  • Guarantee agreement review
  • Issues list draft
  • Master services agreement draft
  • Master services agreement review
  • Non-disclosure agreement review
  • Proofread
  • Shareholders' agreement review

UK Legal Focus

Bhairyam is designed for UK legal use, including:

  • England and Wales
  • Scotland
  • Northern Ireland
  • UK-wide statutes and authorities
  • UK court decisions
  • CPR and procedural references
  • UK regulatory and statutory materials when present in uploaded documents

Private Local AI

Bhairyam uses local AI through Ollama:

Purpose Default model
Answer drafting qwen3:8b
Document embeddings embeddinggemma

Your matter documents are processed against the local application stack.

Accounts And Access

  • Users can register and sign in.
  • User records are stored in the local database.
  • Matters, documents, and research history are linked to the user and organisation records.

Mobile Responsive Interface

  • Chat is designed to work across desktop and mobile.
  • Workspace pages adapt to smaller screens.
  • Navigation supports the document and research panels without requiring a wide monitor.

Quick Start

Install:

  • Docker Desktop
  • Ollama

Download the local AI models:

ollama pull qwen3:8b
ollama pull embeddinggemma

Start Bhairyam:

./scripts/start-production.sh

Open:

http://localhost:3000/register

Create an account, upload a PDF or Word document, and ask a question about the matter.

If port 3000 is already in use:

BHAIRYAM_WEB_PORT=3001 ./scripts/start-production.sh

Then open:

http://localhost:3001/register

How To Check It Is Working

Open the app:

http://localhost:3000

Check the backend:

http://localhost:8000/health

Expected backend response:

{"ok":true,"service":"bhairyam-backend"}

Check Docker:

docker compose ps

You should see:

  • bhairyam-postgres
  • bhairyam-backend
  • bhairyam-web

First Solicitor Demo Flow

For a clean demonstration:

  1. Register a user.
  2. Open the main chat workspace.
  3. Upload a UK judgment, pleading, advice note, contract, witness statement, or bundle extract.
  4. Open the document/workspace view and show the detected cases and legislation.
  5. Ask: What is this case about?
  6. Ask: What are the key legal issues?
  7. Ask: Which authorities are cited?
  8. Ask: What facts support the claimant's position?
  9. Toggle Drafts & Agreements and select Issues List Draft or Master Services Agreement Draft.
  10. Ask: Prepare a short solicitor-style case summary from the uploaded material.
  11. Download the generated .docx.
  12. Show the answer citations and source chunks.

What Happens When You Upload A File

In plain English:

  1. Bhairyam saves the original file.
  2. It reads the text from the PDF or Word document.
  3. It looks for cases, statutes, CPR references, and other legal authorities.
  4. It splits the document into searchable passages.
  5. It creates local embeddings for those passages.
  6. It stores everything in the local database.
  7. When you ask a question, it searches only the selected matter.
  8. It answers using the most relevant passages.

Useful Questions To Ask

Try questions like:

  • Summarise this matter for a partner.
  • What are the strongest points for the claimant?
  • What are the strongest points for the defendant?
  • List the cases cited in this document.
  • Which statutory provisions are relevant?
  • What limitation issues arise?
  • Create a chronology from the uploaded evidence.
  • Find contradictions in the witness evidence.
  • Draft a short advice note based only on the uploaded documents.
  • What further documents should the solicitor request?
  • Create an issues list as a downloadable Word document.
  • Draft a first version of a non-disclosure agreement review note for the client.

Data Kept By Bhairyam

Bhairyam stores:

  • User accounts
  • Organisations
  • Matters
  • Uploaded document records
  • Extracted document text
  • Search chunks and vectors
  • Detected cases and legislation
  • Research questions and answers
  • Audit events
  • Original uploaded files

Uploaded source files are stored locally in the application storage volume.

Stopping And Starting

Stop:

docker compose down

Start again:

docker compose up -d

View logs if something is not working:

docker compose logs -f web
docker compose logs -f backend

Project Structure

bhairyam/
  frontend/        Web app and user interface
  backend/         Document extraction and legal RAG backend
  migrations/      Database schema
  scripts/         Start scripts
  docker-compose.yml

Tests

Run frontend tests:

cd frontend
npm test

Run backend tests:

cd backend
.venv/bin/python -m pytest app/tests

Important Notes

  • Bhairyam is a legal AI workspace, not a solicitor.
  • It does not create a solicitor-client relationship.
  • Answers should be reviewed by a qualified legal professional before use.
  • The quality of answers depends on the quality and completeness of uploaded documents.
  • For urgent deadlines, limitation issues, injunctions, criminal matters, immigration detention, or risk of harm, seek immediate advice from a qualified UK lawyer.

License

This project is licensed under the MIT License.

See LICENSE.