dhirajpatra/Legal-Document-Assistant

An intelligent document analysis system designed to assist legal professionals with case document processing, analysis, and retrieval using advanced AI techniques.

Jupyter Notebook

3

3 commits

updated Jan 29, 2026

See the code

README

Project development not completed yet do not clone or fork now

=====================================================================================

AI Legal Document Assistant

An intelligent document analysis system designed to assist legal professionals with case document processing, analysis, and retrieval using advanced AI techniques.

πŸ“‹ Overview

Business Use Case

Legal professionals handle vast amounts of documentation for case analysis. This application serves as an AI-powered secretary that can read, summarize, and analyze legal documents efficiently. By leveraging local Large Language Models (LLMs) and running entirely offline, it addresses critical privacy and security concerns inherent in legal document processing.

⚠️ IMPORTANT DISCLAIMER: This application is for demonstration purposes only. Users must exercise their own professional judgment, legal knowledge, and implement appropriate security measures according to their jurisdictional requirements and professional standards.

Key Features

  • Local Processing: Runs entirely on local infrastructure using Small Language Models (SLMs) and LLMs
  • Document Intelligence: Converts unstructured legal documents into structured, queryable formats
  • RAG Implementation: Utilizes Retrieval Augmented Generation for intelligent document querying
  • Natural Language Interface: Query documents using plain English
  • Privacy-First: No data leaves your local environment

πŸ—οΈ System Architecture

The application consists of three core components:

1. Document Extraction Engine

Advanced preprocessing pipeline for complex PDF documents containing tables, images, and charts:

  • OCR Integration: Optical Character Recognition for text extraction
  • Computer Vision Models: Layout analysis and component detection
  • Custom YOLO Model: Trained specifically for document layout detection
  • Multi-level Analysis:
    • Level 1: Document layout analysis using computer vision
    • Level 2: Component-specific content extraction
    • Level 3: High-level task analysis (entities, sentiment, summarization)

2. Vector Database & Retrieval System

Intelligent document storage and retrieval using:

  • Embedding Models: Convert documents to vector representations
  • Vector Database: Efficient similarity search and document retrieval
  • Advanced RAG Techniques: Re-ranking, query extensions, and auto-merging
  • LangChain Integration: Streamlined retrieval augmented generation

3. Language Model Interface

Natural language processing and user interaction:

  • Local LLM Support: Llama3, Gemma 2, and other open-source models
  • Multi-modal Capabilities: Text and image processing
  • Natural Language Queries: User-friendly document interaction
  • AI Agent Integration: Automated multi-function workflows

πŸ› οΈ Technology Stack

  • Document Processing: Unstructured, PyTesseract, Computer Vision models
  • Machine Learning: Custom YOLO, Vision Transformers, Layout Transformers
  • LLM Framework: LangChain, Local LLM inference
  • Vector Database: Efficient embedding storage and retrieval
  • Evaluation: TruLens, Weights & Biases for performance monitoring
  • Frontend: Streamlit (current), Full-stack web app (planned)
  • Database: SQL for metadata and query history

πŸš€ Installation and Setup

Prerequisites

  • Python 3.8+
  • Virtual environment manager (venv/conda)
  • Sufficient RAM for local LLM inference (8GB+ recommended)

Installation Steps

  1. Clone the repository
git clone [repository-url]
cd ai-legal-document-assistant
  1. Set up virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
  1. Install dependencies
pip install -r requirements.txt
  1. Configure environment variables
cp .env.example .env
# Add your API keys and configuration to .env file
  1. Install system dependencies (Linux/Ubuntu)
./install-pytesseract-for-linux.sh

πŸƒβ€β™‚οΈ Running the Application

Development Mode

Explore and develop new models/techniques:

cd src/dev/
jupyter notebook

Application GUI

Launch the Streamlit interface:

streamlit run apps.py

For One Step Setup

Windows: setup_lda.bat

Run the setup_lda.bat

Linux: setup_lda.sh

Windows Notes:

  1. Administrator Required: Tesseract OCR and Ollama installations require admin privileges
  2. Model Parameter: Run setup_lda.bat --model phi3:mini-4k to use a different model
  3. Manual Steps: The script opens browser links for manual installation if automatic methods fail
  4. Service Management: Ollama runs as a Windows service (starts automatically)
  5. Tesseract Path: Windows should automatically add Tesseract to PATH during installation

πŸ”’ Privacy and Security Considerations

CRITICAL: Users are responsible for:

  • Legal Compliance: Ensuring compliance with local data protection laws (GDPR, CCPA, etc.)
  • Professional Standards: Adhering to legal professional conduct rules
  • Security Implementation: Implementing appropriate access controls, encryption, and audit trails
  • Data Handling: Following firm policies for sensitive document processing
  • Backup and Recovery: Maintaining secure backup procedures
  • User Training: Ensuring proper training on AI tool limitations and appropriate use

This tool does not replace professional legal judgment and should be used as an assistive technology only.

πŸ“Š Model Evaluation

The system includes comprehensive evaluation frameworks:

  • Performance Metrics: Content relevance, answer relevance, accuracy, recall, precision
  • Monitoring Tools: TruLens and Weights & Biases integration
  • Continuous Improvement: Feedback loops for model refinement

πŸ—ΊοΈ Roadmap

  • Enhanced multi-modal document processing
  • Advanced AI agent capabilities
  • Full-stack web application with RESTful API
  • Enterprise-grade security features
  • Integration with popular legal software
  • Mobile application development

🀝 Contributing

We welcome contributions from the legal-tech community! Here's how you can contribute:

Ways to Contribute

  1. Bug Reports: Submit detailed bug reports with steps to reproduce
  2. Feature Requests: Propose new features or improvements
  3. Code Contributions: Submit pull requests with enhancements
  4. Documentation: Improve documentation and examples
  5. Testing: Help test the application with different document types
  6. Legal Domain Expertise: Provide insights on legal document processing needs

Contribution Guidelines

  1. Fork the repository and create a feature branch
  2. Follow coding standards and include appropriate tests
  3. Update documentation for any new features
  4. Submit pull requests with clear descriptions
  5. Participate in code reviews constructively

Development Setup for Contributors

# Install development dependencies
pip install -r requirements-dev.txt

# Run tests
python -m pytest

# Format code
black .
flake8 .

πŸ“„ License

This project is licensed under Apache License - see the LICENSE file for details.

This software is provided "as is" without warranty. Users assume full responsibility for compliance with applicable laws and regulations. The developers are not liable for any misuse or legal consequences arising from the use of this software.


Remember: This tool is designed to assist, not replace, professional legal judgment. Always verify results and consult with qualified legal professionals for critical decisions.

dhirajpatra/Legal-Document-Assistant

An intelligent document analysis system designed to assist legal professionals with case document processing, analysis, and retrieval using advanced AI techniques.

Jupyter Notebook

3

3 commits

updated Jan 29, 2026

See the code

README

Project development not completed yet do not clone or fork now

=====================================================================================

AI Legal Document Assistant

An intelligent document analysis system designed to assist legal professionals with case document processing, analysis, and retrieval using advanced AI techniques.

πŸ“‹ Overview

Business Use Case

Legal professionals handle vast amounts of documentation for case analysis. This application serves as an AI-powered secretary that can read, summarize, and analyze legal documents efficiently. By leveraging local Large Language Models (LLMs) and running entirely offline, it addresses critical privacy and security concerns inherent in legal document processing.

⚠️ IMPORTANT DISCLAIMER: This application is for demonstration purposes only. Users must exercise their own professional judgment, legal knowledge, and implement appropriate security measures according to their jurisdictional requirements and professional standards.

Key Features

  • Local Processing: Runs entirely on local infrastructure using Small Language Models (SLMs) and LLMs
  • Document Intelligence: Converts unstructured legal documents into structured, queryable formats
  • RAG Implementation: Utilizes Retrieval Augmented Generation for intelligent document querying
  • Natural Language Interface: Query documents using plain English
  • Privacy-First: No data leaves your local environment

πŸ—οΈ System Architecture

The application consists of three core components:

1. Document Extraction Engine

Advanced preprocessing pipeline for complex PDF documents containing tables, images, and charts:

  • OCR Integration: Optical Character Recognition for text extraction
  • Computer Vision Models: Layout analysis and component detection
  • Custom YOLO Model: Trained specifically for document layout detection
  • Multi-level Analysis:
    • Level 1: Document layout analysis using computer vision
    • Level 2: Component-specific content extraction
    • Level 3: High-level task analysis (entities, sentiment, summarization)

2. Vector Database & Retrieval System

Intelligent document storage and retrieval using:

  • Embedding Models: Convert documents to vector representations
  • Vector Database: Efficient similarity search and document retrieval
  • Advanced RAG Techniques: Re-ranking, query extensions, and auto-merging
  • LangChain Integration: Streamlined retrieval augmented generation

3. Language Model Interface

Natural language processing and user interaction:

  • Local LLM Support: Llama3, Gemma 2, and other open-source models
  • Multi-modal Capabilities: Text and image processing
  • Natural Language Queries: User-friendly document interaction
  • AI Agent Integration: Automated multi-function workflows

πŸ› οΈ Technology Stack

  • Document Processing: Unstructured, PyTesseract, Computer Vision models
  • Machine Learning: Custom YOLO, Vision Transformers, Layout Transformers
  • LLM Framework: LangChain, Local LLM inference
  • Vector Database: Efficient embedding storage and retrieval
  • Evaluation: TruLens, Weights & Biases for performance monitoring
  • Frontend: Streamlit (current), Full-stack web app (planned)
  • Database: SQL for metadata and query history

πŸš€ Installation and Setup

Prerequisites

  • Python 3.8+
  • Virtual environment manager (venv/conda)
  • Sufficient RAM for local LLM inference (8GB+ recommended)

Installation Steps

  1. Clone the repository
git clone [repository-url]
cd ai-legal-document-assistant
  1. Set up virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
  1. Install dependencies
pip install -r requirements.txt
  1. Configure environment variables
cp .env.example .env
# Add your API keys and configuration to .env file
  1. Install system dependencies (Linux/Ubuntu)
./install-pytesseract-for-linux.sh

πŸƒβ€β™‚οΈ Running the Application

Development Mode

Explore and develop new models/techniques:

cd src/dev/
jupyter notebook

Application GUI

Launch the Streamlit interface:

streamlit run apps.py

For One Step Setup

Windows: setup_lda.bat

Run the setup_lda.bat

Linux: setup_lda.sh

Windows Notes:

  1. Administrator Required: Tesseract OCR and Ollama installations require admin privileges
  2. Model Parameter: Run setup_lda.bat --model phi3:mini-4k to use a different model
  3. Manual Steps: The script opens browser links for manual installation if automatic methods fail
  4. Service Management: Ollama runs as a Windows service (starts automatically)
  5. Tesseract Path: Windows should automatically add Tesseract to PATH during installation

πŸ”’ Privacy and Security Considerations

CRITICAL: Users are responsible for:

  • Legal Compliance: Ensuring compliance with local data protection laws (GDPR, CCPA, etc.)
  • Professional Standards: Adhering to legal professional conduct rules
  • Security Implementation: Implementing appropriate access controls, encryption, and audit trails
  • Data Handling: Following firm policies for sensitive document processing
  • Backup and Recovery: Maintaining secure backup procedures
  • User Training: Ensuring proper training on AI tool limitations and appropriate use

This tool does not replace professional legal judgment and should be used as an assistive technology only.

πŸ“Š Model Evaluation

The system includes comprehensive evaluation frameworks:

  • Performance Metrics: Content relevance, answer relevance, accuracy, recall, precision
  • Monitoring Tools: TruLens and Weights & Biases integration
  • Continuous Improvement: Feedback loops for model refinement

πŸ—ΊοΈ Roadmap

  • Enhanced multi-modal document processing
  • Advanced AI agent capabilities
  • Full-stack web application with RESTful API
  • Enterprise-grade security features
  • Integration with popular legal software
  • Mobile application development

🀝 Contributing

We welcome contributions from the legal-tech community! Here's how you can contribute:

Ways to Contribute

  1. Bug Reports: Submit detailed bug reports with steps to reproduce
  2. Feature Requests: Propose new features or improvements
  3. Code Contributions: Submit pull requests with enhancements
  4. Documentation: Improve documentation and examples
  5. Testing: Help test the application with different document types
  6. Legal Domain Expertise: Provide insights on legal document processing needs

Contribution Guidelines

  1. Fork the repository and create a feature branch
  2. Follow coding standards and include appropriate tests
  3. Update documentation for any new features
  4. Submit pull requests with clear descriptions
  5. Participate in code reviews constructively

Development Setup for Contributors

# Install development dependencies
pip install -r requirements-dev.txt

# Run tests
python -m pytest

# Format code
black .
flake8 .

πŸ“„ License

This project is licensed under Apache License - see the LICENSE file for details.

This software is provided "as is" without warranty. Users assume full responsibility for compliance with applicable laws and regulations. The developers are not liable for any misuse or legal consequences arising from the use of this software.


Remember: This tool is designed to assist, not replace, professional legal judgment. Always verify results and consult with qualified legal professionals for critical decisions.