<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Zainalabdeen</title>
    <description>The latest articles on Forem by Zainalabdeen (@zainalabdeen).</description>
    <link>https://forem.com/zainalabdeen</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F650208%2Fe56377ce-68f2-48f1-94eb-7661209ea223.png</url>
      <title>Forem: Zainalabdeen</title>
      <link>https://forem.com/zainalabdeen</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/zainalabdeen"/>
    <language>en</language>
    <item>
      <title>🧑‍⚖️ Building a Saudi Labor Law AI Assistant — Bilingual, Semantic, and Context-Aware</title>
      <dc:creator>Zainalabdeen</dc:creator>
      <pubDate>Sat, 11 Oct 2025 21:21:04 +0000</pubDate>
      <link>https://forem.com/zainalabdeen/building-a-saudi-labor-law-ai-assistant-bilingual-semantic-and-context-aware-597e</link>
      <guid>https://forem.com/zainalabdeen/building-a-saudi-labor-law-ai-assistant-bilingual-semantic-and-context-aware-597e</guid>
      <description>&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;I wanted to change that.&lt;br&gt;
So I built &lt;strong&gt;Saudi Labor Law AI Assistant&lt;/strong&gt; — 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.&lt;/p&gt;




&lt;h2&gt;
  
  
  📌 Why This Project Matters
&lt;/h2&gt;

&lt;p&gt;The challenges were clear:&lt;/p&gt;

&lt;p&gt;⚠️ The official English translation of the law is outdated — the Arabic version is the authoritative reference.&lt;/p&gt;

&lt;p&gt;📚 Searching manually across legal PDFs is slow and error-prone.&lt;/p&gt;

&lt;p&gt;🧠 HR teams need contextual interpretations, not just raw text.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;




&lt;h2&gt;
  
  
  🧠 What the AI Assistant Can Do
&lt;/h2&gt;

&lt;p&gt;Here’s what the system offers today:&lt;/p&gt;

&lt;p&gt;💬 Ask legal questions in Arabic or English — answers come in the same language.&lt;/p&gt;

&lt;p&gt;🧾 Analyze real employee cases — like leave eligibility, overtime pay, or termination compensation.&lt;/p&gt;

&lt;p&gt;🔍 Retrieve the exact legal articles that support every answer.&lt;/p&gt;

&lt;p&gt;🧑‍💼 Integrate employee data (age, salary, service years) into the reasoning process for personalized results.&lt;/p&gt;

&lt;p&gt;🌐 Handle bilingual queries with automatic translation and context matching.&lt;/p&gt;




&lt;h2&gt;
  
  
  🔧 How It Works
&lt;/h2&gt;

&lt;p&gt;The assistant is built on a robust NLP and retrieval pipeline:&lt;/p&gt;

&lt;p&gt;📄 &lt;strong&gt;PDF Parsing&lt;/strong&gt; – The official Arabic labor law is parsed with PyMuPDF, preserving RTL text and diacritics.&lt;/p&gt;

&lt;p&gt;🔎 &lt;strong&gt;Structured Splitting&lt;/strong&gt; – The document is split into parts, chapters, and articles with metadata.&lt;/p&gt;

&lt;p&gt;🌐 &lt;strong&gt;Translation&lt;/strong&gt; – Each article is translated to English using Helsinki-NLP/opus-mt-ar-en for bilingual support.&lt;/p&gt;

&lt;p&gt;📊 &lt;strong&gt;Vectorization&lt;/strong&gt; – Both Arabic and English texts are embedded using &lt;strong&gt;intfloat/multilingual-e5-base&lt;/strong&gt; and stored in a Qdrant vector database.&lt;/p&gt;

&lt;p&gt;🤖 Retrieval + Reasoning – A VectorIndexRetriever fetches the most relevant articles, which are then passed to GPT-4o-mini for grounded, human-readable answers.&lt;/p&gt;

&lt;p&gt;📈 &lt;strong&gt;Hybrid Search Evaluation&lt;/strong&gt; – After testing semantic and hybrid retrieval methods on 1,245 queries, hybrid search proved superior and is used by default.&lt;/p&gt;




&lt;h2&gt;
  
  
  🧑‍💼 Context-Aware Legal Reasoning
&lt;/h2&gt;

&lt;p&gt;One of the most powerful features is employee-specific reasoning.&lt;br&gt;
For example:&lt;/p&gt;

&lt;p&gt;“Is this employee eligible for 30 days of annual leave if he has worked for 6 years?”&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;




&lt;h2&gt;
  
  
  🖥️ Streamlit Interface
&lt;/h2&gt;

&lt;p&gt;The frontend is built with Streamlit to make the experience intuitive and user-friendly:&lt;/p&gt;

&lt;p&gt;🌍 Auto-detect Arabic or English queries.&lt;/p&gt;

&lt;p&gt;📄 Optional employee data input.&lt;/p&gt;

&lt;p&gt;🔍 Expandable references with similarity scores.&lt;/p&gt;

&lt;p&gt;📚 Source tracing from Part → Chapter → Article.&lt;/p&gt;




&lt;h2&gt;
  
  
  🚀 Example in Action
&lt;/h2&gt;

&lt;p&gt;Arabic Example:&lt;/p&gt;

&lt;p&gt;👤: ما هي مدة الإجازة السنوية بعد خمس سنوات من الخدمة؟&lt;br&gt;
🤖: يستحق العامل ثلاثين يوماً من الإجازة السنوية…&lt;br&gt;
📖: استنادًا إلى المادة التاسعة بعد المائة&lt;/p&gt;

&lt;p&gt;English Example:&lt;/p&gt;

&lt;p&gt;👤: What are the sick leave entitlements for an employee?&lt;br&gt;
🤖: The employee is entitled to paid sick leave for a specific duration…&lt;br&gt;
📖: Based on Article 117 – Chapter Four&lt;/p&gt;




&lt;h2&gt;
  
  
  🧭 What’s Next
&lt;/h2&gt;

&lt;p&gt;The project is just getting started. Planned enhancements include:&lt;/p&gt;

&lt;p&gt;📑 PDF export of Q&amp;amp;A with references&lt;/p&gt;

&lt;p&gt;🧮 HR calculators (end-of-service, overtime, vacation accrual)&lt;/p&gt;

&lt;p&gt;🔊 Arabic voice interaction&lt;/p&gt;

&lt;p&gt;📊 HR analytics dashboard&lt;/p&gt;

&lt;p&gt;🧰 Tech Stack&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Component&lt;/th&gt;
&lt;th&gt;Technology&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Frontend&lt;/td&gt;
&lt;td&gt;Streamlit&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;LLM&lt;/td&gt;
&lt;td&gt;GPT-4o-mini&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Embeddings&lt;/td&gt;
&lt;td&gt;intfloat/multilingual-e5-base&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Vector DB&lt;/td&gt;
&lt;td&gt;Qdrant&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Retrieval&lt;/td&gt;
&lt;td&gt;LlamaIndex&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Translation&lt;/td&gt;
&lt;td&gt;Helsinki-NLP/opus-mt-ar-en&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Parsing&lt;/td&gt;
&lt;td&gt;PyMuPDF (fitz)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;💡 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.&lt;/p&gt;

&lt;p&gt;🔗 Explore the Project&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/zainalabdeen/llm-zoomcamp/tree/main/hr_assistant" rel="noopener noreferrer"&gt;👉 GitHub Repository&lt;/a&gt;&lt;br&gt;
I build This Project as Final Project Of learning &lt;a href="https://github.com/DataTalksClub/llm-zoomcamp" rel="noopener noreferrer"&gt;LLm-ZoomCamp Course&lt;/a&gt;&lt;/p&gt;

</description>
      <category>rag</category>
      <category>ai</category>
      <category>llm</category>
      <category>showdev</category>
    </item>
  </channel>
</rss>
