Skip to main content

Phase 6 — NIM / Earth-2 Inference

Duration: ~7 working days Critical-path predecessor: Phase 3 Status: in progress

Deliverables (§5.5 / §5.7 / §11)

  1. Production FourCastNet + CorrDiff client with Redis cache and R2 persistence
  2. Vision NIM — SAM-2 (segment_glof_inundation) and OWL-ViT (detect_avalanche_debris)
  3. Scientific RAG corpus — pgvector store of IPCC / ICIMOD / NDMA / forensic
  4. Multilingual narrator — Llama-3.1 70B via NIM, EN / HI / UR / DOI / PAH
  5. CAP 1.2 bulletin generator — OASIS-compliant XML for NDMA / SDMA feeds
  6. Hardened Netlify edge proxy — origin allow-list + per-IP rate limit
  7. 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

LayerModuleResponsibility
Forecastnim/forecast/earth2_production.pyFCN + CorrDiff with cache, retries, synthetic fallback
Visionnim/vision/segmentation.pySAM-2 + OWL-ViT prompted segmentation
RAGnim/rag/corpus.pyChunking, embedding, pgvector search
Narratornim/narrator/llm_narrator.pyLlama-3.1 multilingual bulletin generation
CAPnim/cap/bulletin.pyOASIS CAP-1.2 XML serialiser
Edgenetlify/edge-functions/nim-proxy.tsServer-side key handling + rate limit
APIapi/nim_routes.pyFastAPI router for all NIM operations
UIcomponents/narrator/NarratorPanel.tsxPer-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_at request would not collide.