Intelligent Legal Query System for Mexican Labor Law Based on Retrieval-Augmented Generation (RAG)
摘要
This project develops an intelligent legal query system for Mexican labor law using Retrieval-Augmented Generation (RAG) and natural language processing, democratizing legal knowledge for non-specialized users. The methodology integrates ChromaDB as vector database, multilingual embeddings from Hugging Face, Ollama with llama2:7b-chat model, FastAPI framework, and LangChain for AI orchestration. The modular architecture ensures scalability and efficient maintenance. The system operates through three stages: semantic retrieval from the legal knowledge base, contextual augmentation using a legal glossary, and response generation via specialized prompts. Customized re-ranking algorithms enhance search precision. The JSON-formatted knowledge base contains frequently asked questions, detailed answers, and a specialized Mexican labor law glossary. Results demonstrate high efficacy in addressing queries on fundamental labor law concepts (worker, minimum wage, dismissal) with three-to-five-minute response times and high retrieval precision. This project significantly contributes to AI applications in the legal sector, democratizing access to labor legal information in Mexico and establishing a replicable framework for other legal domains, with implications for legal education and access to justice.