Building Badi: Autonomous Flood Route Intelligence Powered by FalkorDB

  

How we built a graph-grounded multi-agent triage system for mountain disasters using FalkorDB, live Cypher queries, and persistent episodic memory.

Author: Saugat Adhikari

Hackathon: WeMakeDevs × FalkorDB "Graph Hacks: Context for AI Agents"

Target Tracks: Track 01 (Agents That Act on Connected Data) & Track 02 (Agent Memory and Coordination)

Reading Time: 7 minutes

1. Introduction: The Mountain Disaster Problem

During monsoon season in Nepal, mountain roads wash out rapidly. Debris flows destroy concrete bridges. Flash floods sever entire valleys from district hospitals.

In September 2024, severe floods struck the Trishuli River basin in Rasuwa District. The Humanitarian OpenStreetMap Team (HOTOSM) and NDRRMA recorded:

  • 39 washed-out bridges.

  • 4 severely damaged bridges.

  • 2,886 damaged buildings.

Relief teams faced three urgent questions:

  1. Which roads to the district hospital are physically safe right now?

  2. If this single bridge fails, which downstream villages lose their only lifeline?

  3. Which road inspection mission should our scouts prioritize next?

Traditional relational databases and flat vector embeddings cannot answer these questions.

2. Why Standard Databases and Vector RAG Fail

Relational SQL tables store rows. Vector databases store text embeddings. Neither understands physical network topology.

The Limits of SQL

To find an alternate hospital route in SQL, a system must perform recursive table joins across uncertain road segments. When landslides cut multiple roads, multi-hop SQL joins become slow and brittle. Relational databases cannot calculate cut-edge bottlenecks or graph centrality in real time.

The Limits of Vector RAG

Vector embeddings calculate semantic similarity. They do not calculate spatial connectivity. An LLM using semantic search might retrieve road names, but it cannot verify if a 5-hop path has a broken bridge on hop 3. It will hallucinate routes that do not physically connect.

The Core Epistemic Safety Rule

In disaster operations, we enforce a strict rule:

An unobserved road is never assumed safe.

A road segment begins with the status unknown. It only becomes verified_passable when a field scout physically inspects the terrain. Standard databases cannot enforce this state machine across connected paths.

3. The Solution: FalkorDB Connected Graph Architecture

We built Badi (बाढी). Badi is an autonomous disaster response agent powered entirely by FalkorDB.

FalkorDB stores the entire mountain corridor as a connected graph. Every hospital, road segment, bridge, scout observation, and triage decision exists as a node in the graph.

graph LR
Loc[Location: Settlement] -->|ROAD_TO| Loc2[Location: Regional Hub]
Fac[Facility: Hospital] -->|AT_LOCATION| Loc2
Road[RoadSegment] -->|CONNECTS| Loc
Road -->|INCLUDES_BRIDGE| Brg[Bridge]
Road -->|HAS_OBSERVATION| Obs[Observation]
Obs -->|FROM_SOURCE| Src[Source: Scout / NDRRMA]
Msn[Mission: Recon] -->|INVESTIGATES| Road
Mem[EpisodicMemory] -->|AFFECTED_ROAD| Road



Graph Nodes and Properties

Node Label

Core Properties

Operational Role

:Location

id, name, households, type

Settlements, road junctions, and regional hubs.

:Facility

id, name, type, importance_weight

District hospitals and health posts.

:RoadSegment

id, name, status, length_km

Physical road corridors (verified_passable, unknown, blocked, disputed).

:Bridge

id, name, status, damage_assessment

River crossings with surveyed structural damage.

:Observation

id, status, note, timestamp

Field reports submitted by ground units.

:Mission

id, priority_score, priority_level

Prioritized scout inspection assignments.

:EpisodicMemory

id, session_id, event_type, summary

Cross-session agent coordination events.



FalkorDB is the sole database engine. Badi uses zero SQLite fallbacks and zero mock in-memory dictionaries. If FalkorDB stops, the system fails closed with HTTP 503.

4. Track 01: Agents That Act on Connected Data

Badi does not pass static text dumps to an LLM. Badi translates user intent into live Cypher queries executed directly against FalkorDB.

Live Path Search with Epistemic Rules

When an operator asks: "Can an ambulance reach Trishuli Hospital from Syabrubesi?", Badi executes this live Cypher query:

MATCH p = (s:Location {id: 'loc_syabrubesi'})-[:ROAD_TO*1..7]->(hub:Location)
MATCH (f:Facility)-[:AT_LOCATION]->(hub)
WHERE ALL(rel IN relationships(p) WHERE rel.status = 'verified_passable')
AND ALL(n IN nodes(p) WHERE 1 = size([m IN nodes(p) WHERE m = n]))
RETURN p, f.id AS facility_id, f.name AS facility_name, f.importance_weight AS facility_weight
ORDER BY length(p) ASC



If any single segment along path p has status unknown, blocked, or disputed, the query excludes that path.

If no fully verified path exists, Badi executes a secondary query to find potential paths:

MATCH p = (s:Location {id: 'loc_syabrubesi'})-[:ROAD_TO*1..7]->(hub:Location)
MATCH (f:Facility)-[:AT_LOCATION]->(hub)
WHERE NONE(rel IN relationships(p) WHERE rel.status = 'blocked')
AND ANY(rel IN relationships(p) WHERE rel.status IN ['unknown', 'disputed'])
AND ALL(n IN nodes(p) WHERE 1 = size([m IN nodes(p) WHERE m = n]))
RETURN p, f.id AS facility_id, f.name AS facility_name
ORDER BY length(p) ASC



If potential paths exist, Badi returns access state NEEDS_RECON. It identifies the exact unverified segments that scouts must inspect.

The Live Cypher Evidence Drawer

Every response generated by Badi includes the exact Cypher query executed, the database latency, and the graph evidence chain.

Operators click the Inspector tab in the UI to view:

  • Downstream settlements at risk.

  • Surveyed bridge damage along the road.

  • The observation timeline from NDRRMA and field scouts.

  • The raw Cypher query with a one-click copy button.

Judges and operators inspect the mathematical proof behind every answer.

5. Cut-Edge Centrality and Dynamic Landslide Re-Ranking

A primary challenge in disaster triage is calculating bottlenecks. If a road fails, how many communities lose their only hospital route?

In graph theory, this is known as a bridge or cut-edge.

Calculating Blast Radius with Cypher

When evaluating road road_syabru_dhunche (Pasang Lhamu Highway), Badi runs a blast-radius Cypher query:

MATCH p = (s:Location {type: 'settlement'})-[:ROAD_TO*1..7]->(hub:Location)
MATCH (f:Facility)-[:AT_LOCATION]->(hub)
WHERE NONE(rel IN relationships(p) WHERE rel.status = 'blocked')
AND ANY(rel IN relationships(p) WHERE rel.road_id = 'road_syabru_dhunche')
AND ALL(n IN nodes(p) WHERE 1 = size([m IN nodes(p) WHERE m = n]))
RETURN DISTINCT s.id AS settlement_id, s.name AS settlement_name, s.households AS households
ORDER BY s.households DESC



The query reveals that four northern settlements (Syabrubesi, Gatlang, Goljung, and Chilime) depend on this single road corridor.

Dynamic Landslide Adaptation

When an operator clicks Simulate Landslide in the dashboard:

  1. FalkorDB sets road_syabru_dhunche.status = 'blocked'.

  2. Badi re-runs cut-edge centrality calculations across the entire corridor.

  3. Scout reconnaissance missions re-rank dynamically in the Missions queue.

Missions protecting the largest isolated populations automatically receive priority label LIFELINE. Reconnaissance units deploy where the humanitarian need is greatest.

6. Track 02: Agent Memory and Cross-Session Coordination

Disaster response requires multiple agents and operators working across shifts. Field reports filed at 08:00 must guide evacuation decisions made at 16:00.

Badi solves this with persistent Episodic Memory nodes in FalkorDB.

Resolving Disputed Field Reports

Conflicting reports frequently emerge from disaster zones. A news agency reports a road blocked; a local driver claims it is open.

Badi implements an epistemic consensus machine:

  • Conflicting reports set road status to disputed.

  • A ground scout unit files an observation with override = true.

  • FalkorDB resolves the status to verified_passable.

Storing Memory Nodes in FalkorDB

Every major triage event creates an (:EpisodicMemory) node directly in the graph:

MATCH (r:RoadSegment {id: $road_id})
CREATE (m:EpisodicMemory {
id: $memory_id,
session_id: $session_id,
agent_role: $agent_role,
event_type: 'SCOUT_OVERRIDE_VERIFICATION',
summary: $summary,
details: $details,
timestamp: $timestamp
})
CREATE (m)-[:AFFECTED_ROAD]->(r)
RETURN m



Recalling Context Across Sessions

When an agent begins a new conversation session, it queries FalkorDB to reconstruct operational history:

MATCH (m:EpisodicMemory)-[:AFFECTED_ROAD]->(r:RoadSegment)
WHERE m.session_id = $session_id OR $session_id = 'all'
RETURN m.id, m.agent_role, m.event_type, m.summary, r.name, m.timestamp
ORDER BY m.timestamp DESC
LIMIT 10



The agent does not lose context when the user refreshes their browser or switches devices. Memory lives in FalkorDB, not in temporary application memory.

7. Model Context Protocol (MCP) Server

To coordinate with external AI agents, Badi provides a Model Context Protocol (MCP) server in backend/mcp_server.py.

The MCP server exposes 9 graph tools:

  1. get_settlement_safety_status: Checks verified hospital routes for any village.

  2. find_evacuation_or_supply_route: Finds shortest passable paths between two locations.

  3. analyze_road_impact: Calculates blast radius and isolated communities.

  4. record_field_observation: Ingests field reports with optional scout override.

  5. get_active_recon_missions: Returns dynamically ranked inspection missions.

  6. get_bridge_damage_assessments: Reads surveyed structural bridge assessments.

  7. get_episodic_coordination_timeline: Fetches cross-session memory events.

  8. get_network_health_summary: Returns real-time KPI metrics.

  9. get_live_cypher_evidence: Inspects executed Cypher statements and execution times.

External Claude, Gemini, or custom autonomous agents can connect to Badi via MCP and interact with the live graph.

8. Automated Testing and Verification

To ensure disaster reliability, Badi includes 34 automated pytest tests:

  • Path search algorithms (verified, potential, isolated).

  • Blast radius detection and household calculations.

  • Epistemic rules (unobserved roads never default to safe).

  • Consensus resolution via scout overrides.

  • Landslide simulation and dynamic mission re-ranking.

  • Session-scoped episodic memory persistence.

  • FalkorDB dependency validation (HTTP 503 upon database disconnect).

All 34 tests pass consistently.

9. How to Run Badi Locally

You can run Badi on your computer in under five minutes.

Prerequisites

  • Docker and Docker Compose installed.

  • Python 3.10+ (Python 3.12 recommended).

  • Git.

Step 1: Clone Repository & Start FalkorDB

git clone https://github.com/saugatadk/Badi.git
cd Badi
docker compose up -d



Step 2: Set Up Python Environment

python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt



Step 3: Seed Database & Run Server

# Seed the Trishuli flood corridor graph
python -m scripts.seed_falkordb

# Start the FastAPI application
uvicorn backend.main:app --reload --port 8000



Step 4: Open Dashboard

  • Open http://localhost:8000 to launch the interactive dashboard.

  • Open http://localhost:3000 to inspect raw nodes in the FalkorDB Browser.

10. Conclusion: Why Connected Data Wins

Disaster route intelligence is not a text search problem. It is a connected graph problem.

When lives depend on finding an open route to emergency healthcare, AI agents cannot rely on hallucinations or static tables.

By grounding agent reasoning in FalkorDB:

  • Badi verifies multi-hop physical paths with live Cypher queries.

  • Badi detects cut-edge bottlenecks before ambulances deploy.

  • Badi re-ranks reconnaissance missions dynamically when landslides strike.

  • Badi remembers decisions and field observations across sessions.

FalkorDB provides the deterministic, high-speed context graph that AI agents need to operate safely in the physical world.

Resources & Links

  • GitHub Repository: github.com/saugatadk/Badi

  • FalkorDB Official Site: falkordb.com

  • Data Attribution: Humanitarian OpenStreetMap Team (HOTOSM) & Nepal NDRRMA Open Data.

Comments