Home
Softono
ai-legal-compliance-assistant

ai-legal-compliance-assistant

Open source Python
326
Stars
44
Forks
0
Issues
29
Watchers
4 months
Last Commit

About ai-legal-compliance-assistant

AI-powered legal compliance assistant for alcohol beverage pricing laws โ€” extracts, analyzes, and explains New York state-level regulationsusing RAG + knowledge-graph reasoning.

Platforms

Web Self-hosted

Languages

Python

๐Ÿง  AI Regulatory Compliance Assistance System

An AI-based legal compliance analysis platform integrating Alibaba Cloud Bailian AI capabilities for regulatory document processing, semantic retrieval, compliance analysis, and knowledge-graph construction.


๐Ÿš€ System Overview

The AI Regulatory Compliance Assistance System automates compliance interpretation across complex legal frameworks.
It supports PDF / HTML regulation ingestion, AI-powered question answering, and explainable rule mapping through RAG + knowledge-graph techniques.


โœจ Key Features

1. Document Processing Module

  • ๐Ÿ“„ Upload PDF or HTML regulatory documents
  • ๐Ÿ” Automatic text extraction and segmentation
  • ๐Ÿงพ Metadata extraction and storage

2. Vectorization & Embedding Module

  • ๐Ÿง  Uses Alibaba Cloud Bailian Embedding API for text vectorization
  • ๐Ÿ—‚ Builds vector indexes for regulations
  • ๐Ÿ”Ž Enables semantic similarity search

3. Knowledge Graph Construction

  • โš–๏ธ Extracts legal entities (articles, violations, penalties, etc.)
  • ๐Ÿงฉ Identifies inter-entity relationships
  • ๐Ÿ—ƒ Outputs a JSON-formatted knowledge graph

4. Semantic Retrieval & Q&A (RAG)

  • ๐Ÿ“š Regulation retrieval based on vector similarity
  • ๐Ÿ•ธ Enhances context with knowledge graphs
  • ๐Ÿ’ฌ Generates professional answers via Qwen-Turbo model

5. Compliance Determination Workflow

  • ๐Ÿงฎ Multi-factor logical analysis for business compliance
  • ๐Ÿ“Š Risk-level evaluation
  • โš ๏ธ Violation identification & recommendation generation

6. Front-End Interactive Interface

  • ๐Ÿ—‚ Document upload & management
  • ๐Ÿค– Real-time Q&A interaction
  • ๐Ÿ“‘ Compliance analysis report
  • ๐Ÿ”— Knowledge-graph query
  • ๐Ÿ“ˆ System statistics dashboard

๐Ÿ— Technical Architecture

Backend Stack

Component Purpose
FastAPI Web framework
Python Core development language
Alibaba Cloud Bailian AI model service
scikit-learn Vector similarity computation
PyPDF2 PDF parsing
BeautifulSoup4 HTML parsing

Frontend Stack

Component Purpose
HTML5 Page structure
CSS3 Style design
JavaScript Interaction logic
Responsive Design Multi-device adaptation

Data Storage

  • ๐Ÿ—‚ JSON files โ€“ document / vector / graph data
  • ๐Ÿ’พ Local file system โ€“ for uploaded files

Environment Configuration

1. Basic Environment

Python 3.8+

2. Install Dependencies

pip install -r requirements.txt

3. Environment Variable Configuration

Create a .env file and configure it as follows:

ALIBABA_API_KEY="your api key"
QWEN_MODEL=qwen-turbo
EMBEDDING_MODEL=text-embedding-v1
DATA_DIR=./data
UPLOAD_DIR=./uploads

Quick Start

Method 1: Use the Launch Script

python run_system.py

Select โ€œ4. Full Testโ€ to perform a complete system test.

Method 2: Manual Start

Start the service

uvicorn main:app --host 0.0.0.0 --port 8000

Access the system

http://localhost:8000


## API Documentation

After the system starts, visit http://localhost:8000/docs to view the complete API documentation.

### Core API Endpoints
    โ€ข   POST /api/upload-document - Upload regulatory document
    โ€ข   GET /api/documents - Retrieve document list
    โ€ข   POST /api/build-knowledge-graph - Build knowledge graph
    โ€ข   POST /api/ask - Regulatory Q&A
    โ€ข   POST /api/compliance-analysis - Compliance analysis
    โ€ข   GET /api/search-regulations - Search regulations
    โ€ข   GET /api/knowledge-graph/query - Query knowledge graph
    โ€ข   GET /api/statistics - System statistics

## User Guide

### 1. Document Upload
1. Go to the "Document Upload" tab  
2. Select a regulatory file in **PDF** or **HTML** format  
3. Click **Upload** โ€” the system will automatically process the document  

### 2. Regulatory Q&A
1. Go to the "Regulatory Q&A" tab  
2. Enter a regulation-related question  
3. The system will provide a professional answer based on **RAG technology**  

### 3. Compliance Analysis
1. Go to the "Compliance Analysis" tab  
2. Fill in the business type and detailed description  
3. Obtain a compliance analysis report and recommendations  

### 4. Knowledge Graph
1. Go to the "Knowledge Graph" tab  
2. Build a knowledge graph (using already uploaded documents)  
3. Query related information for specific entities  

## Testing and Validation

The system includes a complete API testing suite:

```bash
# Run all tests
python tests/test_api.py

# Run with pytest
pytest tests/test_api.py -v

## Directory Structure

AI_Regulatory_Compliance_Assistance_System/ โ”œโ”€โ”€ app/ # Core application module โ”‚ โ”œโ”€โ”€ init.py โ”‚ โ”œโ”€โ”€ models.py # Data models โ”‚ โ”œโ”€โ”€ storage.py # Data storage โ”‚ โ”œโ”€โ”€ document_processor.py # Document processing โ”‚ โ”œโ”€โ”€ ai_client.py # AI service client โ”‚ โ”œโ”€โ”€ vector_service.py # Vector services โ”‚ โ”œโ”€โ”€ knowledge_graph.py # Knowledge graph โ”‚ โ”œโ”€โ”€ rag_service.py # RAG service โ”‚ โ”œโ”€โ”€ compliance_analyzer.py # Compliance analysis โ”‚ โ””โ”€โ”€ api.py # API routing โ”œโ”€โ”€ static/ # Front-end static files โ”‚ โ”œโ”€โ”€ index.html โ”‚ โ”œโ”€โ”€ style.css โ”‚ โ””โ”€โ”€ script.js โ”œโ”€โ”€ tests/ # Test files โ”‚ โ””โ”€โ”€ test_api.py โ”œโ”€โ”€ data/ # Data storage directory โ”œโ”€โ”€ uploads/ # File upload directory โ”œโ”€โ”€ main.py # Main application entry point โ”œโ”€โ”€ requirements.txt # Dependency file โ”œโ”€โ”€ .env # Environment configuration โ”œโ”€โ”€ run_system.py # Launch script โ””โ”€โ”€ README.md # System documentation



## Notes

1. **API Key**: Ensure that your Alibaba Cloud Bailian API key is valid and has sufficient quota.  
2. **File Formats**: Currently supports PDF and HTML formats; make sure the documents are clear and readable.  
3. **Network Connection**: A stable internet connection is required to access Alibaba Cloud services.  
4. **Storage Space**: Ensure there is enough disk space to store uploaded documents and generated data.  

## Future Enhancements

- Support for additional document formats (Word, TXT, etc.)  
- User permission management  
- Integration with more AI model options  
- Database persistence  
- Distributed deployment support  

## Technical Support

If any issues occur, please check the following:  
1. Whether environment variables are configured correctly  
2. Whether the network connection is stable  
3. Whether the API key is valid  
4. Review console error logs for troubleshooting  

---

ยฉ 2025 AI Regulatory Compliance Assistance System | Powered by Alibaba Cloud Bailian Platform