Skip to main content

AI-powered document analysis and query generation tool with RAG capabilities

Project description

LawFirm RAG Package

A comprehensive Python package for document analysis and query generation using Retrieval-Augmented Generation (RAG) with local AI models. Currently optimized for legal documents with support for Westlaw, LexisNexis, and Casetext query generation.

Features

  • 📄 Document Processing: Extract and analyze text from various legal document formats
  • 🤖 AI-Powered Analysis: Local GGUF model support for document summarization and legal issue identification
  • 🔍 Query Generation: Generate optimized search queries for legal databases (Westlaw, LexisNexis, Casetext)
  • 🌐 Web Interface: Modern web UI for document upload and analysis
  • 🔧 CLI Tools: Command-line interface for batch processing
  • 💾 Model Management: Download, load, and manage AI models with progress tracking
  • 🏗️ Pip Installable: Clean package structure for easy installation and distribution

Quick Start

Installation

From PyPI (Recommended)

# Install directly from PyPI
pip install lawfirm-rag-package

From GitHub Repository

# Clone the repository
git clone https://github.com/DannyMExe/rag-package.git
cd rag-package

# Install the package in development mode
pip install -e .

Basic Usage

Web Interface

# Start the web server
rag serve

# Open http://localhost:8000/app in your browser

CLI Usage

# Analyze documents
rag analyze document.pdf --type summary

# Generate queries for legal databases
rag query document.pdf --database westlaw

# Process multiple files
rag analyze *.pdf --output results.json

# Additional options
rag serve --port 8080
rag analyze document.pdf --type summary

Git Bash Usage

If you're using Git Bash on Windows and the rag command isn't found, use one of these options:

Option 1: Use Python module syntax

# Run any command through the Python module
python -m lawfirm_rag.cli.main serve
python -m lawfirm_rag.cli.main analyze document.pdf

Option 2: Add Scripts directory to Git Bash PATH

Add this line to your ~/.bashrc file:

# Adjust the Python version in the path if needed
export PATH="$PATH:/c/Users/$USERNAME/AppData/Local/Packages/PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0/LocalCache/local-packages/Python311/Scripts"

Then restart Git Bash or run source ~/.bashrc

Option 3: Create an alias

Add this line to your ~/.bashrc file:

alias rag="python -m lawfirm_rag.cli.main"

Then restart Git Bash or run source ~/.bashrc

AI Model Setup

The package supports local GGUF models for privacy and offline operation:

  1. Via Web Interface: Use the Model Management section to download models
  2. Manual Download: Place GGUF files in the models/ directory
  3. Recommended Model: Law Chat GGUF (Q4_0 variant recommended)

Architecture

lawfirm_rag/
├── core/           # Core processing modules
│   ├── ai_engine.py       # GGUF model handling
│   ├── document_processor.py  # Document text extraction
│   ├── query_generator.py     # Legal database query generation
│   └── storage.py            # Document storage layer
├── api/            # FastAPI web server
├── cli/            # Command-line interface
├── web/            # Frontend assets
└── utils/          # Utilities and configuration

Legal Database Support

Westlaw

  • Syntax: Terms and Connectors
  • Operators: &, |, /s, /p, /n, !, %
  • Example: negligen! /p \"motor vehicle\" /s injur! & damag!

LexisNexis

  • Syntax: Boolean operators
  • Operators: AND, OR, NOT, W/n, PRE/n
  • Example: negligence AND \"motor vehicle\" AND damages

Casetext

  • Syntax: Natural language + Boolean
  • Features: Supports both natural language and boolean queries

Development

Project Structure

This project uses Task Master for development workflow management:

# View current tasks
task-master list

# Get next task to work on
task-master next

# Mark task complete
task-master set-status --id=X --status=done

Running Tests

# Install development dependencies
pip install -e \".[dev]\"

# Run tests
pytest

# Run with coverage
pytest --cov=lawfirm_rag

Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes
  4. Add tests for new functionality
  5. Commit your changes (git commit -m 'Add amazing feature')
  6. Push to the branch (git push origin feature/amazing-feature)
  7. Open a Pull Request

Configuration

Configuration is managed through:

  • .taskmasterconfig: AI model settings and parameters
  • .env: API keys and sensitive configuration (see .env.example)

Environment Variables

# AI Provider API Keys (optional - for cloud models)
ANTHROPIC_API_KEY=your_key_here
OPENAI_API_KEY=your_key_here
PERPLEXITY_API_KEY=your_key_here

# Local model settings
OLLAMA_BASE_URL=http://localhost:11434/api

API Reference

FastAPI Endpoints

  • POST /upload - Upload documents for analysis
  • POST /analyze - Analyze uploaded documents
  • POST /query - Generate database queries
  • GET /health - Service health check
  • POST /models/load - Load AI models
  • GET /models/loaded - Get loaded model status

Python API

from lawfirm_rag.core import DocumentProcessor, AIEngine, QueryGenerator

# Initialize components
processor = DocumentProcessor()
ai_engine = AIEngine(\"path/to/model.gguf\")
query_gen = QueryGenerator(ai_engine)

# Process document
text = processor.extract_text(\"document.pdf\")
summary = ai_engine.analyze_document(text, \"summary\")
query = query_gen.generate_query(text, \"westlaw\")

License

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

Acknowledgments

Support

For questions, issues, or contributions:

[project.urls] Homepage = "https://github.com/DannyMExe/rag-package" Documentation = "https://lawfirm-rag.readthedocs.io" Repository = "https://github.com/DannyMExe/rag-package" "Bug Tracker" = "https://github.com/DannyMExe/rag-package/issues" Changelog = "https://github.com/DannyMExe/rag-package/blob/main/CHANGELOG.md"

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rag_package-0.1.3.tar.gz (48.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rag_package-0.1.3-py3-none-any.whl (54.4 kB view details)

Uploaded Python 3

File details

Details for the file rag_package-0.1.3.tar.gz.

File metadata

  • Download URL: rag_package-0.1.3.tar.gz
  • Upload date:
  • Size: 48.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for rag_package-0.1.3.tar.gz
Algorithm Hash digest
SHA256 78ccbc2efa1ceb37cf4d9b666c7a102fcdbb77dd94ca1879c371210ecc9397b6
MD5 ba7fc27f56584eaf3b94e0e3bacfbd97
BLAKE2b-256 6bc7bdf856d7ee0adbfafa7db2e0ea6a53f5f9d497e88680a36ccdc69369670b

See more details on using hashes here.

Provenance

The following attestation bundles were made for rag_package-0.1.3.tar.gz:

Publisher: publish-to-pypi.yml on DannyMExe/rag-package

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rag_package-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: rag_package-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 54.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for rag_package-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 49efd2285f1871307a21af7d08242d61ed0b09b73222021e3257d694b6876cfb
MD5 8012616d4991553a9e566a402babc53a
BLAKE2b-256 b03333f677a75fabb223d25be6ab0f737a284e2f36091aa92470627da8a82d67

See more details on using hashes here.

Provenance

The following attestation bundles were made for rag_package-0.1.3-py3-none-any.whl:

Publisher: publish-to-pypi.yml on DannyMExe/rag-package

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page