Phase 6 — NIM / Earth-2 Inference
Duration: ~7 working days Critical-path predecessor: Phase 3 Status: in progress
Deliverables (§5.5 / §5.7 / §11)
- Production FourCastNet + CorrDiff client with Redis cache and R2 persistence
- Vision NIM — SAM-2 (
segment_glof_inundation) and OWL-ViT (detect_avalanche_debris) - Scientific RAG corpus — pgvector store of IPCC / ICIMOD / NDMA / forensic
- Multilingual narrator — Llama-3.1 70B via NIM, EN / HI / UR / DOI / PAH
- CAP 1.2 bulletin generator — OASIS-compliant XML for NDMA / SDMA feeds
- Hardened Netlify edge proxy — origin allow-list + per-IP rate limit
- Frontend NarratorPanel integrated into the Provenance section
Acceptance Gate
Sub-2 s FourCastNet 6-h forecast latency; multilingual SMS auto-generation verified against IMD bulletin format.
Run:
cd snow-ir-backend
pytest tests/nim -v
uvicorn snow_ir.api.main:app --reload
# Cache-cold
time curl -s -X POST http://localhost:8000/nim/forecast/fcn \
-H "Content-Type: application/json" \
-d '{"lead_hours": 6}' | jq
# Cache-hot (should return < 50 ms server-side)
time curl -s -X POST http://localhost:8000/nim/forecast/fcn \
-H "Content-Type: application/json" \
-d '{"lead_hours": 6}' | jq
# Multilingual narrator
curl -s -X POST http://localhost:8000/nim/narrate \
-H "Content-Type: application/json" \
-d '{"language":"hi","assessment":{"hazard_class":"GLOF","sub_basin_id":"kishtwar","probability":0.62,"ci_low":0.55,"ci_high":0.69,"forecast_horizon_h":72,"severity":"warning"}}' | jq
Architecture
| Layer | Module | Responsibility |
|---|---|---|
| Forecast | nim/forecast/earth2_production.py | FCN + CorrDiff with cache, retries, synthetic fallback |
| Vision | nim/vision/segmentation.py | SAM-2 + OWL-ViT prompted segmentation |
| RAG | nim/rag/corpus.py | Chunking, embedding, pgvector search |
| Narrator | nim/narrator/llm_narrator.py | Llama-3.1 multilingual bulletin generation |
| CAP | nim/cap/bulletin.py | OASIS CAP-1.2 XML serialiser |
| Edge | netlify/edge-functions/nim-proxy.ts | Server-side key handling + rate limit |
| API | api/nim_routes.py | FastAPI router for all NIM operations |
| UI | components/narrator/NarratorPanel.tsx | Per-alert multilingual UI |
Discipline
- API key security: API key never reaches the browser. All
/api/nim/*calls are intercepted at the edge and signed server-side. - Deterministic fallback: Synthetic fallback is deterministic — same input → same payload hash → same bulletin text. Non-credentialed staging environments still produce every artefact.
- Length budgets: Bulletin length budgets are enforced in the system prompt and clipped at the response boundary in
narrator.py. - Validation: CAP XML is always validated against the schema in
tests/nim/test_cap.py. - Cache isolation: Earth-2 cache keys are bbox-pinned to the Chenab basin geometry, so a neighbour's identical
issued_atrequest would not collide.