a RAG system tailored for algerian law/decree files using LlamaIndex.
# Local RAG for Algerian Law
## Overview
This project provides a fully localized Retrieval-Augmented Generation (RAG) system dedicated to querying Algerian legal documents. The entire architecture is designed to run completely offline on a local machine, ensuring maximum privacy and data control. It utilizes local Large Language Models (LLMs) and Vision-Language Models (VLMs) via Ollama, along with local embedding models and a local vector database. No external APIs or cloud services are required.
## Pre-Processing and Parsing
The first crucial step in the pipeline involves converting raw, scanned PDF legal documents into clean, structured Markdown format. This extraction process relies on a powerful local Vision-Language Model to intelligently parse text while maintaining original document formatting and layouts.
```mermaid
graph TD
A[Raw PDF Legal Documents] --> B[PDF to Image Rendering]
B -->|pdf2image & Poppler| C[High-Resolution Images]
C --> D{Local VLM Processing}
D -->|System Prompt: Preserve Structure| E[qwen2.5vl:7b via Ollama]
D -->|Fallback/Other Models| F[Alternative VLMs]
E --> G[Text Extraction & Formatting]
F --> G
G -->|Clean Structured Markdown| H[Parsed Data Directory]
H -->|Feeds Into| I(Ingestion Pipeline)
```
1. **PDF Rendering**: We use Poppler and `pdf2image` to reliably convert each PDF page into high-quality images.
2. **VLM Extraction**: The images are sent to a local Ollama instance running a Vision-Language Model (`qwen2.5vl:7b`). A specialized system prompt instructs the model to preserve all headers (Books, Chapters, Articles), structural lists, and tables without hallucinating any external information or translating any text.
3. **Structured Markdown**: The clean markdown output is seamlessly saved into the `Parsed Data` directory, perfectly maintaining the original document's hierarchical integrity (e.g., keeping article numbers as bold headings and preserving legal formatting).
## Ingestion Pipeline
Once the legal texts are p …