Smart Legal Chatbot (RAG System)

Overview

Tired of flipping through endless legal documents or scrolling through outdated HR guidelines?


This smart legal chatbot is the solution: an AI-powered assistant trained on the official Saudi Labor Law, providing instant, accurate answers in both Arabic and English through a clean, user-friendly chat interface. Whether you’re an HR professional, legal advisor, or business owner, it empowers you to access reliable insights on contracts, vacation policies, termination rules, and more, all sourced from verified legal documents.

Developed as part of my AI engineering portfolio, this project demonstrates how Retrieval-Augmented Generation (RAG) combined with modern LLMs can be deployed online using tools like Groq API and FastAPI, delivering real-time, document-grounded responses through a fully interactive web interface.

While the live version is normally hosted with complete backend logic, the page offers a quick preview through two short GIFs showcasing how the chatbot works in both English and Arabic.

This project reflects what I build best: AI systems that are not only technically advanced, but also practical, accessible, and ready for real-world use.

Demos of the project

1. English Interaction Preview ⬅️

In this example, the chatbot responds to a typical HR-related question in English instantly retrieving the relevant clause from the Saudi Labor Law. The goal here is to show how business users, managers, or legal staff can get precise answers in seconds without reading through entire documents.

2. Arabic Interaction Preview ➡️

This second demo showcases the chatbot’s ability to understand and respond fluently in Arabic. It proves the system’s bilingual design and demonstrates how native Arabic speakers can interact with it just as smoothly, making it ideal for HR teams in Saudi-based companies.

Technical Explanation

For technical readers interested in the underlying architecture, the chatbot is built using a multilingual Retrieval-Augmented Generation (RAG) pipeline optimized for Arabic and English legal contexts. It processes a curated set of official Saudi Labor Law documents, which are parsed, semantically chunked, and embedded using a sentence-transformers model capable of high-performance bilingual encoding. These embeddings are stored in ChromaDB for efficient vector-based retrieval.

 

At query time, the user’s input is embedded and matched against the vector index to retrieve the most relevant context chunks. These chunks are then passed to the language model as part of a dynamically constructed prompt. The architecture supports two inference modes: local inference via Ollama using Mistral 7B, and cloud inference through Groq API, which significantly reduces response latency and removes the need for local compute during deployment.

 

The system is orchestrated using LangChain to manage the RAG pipeline, retrieval chain, and document context injection. All backend processes (including document loading, embedding, and vector storage)  are modularized, enabling the project to scale horizontally, integrate with other APIs, or be wrapped into a FastAPI backend if needed.

 

The frontend is built with Streamlit, chosen for its speed, minimalism, and clean session-based interaction model. It allows the chatbot to be deployed online with an interactive UI and multi-language support, ready for HR or legal team use with no installation required. The system architecture reflects real-world engineering concerns (modularity, clarity, localization, and deployability) and was designed for maintainability and extensibility, not just as a one-off prototype.

 

Innovative solutions
for business