A Python‑based Retrieval‑Augmented Generation (RAG) system that scrapes Saudi legal statutes, splits them into article‑level chunks, builds a FAISS index with OpenAI embeddings, and answers Arabic legal questions using the ALLaM‑7B‑Instruct model. The pipeline runs on an RTX 5070 Ti (FP16) and provides concise, citation‑backed answers.
Python
0
6 commits
updated Dec 8, 2025
A Python‑based Retrieval‑Augmented Generation (RAG) system that scrapes Saudi legal statutes, splits them into article‑level chunks, builds a FAISS index with OpenAI embeddings, and answers Arabic legal questions using the ALLaM‑7B‑Instruct model. The pipeline runs on an RTX 5070 Ti (FP16) and provides concise, citation‑backed answers.
build_faiss.py).segments/ folder and normalized (whitespace, punctuation) using custom Python utilities.(?m)^\s*المادة) splits the statutes into article‑level chunks, each saved as a JSON‑L line by generateJSONL.py.text‑embedding‑3‑large model and stored in a FAISS IndexFlatL2 via build_faiss.py.humain‑ai/ALLaM‑7B‑Instruct‑preview is loaded in FP16 (no bitsandbytes) on an RTX 5070 Ti GPU.rag_query.py retrieves the top‑5 most similar chunks, builds a prompt that treats those chunks as reference material, and generates the final answer.Legal professionals, students, or anyone needing quick access to Saudi statutes can get accurate, citation‑backed answers without manually searching through long documents.
python -m venv venv
.\venv\Scripts\activate
pip install -r requirements.txt
# or manually:
pip install faiss-cpu openai tqdm transformers torch sentencepiece protobuf
$env:OPENAI_API_KEY="sk-..."
humain-ai/ALLaM-7B-Instruct-preview automatically on first run.Place your raw statute .txt files in the segments/ directory. Run:
python generateJSONL.py
This creates chunks.jsonl with cleaned article chunks.
python build_faiss.py
Creates faiss_index.bin and metadata.jsonl.
python rag_query.py "ما هي شروط الشهادة في المحكمة؟"
The script retrieves the top‑5 relevant articles, feeds them to the LLM, and prints a concise answer.
pip install protobuf sentencepiece.build_faiss.py before querying.This project is provided for educational purposes. The ALLaM model is subject to its own license on Hugging Face.
Author: Abdalmalik alGhamdi Email: [email protected]
A Python‑based Retrieval‑Augmented Generation (RAG) system that scrapes Saudi legal statutes, splits them into article‑level chunks, builds a FAISS index with OpenAI embeddings, and answers Arabic legal questions using the ALLaM‑7B‑Instruct model. The pipeline runs on an RTX 5070 Ti (FP16) and provides concise, citation‑backed answers.
Python
0
6 commits
updated Dec 8, 2025
A Python‑based Retrieval‑Augmented Generation (RAG) system that scrapes Saudi legal statutes, splits them into article‑level chunks, builds a FAISS index with OpenAI embeddings, and answers Arabic legal questions using the ALLaM‑7B‑Instruct model. The pipeline runs on an RTX 5070 Ti (FP16) and provides concise, citation‑backed answers.
build_faiss.py).segments/ folder and normalized (whitespace, punctuation) using custom Python utilities.(?m)^\s*المادة) splits the statutes into article‑level chunks, each saved as a JSON‑L line by generateJSONL.py.text‑embedding‑3‑large model and stored in a FAISS IndexFlatL2 via build_faiss.py.humain‑ai/ALLaM‑7B‑Instruct‑preview is loaded in FP16 (no bitsandbytes) on an RTX 5070 Ti GPU.rag_query.py retrieves the top‑5 most similar chunks, builds a prompt that treats those chunks as reference material, and generates the final answer.Legal professionals, students, or anyone needing quick access to Saudi statutes can get accurate, citation‑backed answers without manually searching through long documents.
python -m venv venv
.\venv\Scripts\activate
pip install -r requirements.txt
# or manually:
pip install faiss-cpu openai tqdm transformers torch sentencepiece protobuf
$env:OPENAI_API_KEY="sk-..."
humain-ai/ALLaM-7B-Instruct-preview automatically on first run.Place your raw statute .txt files in the segments/ directory. Run:
python generateJSONL.py
This creates chunks.jsonl with cleaned article chunks.
python build_faiss.py
Creates faiss_index.bin and metadata.jsonl.
python rag_query.py "ما هي شروط الشهادة في المحكمة؟"
The script retrieves the top‑5 relevant articles, feeds them to the LLM, and prints a concise answer.
pip install protobuf sentencepiece.build_faiss.py before querying.This project is provided for educational purposes. The ALLaM model is subject to its own license on Hugging Face.
Author: Abdalmalik alGhamdi Email: [email protected]