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
AI Model Setup
The package supports local GGUF models for privacy and offline operation:
- Via Web Interface: Use the Model Management section to download models
- Manual Download: Place GGUF files in the
models/directory - 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
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Add tests for new functionality
- Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - 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 analysisPOST /analyze- Analyze uploaded documentsPOST /query- Generate database queriesGET /health- Service health checkPOST /models/load- Load AI modelsGET /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
- Built with FastAPI for the web framework
- Uses llama-cpp-python for local AI model support
- Task management powered by Task Master AI
Support
For questions, issues, or contributions:
- 🐛 Issues: GitHub Issues
- 💬 Discussions: GitHub Discussions
[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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rag_package-0.1.2.tar.gz.
File metadata
- Download URL: rag_package-0.1.2.tar.gz
- Upload date:
- Size: 48.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f6dffede126cc80f4a6fdbd27a1b0e56729cda36721fabee5e36f461958ec081
|
|
| MD5 |
c62068b4d2ed4952ef87e9594c1a08cd
|
|
| BLAKE2b-256 |
8b19ce039e5025e6689d4823c6239d58be79e3c823fe47497484eec18775199d
|
Provenance
The following attestation bundles were made for rag_package-0.1.2.tar.gz:
Publisher:
publish-to-pypi.yml on DannyMExe/rag-package
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rag_package-0.1.2.tar.gz -
Subject digest:
f6dffede126cc80f4a6fdbd27a1b0e56729cda36721fabee5e36f461958ec081 - Sigstore transparency entry: 221453600
- Sigstore integration time:
-
Permalink:
DannyMExe/rag-package@77f5b45b90f5b60ff193ca5a0359957d74b64214 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/DannyMExe
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@77f5b45b90f5b60ff193ca5a0359957d74b64214 -
Trigger Event:
release
-
Statement type:
File details
Details for the file rag_package-0.1.2-py3-none-any.whl.
File metadata
- Download URL: rag_package-0.1.2-py3-none-any.whl
- Upload date:
- Size: 53.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
34c6114e5f5b02342dadff41960cff57c2a48c14b3a7beab718c3d586e36297d
|
|
| MD5 |
f07cda8cc2b0829645813af456731f43
|
|
| BLAKE2b-256 |
9e861c621a23293d4661fc1b96a326b74f8157308abde4d4ba1d7dca099fa3f2
|
Provenance
The following attestation bundles were made for rag_package-0.1.2-py3-none-any.whl:
Publisher:
publish-to-pypi.yml on DannyMExe/rag-package
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rag_package-0.1.2-py3-none-any.whl -
Subject digest:
34c6114e5f5b02342dadff41960cff57c2a48c14b3a7beab718c3d586e36297d - Sigstore transparency entry: 221453612
- Sigstore integration time:
-
Permalink:
DannyMExe/rag-package@77f5b45b90f5b60ff193ca5a0359957d74b64214 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/DannyMExe
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@77f5b45b90f5b60ff193ca5a0359957d74b64214 -
Trigger Event:
release
-
Statement type: