The Saudi Labor Law is a complex and evolving legal framework. For HR teams, employers, and employees, understanding its details โ from leave entitlements to termination rules โ often means scrolling through dozens of pages, interpreting legal text, and trying to connect articles to real-world cases.
I wanted to change that.
So I built Saudi Labor Law AI Assistant โ an intelligent, bilingual chatbot that answers legal questions instantly, explains relevant articles, and even analyzes employee-specific scenarios โ all powered by vector search, LLMs, and semantic retrieval.
๐ Why This Project Matters
The challenges were clear:
โ ๏ธ The official English translation of the law is outdated โ the Arabic version is the authoritative reference.
๐ Searching manually across legal PDFs is slow and error-prone.
๐ง HR teams need contextual interpretations, not just raw text.
The solution? Combine document parsing, embeddings, vector databases, translation, and LLM reasoning into one end-to-end system that delivers article-backed, trustworthy answers in Arabic or English.
๐ง What the AI Assistant Can Do
Hereโs what the system offers today:
๐ฌ Ask legal questions in Arabic or English โ answers come in the same language.
๐งพ Analyze real employee cases โ like leave eligibility, overtime pay, or termination compensation.
๐ Retrieve the exact legal articles that support every answer.
๐งโ๐ผ Integrate employee data (age, salary, service years) into the reasoning process for personalized results.
๐ Handle bilingual queries with automatic translation and context matching.
๐ง How It Works
The assistant is built on a robust NLP and retrieval pipeline:
๐ PDF Parsing โ The official Arabic labor law is parsed with PyMuPDF, preserving RTL text and diacritics.
๐ Structured Splitting โ The document is split into parts, chapters, and articles with metadata.
๐ Translation โ Each article is translated to English using Helsinki-NLP/opus-mt-ar-en for bilingual support.
๐ Vectorization โ Both Arabic and English texts are embedded using intfloat/multilingual-e5-base and stored in a Qdrant vector database.
๐ค Retrieval + Reasoning โ A VectorIndexRetriever fetches the most relevant articles, which are then passed to GPT-4o-mini for grounded, human-readable answers.
๐ Hybrid Search Evaluation โ After testing semantic and hybrid retrieval methods on 1,245 queries, hybrid search proved superior and is used by default.
๐งโ๐ผ Context-Aware Legal Reasoning
One of the most powerful features is employee-specific reasoning.
For example:
โIs this employee eligible for 30 days of annual leave if he has worked for 6 years?โ
The chatbot uses employee metadata (service years, salary, leave days, etc.) to reason about the law in context, delivering precise, actionable answers โ always citing the original legal article.
๐ฅ๏ธ Streamlit Interface
The frontend is built with Streamlit to make the experience intuitive and user-friendly:
๐ Auto-detect Arabic or English queries.
๐ Optional employee data input.
๐ Expandable references with similarity scores.
๐ Source tracing from Part โ Chapter โ Article.
๐ Example in Action
Arabic Example:
๐ค: ู
ุง ูู ู
ุฏุฉ ุงูุฅุฌุงุฒุฉ ุงูุณูููุฉ ุจุนุฏ ุฎู
ุณ ุณููุงุช ู
ู ุงูุฎุฏู
ุฉุ
๐ค: ูุณุชุญู ุงูุนุงู
ู ุซูุงุซูู ููู
ุงู ู
ู ุงูุฅุฌุงุฒุฉ ุงูุณูููุฉโฆ
๐: ุงุณุชูุงุฏูุง ุฅูู ุงูู
ุงุฏุฉ ุงูุชุงุณุนุฉ ุจุนุฏ ุงูู
ุงุฆุฉ
English Example:
๐ค: What are the sick leave entitlements for an employee?
๐ค: The employee is entitled to paid sick leave for a specific durationโฆ
๐: Based on Article 117 โ Chapter Four
๐งญ Whatโs Next
The project is just getting started. Planned enhancements include:
๐ PDF export of Q&A with references
๐งฎ HR calculators (end-of-service, overtime, vacation accrual)
๐ Arabic voice interaction
๐ HR analytics dashboard
๐งฐ Tech Stack
Component | Technology |
---|---|
Frontend | Streamlit |
LLM | GPT-4o-mini |
Embeddings | intfloat/multilingual-e5-base |
Vector DB | Qdrant |
Retrieval | LlamaIndex |
Translation | Helsinki-NLP/opus-mt-ar-en |
Parsing | PyMuPDF (fitz) |
๐ก Saudi Labor Law AI Assistant is open-source and licensed under MIT. Itโs built to make labor law understandable, accessible, and actionable โ for HR teams, companies, and employees across Saudi Arabia.
๐ Explore the Project
๐ GitHub Repository
I build This Project as Final Project Of learning LLm-ZoomCamp Course
Top comments (0)