Skip to content

Latest commit

 

History

21 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

⚖️ LexAnalyzer — Legal Contract Analysis System

A full-stack LegalTech application that combines Large Language Models (LLMs), Retrieval-Augmented Generation (RAG), multi-agent orchestration, and LLM fine-tuning to automate contract analysis, risk detection, and negotiation support.

🎯 Key Features

  • 📄 Multi-format document ingestion — PDF, DOCX, TXT, CSV, Markdown, JSON and JSONL
  • 🔍 RAG-based contract analysis using LangChain and ChromaDB
  • 🤖 Multi-agent analysis with four specialized agents
  • ⚠️ Legal risk and penalty detection
  • 📊 Structured extraction of contractual obligations
  • 🔄 Contract comparison against standard/reference contracts
  • 💡 Negotiation recommendations
  • 🧠 Dynamic model selection for base and fine-tuned models
  • 🎯 Integrated fine-tuning pipeline using Kaggle, LoRA and Unsloth
  • ☁️ Cloud inference with Groq
  • 🔒 Local/offline inference with Ollama
  • 🗄️ Object storage with MinIO
  • 🐘 PostgreSQL for application data and metadata
  • 🐳 Containerized microservices architecture with Docker Compose

🧠 Architecture

LexAnalyzer follows a microservices architecture that separates the web interface, backend API, AI processing, database, and document storage.

User
  |
  v
Frontend / Nginx
  |
  v
Go Backend (REST API)
  |
  +----> PostgreSQL
  |
  +----> MinIO
  |
  +----> Python / FastAPI RAG Service
              |
              +----> ChromaDB
              |
              +----> Groq / Ollama
              |
              +----> 4 Specialized Agents

The main components are deployed as independent Docker services and communicate through the Docker network.

📚 Knowledge Base & Multi-Format Document Ingestion

One of the main features of LexAnalyzer is its multi-format document ingestion pipeline.

The Knowledge Base supports the following document and data formats:

  • .pdf — Legal contracts and documents
  • .docx — Word documents
  • .txt — Plain-text documents
  • .csv — Structured datasets
  • .md — Markdown documents
  • .json — Structured data and training datasets
  • .jsonl — Training and structured datasets

Uploaded documents are processed and incorporated into the RAG pipeline, allowing the system to retrieve relevant information and enrich the context provided to the LLMs during contract analysis.

The ingestion pipeline was designed to support heterogeneous document sources rather than limiting the system to a single document format.

The Knowledge Base also integrates with the fine-tuning workflow, allowing .json and .jsonl datasets to be used for model training.

🧩 Key Components

🔄 Dynamic Model Selection

The Contract Analysis interface includes a dynamic model selector that displays the models currently available in the system:

  • Base Models — Foundation models ready for immediate use, such as Llama 3.
  • Fine-tuned Models — Models trained through the integrated Training module and registered in the application once training is completed successfully.

This allows users to switch between base and specialized models directly from the interface.

☁️ LLM Providers: Groq & Ollama

LexAnalyzer supports two inference modes:

Groq — Cloud inference

  • Fast cloud-based LLM inference.
  • No specialized local hardware required.
  • Configured as the default provider.

Ollama — Local inference

  • Enables local and offline model execution.
  • Useful when keeping inference entirely on the local environment.
  • Requires a locally downloaded model, for example:
ollama pull llama3.2

The provider can be selected through the environment configuration:

LLM_PROVIDER=ollama

🗄️ Document Storage with MinIO

LexAnalyzer uses MinIO, an S3-compatible object storage service, to store the original documents uploaded to the system.

The Go backend handles document uploads and bucket management, while the Python RAG service retrieves the required document content during the analysis pipeline.

MinIO exposes:

🎯 Integrated Fine-Tuning Pipeline

LexAnalyzer includes an integrated fine-tuning workflow that can be launched directly from the web interface.

The workflow is:

  1. Upload a dataset in .json or .jsonl format through the Knowledge Base.
  2. Select a base model and dataset.
  3. Launch a fine-tuning job from the Training interface.
  4. Connect to Kaggle automatically through the Kaggle API.
  5. Run the training process using GPU acceleration and parameter-efficient techniques such as LoRA and Unsloth.
  6. Register the trained model in LexAnalyzer once training is complete.
  7. Use the fine-tuned model through the dynamic model selector for subsequent contract analysis.

This creates an end-to-end workflow from dataset ingestion and model training to model registration and inference.

🗄️ Data & Storage Services

LexAnalyzer uses several storage components with different responsibilities:

Service Purpose
PostgreSQL Stores application data and metadata
ChromaDB Stores vector embeddings for RAG
MinIO Stores uploaded documents and files

🛠️ Technology Stack

AI & LLM

  • Python
  • LangChain
  • FastAPI
  • ChromaDB
  • Groq
  • Ollama
  • LoRA
  • Unsloth
  • Kaggle API

Backend

  • Go
  • REST API
  • PostgreSQL
  • MinIO

Frontend & Infrastructure

  • HTML
  • JavaScript
  • CSS
  • Nginx
  • Docker
  • Docker Compose

⚡ Quick Start

Prerequisites

Make sure you have:

  • Docker
  • Docker Compose
  • A Groq API key if using Groq as the LLM provider
  • Kaggle credentials if using the fine-tuning functionality

1. Configure environment variables

Create a .env file in the project root.

For Groq:

GROQ_API_KEY=your_api_key_here
LLM_PROVIDER=groq

For the fine-tuning functionality, configure the required Kaggle credentials:

KAGGLE_USERNAME=your_kaggle_username
KAGGLE_KEY=your_kaggle_api_key

2. Start the application

Build and launch the complete environment with:

docker-compose up --build

The first startup may take several minutes while dependencies and embedding models are downloaded.

3. Open the application

Once the services are running, open: http://localhost:3000

🔌 Services & Ports

Service Port Description
Frontend 3000 Web interface served by Nginx
Backend API 8080 REST API developed in Go
RAG Service 8001 Python/FastAPI AI service
PostgreSQL 5432 Application database
MinIO API 9000 S3-compatible object storage API
MinIO Console 9001 MinIO web interface

🚨 Troubleshooting

Backend connection errors

If you encounter errors such as Failed to load or Cannot connect to backend:

  • Make sure all Docker services have started successfully.
  • Check the Docker logs for the RAG service.
  • Verify that the application is accessed through port 3000.

Slow analysis

When using Ollama without dedicated GPU hardware, processing large contracts may take significantly longer.

For faster inference, use Groq:

LLM_PROVIDER=groq

Production deployment The project also includes a docker-compose.prod.yml configuration intended for cloud/server deployments, including Oracle Cloud infrastructure.

📁 Project Structure

LexAnalyzer/
├── backend/
│   └── services/
│       └── ...                  # RAG, agents and embeddings
├── frontend/                    # Web interface
├── chroma_db/                   # Persistent vector database
├── data/                        # Example datasets
└── docker-compose.yml            # Service orchestration

📄 License

MIT License

About

LegalTech platform combining RAG, fine-tuning, microservices, and agent orchestration for legal document analysis.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages