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".
- 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.
- 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.
- Role-Based Access Control (RBAC): Distinct
User(Search, Rate) andAdmin(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.
- 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.
- 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.
- Docker Desktop installed and running.
- Git.
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 --buildThe application will be available at:
- Frontend:
http://localhost:5173 - Backend API:
http://localhost:8000
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 --reload2. Frontend
cd client
npm install
npm run dev3. 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.
MIT