An AI-powered legal assistant for Algerian law, using Retrieval-Augmented Generation (RAG) to provide accurate, context-aware answers from legal documents.
# KanounGPT
KanounGPT is an early retrieval-augmented generation (RAG) experiment for Algerian law. Its goal is to make issues of the *Journal officiel de la République algérienne* easier to search and, eventually, to question in natural language.
The repository currently covers the data pipeline: downloading Arabic editions of the official journal, extracting their text with OCR, preparing the documents, generating embeddings, and storing those embeddings in a FAISS index. The conversational answer-generation layer is not implemented yet, so this should be treated as a research prototype rather than a finished legal assistant.
## How it works
The pipeline is split into a few small scripts and notebooks:
1. `scrape.ipynb` downloads Arabic PDF issues from `joradp.dz` and stores them by year under `joradp/`.
2. `model.py` renders each PDF as images and runs Arabic Tesseract OCR. The resulting text files are written to `extracted_texts/`.
3. `remove_pages.py` removes the cover and table-of-contents material by keeping text from `Page 2` onward.
4. `add_info.py` adds the year and issue number inferred from filenames such as `A1995001.txt`.
5. `json_converter.py` can split OCR output into page-level JSON. `correct_json.py` is an optional Arabic correction experiment.
6. `rag.ipynb` embeds each complete text file with `all-MiniLM-L6-v2`, normalizes the vectors, and inserts them into a FAISS `IndexFlatIP`.
After normalization, inner-product search is equivalent to cosine similarity. `IndexFlatIP` was chosen because it is simple and exact: it does not require training and is a reasonable baseline for a corpus of this size. The tradeoff is that search time and memory use grow linearly with the number of documents.
The repository includes `vector_index_cosine.faiss`, a generated index with 384-dimensional vectors.
## Why these choices
- **The official journal as the source.** It gives the project a primary, authoritative corpus instead of relying on summaries or thir …