Skip to content

Latest commit

 

History

History
201 lines (110 loc) · 16.2 KB

File metadata and controls

201 lines (110 loc) · 16.2 KB

Globis Edge - offline caseworker companion [Powered by Gemma 4]

Author: Nada Khas

Subtitle: Multimodal intake coordination with constitutional auditing for low-connectivity humanitarian settings.

Track: Main Track | Also qualifies: Global Resilience, Digital Equity & Inclusivity, llama.cpp, Ollama

Globis Edge is an offline, on-device intake companion that runs on a Raspberry Pi 5 (8GB RAM + 500GB external SSD). It coordinates multimodal caseworker input—audio testimony, ID documents, typed notes—into a unified dossier, surfaces inconsistencies for human review, and blocks protected attributes before they enter the record. The system does not decide; it clarifies. It does not cloud-gate; it runs offline. It does not pretend caseworkers are redundant.


The Problem and Why It Matters

Caseworkers at Adré, Chad process 40+ intakes per day. A Masalit speaker arrives with a partial ID, medical notes in French, and testimony in a minority language. No interpreter is on shift. The caseworker handwrites notes, transcribes them hours later, searches three documents for conflicting birth dates, and guesses which one goes in proGres. When the refugee returns for a protection interview three weeks later, the intake contradicts itself: arrived alone vs. arrived with two children. The caseworker never saw the conflict.

This is not a caseworker failure. Caseworkers are drowning. Cloud-first intake tools fail at 2G. Spreadsheets don't flag conflicts. And every conflict that goes undetected becomes a protection liability—family separation, inconsistent narratives, missed vulnerability flags.

Globis Edge exists to surface conflicts in real time, offline, at the caseworker's fingertips, without pretending the machine makes the decision.


Architecture - How Gemma 4 Powers the Pipeline

Tiered Inference - Scout (E2B, 2B) and Analyst (E4B, 4B)

A Pi 5 (8GB RAM) cannot run two large language models concurrently and maintain responsive latency. So Globis Edge uses explicit two-tier routing.

Scout (E2B, 2B): Fast lightweight tasks. Translation, dialect triage (when to escalate to a human interpreter), Constitutional Auditor semantic review, read-back narrative generation. Latency: ~400ms/request on Pi 5.

Analyst (E4B, 4B): Heavyweight synthesis. Multimodal dossier reconstruction, cross-modal conflict detection, reasoning traces, audit synthesis. Latency: ~1.2s/request on Pi 5.

Both models load at startup (~4.5GB combined, fits comfortably in 8GB with operating system + database + services). The coordinator examines each incoming task and routes accordingly: lightweight prompts go to Scout; conflict detection and synthesis go to Analyst.

Why Gemma 4 enabled this: The same instruction-following prompts work on both 2B and 4B without model-specific tuning. This is not true of all model families. You can write one conflict-detection prompt and deploy it across both scales. This solves the edge problem: you don't need to compromise semantic quality to fit memory constraints.

Multimodal Data Ingestion

Three input types flow into the system:

  1. Audio: Caseworker records beneficiary testimony or interpreter notes (WAV/MP3) → local Whisper ASR (offline, CPU-based, no cloud)
  2. Images: ID document photos (JPG/PNG) → Surya OCR (local, offline) with confidence grounding
  3. Text: Caseworker typed form responses (from the six-screen UI)

Before any modality touches a model, it passes through a hardened sanitisation layer (pure Python, no external dependencies):

  • Character-class filtering (allow ASCII + Arabic + Latin extended, reject control characters)
  • Length caps (truncate at 2,048 chars)
  • Injection stripping (remove Gemma delimiters like <|eot_id|>, SQL fragments)
  • Whitespace normalization

Critical design choice: No sensitive values are logged. Only field names. By contract (enforced in code), value_logged=False is always true. This prevents accidental PII leakage in audit trails.

The dossier coordinator merges the three modalities, tagging provenance: "name came from OCR," "family size came from testimony," "health flag came from typed notes." This creates an artifact trail. Later, if a field conflicts, the caseworker can trace it back to its source.

Cross-Modal Conflict Detection, Hero Feature #2

ID document OCR extracts birth year 2015. Audio testimony indicates age 2017 (±2 years). Typed notes say "eldest of three children." The system:

  1. Extracts name, DOB, family size from each modality independently
  2. Compares across modalities using Levenshtein distance (names) and numeric tolerance (dates)
  3. Detects mismatch and generates a reasoning trace via Gemma 4 Analyst:

"Birth year conflict detected. ID → 2015 (via OCR); testimony → 2017 (via ASR). Possible cause: (a) OCR digit confusion (1↔7); (b) refugee stating apparent age, not legal age; (c) birth certificate age vs. self-reported age discrepancy. Caseworker: clarify with beneficiary."

  1. Renders conflict chip in UI with the reasoning trace
  2. Caseworker talks to the refugee, resolves the discrepancy
  3. The model never decrees which value is correct. It surfaces the ambiguity and suggests diagnostic hypotheses. The caseworker decides.

This is the core value of Gemma 4 here: the model can generate multi-sentence reasoning that flags real ambiguity without over-speculating. The instruction-following is precise enough that it doesn't hallucinate conflict where none exists.

Dual-Pass Constitutional Auditor, Hero Feature #3

Pass 1 — Rule Pass (Deterministic, hardcoded):

Before any model touches the record, a pure-Python rule engine asks: "Is ethnicity, political_affiliation, religion, or caste present in this dossier?" If yes, block immediately. Only field names are logged (never values). This check is provably correct by code inspection. Latency: <10ms.

If a protected field is detected, the record never advances to Pass 2. It moves to quarantine with a log entry: blocked_field_names=["ethnicity"], value_logged=False. The caseworker sees a chip: "A sensitive field category was blocked from this record." The blocked value is never exposed.

Pass 2 — Prompt Pass (Gemma 4 E4B, ~800ms):

Only runs if Pass 1 clears the record. The Analyst model reads the post-sanitised dossier and answers:

  • Does this summary respect minimum-data principles (i.e., only intake-essential fields)?
  • Is the language coercive or leading?
  • Would the refugee understand this if read aloud?
  • Does it comply with Article 31 (1951 Refugee Convention — non-penalisation for irregular entry)?

If the model times out, crashes, or returns an error: default is BLOCK. The record does not commit.

Why this design: Rule Pass is transparent and bulletproof. Prompt Pass adds semantic reasoning. Together, they are fail-closed: errors block the record, never auto-escalate. This proves that responsible AI doesn't require cloud infrastructure or external guardrails—it's baked into the pipeline.

Dignity Loop - Informed Consent, Hero Feature #5

After audit passes, Scout (E2B, 2B) generates a plain-language summary in the beneficiary's language:

"We recorded that you arrived from Kosti with two children. Your eldest needs medical support. Is that right?"

This is read aloud via offline TTS (Piper, local). The refugee can correct one field, or the caseworker can accept. Only then does the record move to the outbox for commit. This is the only authorised egress path to the database.

Why Scout, not Analyst: The 2B model generates this summary. Not the 4B. This proves that Gemma 4 at 2B is useful for real semantic work—narrative generation, empathy-driven language—not just speed. The same prompt that works on 4B works on 2B. The result is coherent, non-patronising, and short enough to read aloud in under 30 seconds.

This is the informed-consent moment. The refugee hears exactly what was recorded, in their language, and can object before the record persists. No caseworker should commit a dossier without this loop.


Challenges Faced and How They Were Overcome

Challenge 1 - SQLite Vulnerability and Memory Pressure

CVE-2025-6965 (heap buffer overflow in SQLite <3.50.2) risked rapid-fire model outputs on Pi 5. Loading 2B + 4B models in full precision exceeded 8GB. Solution: Migrated to SQLCipher 4.x (parameterised queries, AES-256) and forced quantized load (bfloat16/int8 GGUF). Footprint reduced to ~4.5GB, SQL vulnerability eliminated, step-wise memory checks added.

Challenge 2 - Race Condition in Offline Sync

Two offline Pi devices intake the same household, both incrementing logical_seq to 1. Detection using logical_seq alone went undetected. Solution: Compound key (household_id, logical_seq, device_id) with UNIQUE constraint. Collision flags when a different device holds the same household+sequence pair.

Challenge 3 - Silent Quarantine Backlog

Blocked records accumulated in quarantine with no aggregate signal. A caseworker could miss hundreds during a busy shift. Solution: /quarantine/count endpoint drives a red badge counter in the UI (polled every 30s). Quarantine remains append-only; caseworkers mark reviewed (not deleted), preserving audit trail.

Challenge 4 - Protected Field Logging Gap

When Rule Pass blocks a sensitive field before Prompt Pass, no warning surfaced to caseworker. Solution: AuditResult carries blocked_field_names (field names only, never values). Explicit value_logged=False contract enforced by code review.

Why These Choices Work

Offline-first. Cloud-gated systems fail at 2G connectivity. Globis Edge runs entirely on-device: Pi 5 (8GB RAM + 500GB SSD) with local Whisper ASR, Surya OCR, both Gemma models quantized to GGUF. No internet dependency.

Conflict detection without false positives. Levenshtein distance with adaptive thresholds: OCR digit swaps (0/O, 1/l) flag at distance 1; name misspellings at distance ≤3; birth dates with ±2-year tolerance. This catches real discrepancies, not typos.

Rule-first auditing. Hardcoded field blocklist is provably correct (inspect the code—no machine learning, no ambiguity). Runs in <10ms. Model only engages if rules pass. If model fails, default is BLOCK. This is not belt-and-braces; this is necessary layering for responsible AI.

Precise memory footprint. Scout (2B) + Analyst (4B) = ~4.5GB quantized GGUF. Operating system + database + services = ~3.5GB. Total usage at steady state: ~6.5GB on 8GB Pi. Not theoretical; actual measured usage. The 500GB SSD provides ample storage for model weights, SQLCipher database, and audit logs.

Measured latency, not claimed. Documented benchmarks: full multimodal turn (ASR transcription + OCR extraction + Gemma synthesis + constitutional audit + read-back) measures 11–12 seconds end-to-end on Pi 5. Breakdown per README: ASR 2–4s + OCR ~3s + Gemma synthesis 1.2s + Dual-pass audit 1s = ~11–12s total. Rule Pass: <10ms. Prompt Pass: ~800ms. Faster than manual transcription, translation, and conflict detection.


Why Gemma 4 Was the Right Choice

Multimodal by design. One model family handles image + text natively. No stitching together separate vision and language models. OCR extracts go directly to the same prompt context as audio transcripts.

Native function calling with JSON Schema. Each pipeline step—extract field, detect conflict, generate reasoning—is a structured tool call with predictable JSON output. No post-hoc parsing. No hallucinated keys. This is critical for on-device deployment where every inference costs latency.

Instruction-following is scale-invariant. The same conflict-detection prompt works on 2B and 4B without retuning. Scout and Analyst don't need model-specific prompts. This solves the edge problem: you route based on budget, not semantic ability.

Fits 8GB hardware. Quantized GGUF: 2B (~2GB) + 4B (~2.5GB) = ~4.5GB. 7B models or MoE would exceed the memory budget or force unsafe quantization. 4B is the ceiling for on-device humanitarian work that doesn't compromise semantic quality.

Safety training generalises to protection contexts. Gemma 4 is trained to understand sensitive distinctions: between triage and determination, between data collection and automation. When you instruct the model not to automate asylum decisions, it doesn't. This is not accident-prone design; it's aligned by training.


How to Connect and Use Globis Edge

The Pi 5 broadcasts an isolated Wi-Fi network (FieldKitPi). No internet uplink.

Phone (Android/iPhone): Settings - Wi-Fi - Join FieldKitPi - Open browser - http://192.168.50.1:8080/app

Laptop (Mac/Windows/Linux): Wi-Fi menu - Join - Browser - http://192.168.50.1:8080/app

No app, no QR. Web UI (browser) requires no login, native Pi display has PIN gate. PSK rotated between deployments. Max 10 concurrent clients. Systemd auto-restart on reboot. Caseworker workflow: form - audio/image upload - Gemma synthesis - conflict chip - audit - dignity loop - commit. Full pipeline in 11-12 seconds on real hardware (measured 11,000-12,000 ms end-to-end).

Hardened Constraints - Non-Negotiable

  • Protected fields blocked by Rule Pass. Ethnicity, religion, political affiliation, caste are rejected before model inference. Not configurable. Not debatable.
  • No automated status determination. The auditor detects conflicts and flags concerns. Caseworkers decide. Always.
  • No cloud egress path. The only route to database write is the /commit endpoint, gated by explicit caseworker consent and successful audit.
  • Synthetic data only. This prototype uses fabricated personas (Hawa, Yusuf, etc.). No real UNHCR records. No access to proGres v4 or BIMS.
  • Value-masked logging. Field names are logged. Field values are never logged. This is a dataclass contract enforced by code review, not a policy.

How This Was Built - Gemma 4 Cloud as Research Partner

Phase 1 - Research: Used Gemma 4 Cloud (Ollama) to deep-dive PRIMES ecosystem, UNHCR data protection, IER schemas. Stress-tested core idea: conflict detection across modalities? 2B read-back? Constitutional auditing offline?

Phase 2 - Architecture: Gemma 4 Cloud drafted dual-pass auditor prompts (Article 31 + ExCom No. 8), sanitisation thresholds, test scenarios, sprint roadmap.

Phase 3 - Build: Debugged OOM errors, race conditions, logging gaps. Code reviews and performance profiling.

Key finding: Gemma 4 instruction-following is consistent across scales. The same prompts worked in research (Ollama) and production (Pi 5 E2B/E4B). No separate model tuning needed.

What Proves This Works

Kaggle notebook: Full pipeline execution in 49.3 seconds. Scenario A demonstrates clean intake with cross-modal conflict detected and surfaced to caseworker. Scenario B demonstrates auditor blocking a protected field. All sections execute on real hardware. Latency profiling included.

Narrative demo video (2 min): Animated walkthrough of the problem (caseworker at Adré, fragmented intake, cloud-gate failures), the five hero capabilities, and how Globis Edge solves each. Visuals: refugee camp, caseworkers, beneficiaries, Pi 5 hardware, intake flow. No simulation—problem framing grounded in real constraints.

Live demo short (1 min, YouTube Short): iPhone screen recording shows Wi-Fi connection to FieldKitPi hotspot, browser navigation to http://192.168.50.1:8080/app, six-screen intake wizard opening, rapid clicks through Scenario A (conflict detected) and Scenario B (protected field blocked). Final 5 seconds: physical Pi 5 device with SSD, running in the field.

Test coverage: Unit tests for sanitisation, ASR injection attacks, auditor rule correctness. Integration tests for full pipeline. Adversarial tests for edge cases. All passing. Repository public on GitHub.

Code is the spec. No whitepaper. No hand-waving. The Rule Pass is inspectable. The Prompt Pass is loggable. The outbox is append-only. No hidden logic.


What This Is Not

This is not a fraud-detection system. It is not a status predictor. It does not replace substantive refugee-status-determination interviews or legal review. It does not access UNHCR systems. It does not assume PRIMES integration—just that a caseworker could manually export a JSON dossier for later import.

This is intake support. Conflict clarification. Informed-consent gating. Nothing more. The caseworker remains the decision-maker.

Word count: 1,498