RightsNavigator: Offline African Legal AI
Tagline: Democratizing African legal intelligence -- 100% offline, multilingual, and grounded on budget hardware.
Inspiration
Across Africa, Micro, Small, and Medium Enterprises (MSMEs), informal workers, and local business operators encounter immense friction when attempting to understand their legal protections and compliance obligations. Navigating labor rights, employment contracts, business registration laws, and corporate governance typically requires high-priced legal retainers that are out of reach for everyday citizens.
This justice gap is exacerbated by three systemic realities:
- Connectivity and High Data Costs: Most legal AI platforms are cloud-bound SaaS tools that fail in regions with intermittent electrical grids, poor connectivity, or prohibitive mobile data rates.
- The Language Barrier: Official statutory gazettes are written in dense, formal colonial legal registers (English/French), creating a barrier for native speakers of Swahili, Kinyarwanda, Yoruba, Hausa, Igbo, and other indigenous languages.
- Hardware Constraints: Community legal aid centers, rural paralegals, and small enterprise owners rely on budget, low-spec hardware (typically $\le 8\text{ GB RAM}$).
We built RightsNavigator to provide a privacy-first, on-device legal intelligence assistant that grounds statutory laws into clear, actionable guidance in local African languages -- requiring zero internet connectivity and running comfortably on low-resource machines.
What it does
RightsNavigator is an offline, multilingual legal AI assistant and corporate compliance advisor for African jurisdictions (including Kenya, Nigeria, and Rwanda).
Key capabilities include:
- Natural Situation-to-Law Translation: Users do not need to know legal terminology. They describe real-world situations in plain or mixed native languages (for example, "My boss dismissed me without notice after 2 years and refused to pay my final salary"), and RightsNavigator identifies the relevant legal domain, extracts the statutory issue, and provides actionable remedies.
- Grounded Legal Answers with Section Citations: Every piece of advice is explicitly grounded in indexed statutory legislation (such as Employment Act, Section 35(1) or Companies Act), eliminating unsubstantiated assertions.
- 100% Offline and Private: Operates entirely locally with zero external API calls, ensuring full confidentiality for sensitive commercial and workplace disputes.
- Dual User Interfaces:
- CustomTkinter Desktop Application: A native, zero-dependency desktop UI with sidebar jurisdiction filters, collapsible panels, and one-click session export.
- Streamlit Web Console: A browser-based interface with dynamic citation cards and real-time response generation.
- Model Context Protocol (MCP) Integration: Exposes standard stdio JSON-RPC tools (
query_legislation,index_new_document,list_available_jurisdictions) for local AI agents and IDEs.
How we built it
RightsNavigator is built around a low-latency, zero-cloud architecture engineered to operate under a strict memory ceiling:
$$\text{RAM}{\text{total}} = \underbrace{\text{RAM}{\text{LLM weights}}}{\sim 2.15\text{ GB}} + \underbrace{\text{RAM}{\text{Context buffer}}}{\sim 0.35\text{ GB}} + \underbrace{\text{RAM}{\text{SQLite BM25}}}_{\sim 0.14\text{ GB}} \approx \mathbf{2.64\text{ GB}} \ll 7.0\text{ GB}$$
1. Two-Stage Reasoning and Orchestration Pipeline (orchestration.py)
Rather than passing raw narrative user queries directly to retrieval, our orchestrator uses a two-stage reasoning pipeline:
- Stage 1 (Situation Extraction): The quantized LLM parses the narrative into structured intent: Jurisdiction, Legal Domain, Core Issue, and Urgency.
- Stage 2 (Grounded Retrieval and Generation): The extracted core issue is queried against our statutory index, and retrieved clauses are injected into a constrained prompt enforcing verbatim statutory citations.
2. Zero-Embedding SQLite BM25 Engine (rag_engine.py)
To avoid loading heavy vector embedding models into RAM, we engineered an in-process Okapi BM25 search index stored in SQLite (legal_kb.db).
The relevance score for query $Q = {q_1, q_2, \dots, q_n}$ against document chunk $D$ is calculated as:
$$\text{Score}(D, Q) = \sum_{i=1}^{n} \text{IDF}(q_i) \cdot \frac{f(q_i, D) \cdot (k_1 + 1)}{f(q_i, D) + k_1 \cdot \left(1 - b + b \cdot \frac{|D|}{\text{avgdl}}\right)}$$
where the Inverse Document Frequency ($\text{IDF}$) is computed across corpus size $N$:
$$\text{IDF}(q_i) = \ln\left(\frac{N - n(q_i) + 0.5}{n(q_i) + 0.5} + 1\right)$$
(Calibrated parameters: $k_1 = 1.5$, $b = 0.75$)
3. Multilingual Model Core and Quantization
We integrated Cohere's tiny-aya-global (3.35B) model, quantized to Q4_K_M via llama.cpp / llama-server. This model provides strong representations for African languages (Swahili, Yoruba, Hausa, Igbo, Zulu, Amharic, Kinyarwanda) while maintaining high inference speeds on multi-core consumer CPUs.
4. Synthetic Instruction Dataset Generator (build_dataset.py)
An automated heuristic pipeline parses raw statutory texts into multi-turn, structured Q&A instruction pairs formatted for QLoRA fine-tuning with PEFT and PyTorch.
Challenges we ran into
Eliminating Legal Hallucinations Without Cloud Safeguards:
Standard LLMs often generate plausible-sounding legal sections when unsure. We implemented strict BM25 score gating ($\text{Score} \ge \tau$). If no statutory chunk meets the threshold, the system returns a safe, explicit fallback rather than guessing.Operating Within Strict Hardware and RAM Limits:
Combining a vector database, embedding model runtime, and LLM easily exceeded $8\text{ GB RAM}$ in early tests. By replacing heavy vector stores with our pure SQLite BM25 implementation, we reduced total memory footprint to $2.64\text{ GB}$, preventing CPU throttling and disk paging on budget laptops.Inconsistent Legal PDF Formatting:
Raw statutory gazettes from different African governments varied widely in structure (scanned documents, inconsistent roman numerals, sub-clause nesting). We created custom heuristic splitters and clean tokenizers to ensure sections, subsections, and penalty schedules remain intact during chunking.
Accomplishments that we're proud of
- Ultra-Low Memory Footprint: Achieved a peak consumption of just $2.64\text{ GB RAM}$, allowing smooth execution on low-cost $4\text{ GB}$ and $8\text{ GB}$ RAM machines.
- True Multilingual African Coverage: Enabled native legal interpretation and QA across major African languages alongside English and French.
- Zero Data Leakage: Built a completely air-gapped system where all queries, documents, and corporate records stay on the user's physical machine.
- Full MCP Server Support: Delivered a standard Model Context Protocol interface allowing third-party AI agents and development environments to query offline African legislation.
- Zero-Configuration Bundling: Packaged one-click launcher scripts and automated corpus synchronization pipelines for immediate deployment.
What we learned
- Lexical Precision Outperforms Dense Vectors in Legal Search: Exact section citations, statutory terminology, and penalty figures are better captured by optimized BM25 indexing than dense embeddings -- with zero GPU memory overhead.
- Multilingual Tokenizer Pre-training is Essential: Using a model natively trained on African tokens (
tiny-aya-global) drastically reduced token fragmentation and improved comprehension of regional legal context. - Edge AI Can Bridge the Justice Gap: High-utility AI does not require multi-billion parameter cloud models; lightweight, quantized architectures combined with structured retrieval can deliver life-changing access to law.
What's next for RightsNavigator
- Broadening Jurisdictions: Adding statutory corpuses for Ghana, South Africa, Uganda, and the regional OHADA Uniform Acts (West/Central Africa).
- Offline Voice Interface (STT/TTS): Integrating an on-device multilingual Whisper model to support voice-driven legal queries for non-literate community members.
- Automated Contract and NDA Compliance Scanner: Enabling users to drop in employment contracts or leases for automated clause-by-clause statutory compliance auditing.
- Case Law and Judicial Precedent Indexing: Expanding the retrieval index to encompass high court rulings and industrial labor tribunal precedents.
Built With
- bm25
- cohere
- custom-tkinter
- edge-ai
- enterprise
- gguf
- legaltech
- llama.cpp
- machine-learning
- mcp-server
- multilingual
- natural-language-processing
- offline-first
- on-device-ai
- python
- rag
- sqlite
- streamlit
- tiny-aya