Skip to content

delphium226/LexChat2

Repository files navigation

LexChat: Secure Legal Research Assistant

A secure, agentic AI research assistant designed for the Scottish Government Internal Legal Department. LexChat leverages the UK Government LEX API for ground-truth legal data and Ollama for local inference, operating under a doctrine of "Intelligence Isolation".

Core Philosophy

  • Intelligence Isolation: The system is logically isolated. The LLM is prohibited from answering based on pre-trained knowledge and acts solely as a summarization and synthesis interface for the LEX API.
  • Strict Grounding: Uses "Strict Grounding Enforcers" to ensure answers are derived only from retrieved legal texts. If no relevant authority is found, the system explicitly states so.

Key Features

🔍 Deep Research Agent

  • Interactive Planning: Generates a research plan (checklist) which the user can review and edit before execution.
  • Map-Reduce Execution: Handles large context (e.g., >32k tokens) by summarizing individual statutes in parallel before final synthesis.

🛡️ Security & Governance

  • Role-Based Access Control (RBAC): Distinct User (Search, Rate) and Admin (Moderate, View Logs) roles.
  • Feedback Loop: Users rate answers. Low-rated feedback (≤ 2 stars) is queued for Admin review before being indexed, preventing "poisoning" of the RAG context.
  • Session Management: Idle timeouts (15m) and absolute timeouts (30m) with HttpOnly cookie storage.

🖥️ User Experience

  • Split-Screen Interface: Dedicated "Source Viewer" highlights cited text verbatim from the raw JSON API response side-by-side with the AI answer.
  • Accessibility: WCAG 2.1 AA compliant, with full screen reader support for loading states and semantic HTML.
  • Responsive Design: Polished UI using the Scottish Government color palette.

System Architecture

  • Frontend: React (TypeScript), Vite, Tailwind CSS.
  • Backend: Python (FastAPI), LangChain.
  • Inference: Ollama (Llama 3 / Mistral) running locally.
  • Database: PostgreSQL with pgvector (Vector Store, Logs, RBAC).
  • Task Queue: Celery & Redis (for long-running research tasks).
  • Infrastructure: Docker & Docker Compose.

Getting Started

Prerequisites

Running the Application (Production-like)

The easiest way to run the full stack (Frontend, Backend, Database, Redis, Worker) is via Docker Compose.

# Clone the repository
git clone <repository-url>
cd LexChat2

# Build and start all services
docker-compose up --build

The application will be available at:

  • Frontend: http://localhost:5173
  • Backend API: http://localhost:8000

Local Development

If you prefer to run services individually for development:

1. Backend

cd server
python -m venv venv
# Activate venv (Windows: .\venv\Scripts\activate, Mac/Linux: source venv/bin/activate)
pip install -r requirements.txt
uvicorn main:app --reload

2. Frontend

cd client
npm install
npm run dev

3. Infrastructure (DB & Redis) You will still need the database and redis running. You can use the docker-compose.yml but stop the web/app containers, or run independent instances.

License

MIT

About

Experiment re-writing LexChat using autonomous coding agents

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors