AWS Builder Center
Connecting the Dots: Building a Smart City Knowledge Graph | Part 4

Connecting the Dots: Building a Smart City Knowledge Graph | Part 4

What connects a city's roads, pipelines, sensors, and public facilities? Explore knowledge graphs, Amazon Neptune, and graph-based intelligence to uncover infrastructure relationships and investigate cascading urban risks.

Series: THE CITY THAT CAN FEEL: Building an Artificial Nervous System for Smart Cities Using AWS (7 articles)

  1. …
  2. 4
    Connecting the Dots: Building a Smart City Knowledge Graph | Part 4 This article

THE CITY THAT CAN FEEL | PART 04/07

Connecting the Dots: Building a Smart City Knowledge Graph Using AWS

1. Introduction: A city is more than a collection of buildings

Imagine a water-level sensor detects an unusual reading near a drainage network.
An anomaly detection model identifies the reading as unusual. An alert is generated.
But what happens next?
Which drainage network is connected to that location? Which roads are nearby? Are there public facilities in the surrounding area? Does the affected drainage system connect to another urban zone? Has a similar incident occurred before?
A conventional monitoring application might display the sensor reading and its location.
But understanding the relationships between infrastructure requires something more.
It requires a system that can connect information.
This is where knowledge graphs become interesting.
A knowledge graph represents real-world entities and the relationships between them. Instead of storing every infrastructure asset as an isolated record, we can model how those assets are connected.
Imagine a city where the system understands relationships such as:
  • A sensor monitors a drainage network.
  • A drainage network serves an urban zone.
  • A road passes through an urban zone.
  • A hospital is located near a road.
  • A maintenance team is responsible for a pipeline.
  • An incident affected a particular infrastructure asset.
These connections can help an intelligent application investigate potential impacts and provide more useful context.
In the previous episodes, we built the conceptual foundation:
  • Part 1: Introduced the artificial nervous system.
  • Part 2: Connected the city's sensor network.
  • Part 3: Explored machine learning-based anomaly detection.
Now, in Part 4, we introduce the relationship layer.
Our objective is to design a knowledge graph that helps an AI system understand how urban infrastructure is connected.

2. Why traditional databases are not always enough

Relational databases are excellent for storing structured information.
For example, a city might maintain separate tables for sensors, roads, buildings, and maintenance records.
Consider these simplified tables.

Sensor table

Sensor ID
Type
Zone
W001
Water level
Zone A
N002
Noise
Zone B
T003
Traffic
Zone A

Infrastructure table

Asset ID
Asset Type
Zone
D001
Drainage
Zone A
R001
Road
Zone A
H001
Hospital
Zone A

Relationship table

Source
Relationship
Target
W001
MONITORS
D001
D001
SERVES
Zone A
R001
LOCATED_IN
Zone A
H001
LOCATED_IN
Zone A
This approach works, but complex relationship queries can require multiple joins and careful query design.
Now imagine investigating a problem that involves ten types of infrastructure, multiple zones, historical incidents, and several levels of dependency.
The number of relationships can become difficult to manage.
A graph database is designed to represent highly connected data directly.
Instead of treating relationships as secondary information, it makes them a central part of the data model.

3. Understanding knowledge graphs

A knowledge graph has three fundamental building blocks.

A. Nodes

Nodes represent entities.
Examples:
  • Sensor
  • Road
  • Pipeline
  • Drainage network
  • Building
  • Hospital
  • Urban zone
  • Maintenance team
  • Incident

B. Edges

Edges represent relationships between entities.
Examples:
  • MONITORS
  • CONNECTS_TO
  • LOCATED_IN
  • MAINTAINED_BY
  • NEAR
  • AFFECTED_BY
  • SERVES

C. Properties

Properties describe the entities or relationships.
A sensor node might contain:
{
"sensor_id": "WATER_001",
"sensor_type": "water_level",
"zone": "ZONE_A",
"status": "ACTIVE"
}
A drainage network node might contain:
{
"asset_id": "DRAIN_001",
"asset_type": "drainage_network",
"zone": "ZONE_A",
"capacity": "illustrative_value"
}
A relationship could represent:
WATER_001 --MONITORS--> DRAIN_001
Together, these elements form a connected model of the city.
An important design principle is that relationships should be supported by authoritative infrastructure records, engineering documentation, verified geographic data, or clearly labeled assumptions.
AI should not invent connections simply because two assets are nearby.

4. Designing the Smart City Knowledge Graph

Let's create a hypothetical infrastructure model.
Suppose our city contains:
  • One water-level sensor
  • One drainage network
  • Two roads
  • One hospital
  • One urban zone
  • One maintenance team
We can model these as connected entities.

Example graph

HOSPITAL_001
|
NEAR
|
ROAD_001 ---- LOCATED_IN ---- ZONE_A
| |
CONNECTS_TO CONTAINS
| |
DRAIN_001 <--- SERVES --------+
|
MONITORED_BY
|
WATER_001
|
REPORTS
|
INCIDENT_001
This is a simplified conceptual example. In a production model, relationship direction and meaning should be defined consistently, and geographic proximity should be calculated from actual coordinates.

Suggested entity types

Entity
Important properties
Sensor
ID, type, location, status
Road
ID, name, road class, coordinates
Drainage network
ID, capacity, condition
Building
ID, type, coordinates
Urban zone
ID, boundary, classification
Incident
ID, timestamp, type, status
Maintenance team
ID, department, responsibility

Suggested relationship types

Relationship
Meaning
MONITORS
Sensor monitors an asset
CONNECTS_TO
One infrastructure asset connects to another
LOCATED_IN
Asset belongs to a geographic zone
MAINTAINED_BY
Asset has an assigned maintenance team
NEAR
Two assets are geographically close
AFFECTED_BY
Asset was affected by a verified incident
SERVES
Infrastructure provides a service to an area
The relationship model should be developed with domain experts and validated against reliable infrastructure records.

5. Proposed AWS architecture: Introducing Amazon Neptune

Now let's explore how we can implement this graph layer using AWS.

Amazon Neptune

Amazon Neptune is a managed graph database service designed for applications that work with highly connected datasets.
It supports property graph models and RDF data models.
For property graphs, developers can use:
  • openCypher
  • Apache TinkerPop Gremlin
For RDF data, Neptune supports SPARQL.
For our initial smart city prototype, a property graph with openCypher is a practical option to explore because its syntax is approachable for developers familiar with SQL-like queries.

Proposed architecture components

Amazon S3
Stores infrastructure records, source files, historical incidents, and prepared graph import datasets.
AWS Lambda
Transforms validated infrastructure records into graph operations or ingestion batches.
Amazon Neptune Database
Stores the connected city infrastructure graph and supports graph queries.
Amazon Neptune Analytics
Can be evaluated when graph analytics workloads require large-scale graph algorithms, pathfinding, centrality, and related analysis.
Amazon Bedrock
Can help convert an operator's natural-language question into a structured query workflow and summarize verified graph results.
Amazon CloudWatch
Monitors application and service operations.
Important distinction: Neptune Database and Neptune Analytics are different offerings with different roles. Neptune Database is suited to persistent graph database workloads. Neptune Analytics is designed for graph analytics and graph algorithm workloads. They should not be treated as interchangeable components.
Figure 1: Proposed AWS Architecture for Building a Smart City Knowledge Graph using Amazon Neptune.
Explain the data flow from sensor ingestion to graph analysis and human review.


6. Practical implementation: Creating a small city knowledge graph using Python

Before connecting to AWS, let's build a small local prototype.
We will use NetworkX to represent infrastructure entities and relationships.
This helps us understand the graph model without provisioning a managed graph database.

Step 1: Install NetworkX

pip install networkx matplotlib

Step 2: Create infrastructure entities

import networkx as nx

city_graph = nx.DiGraph()

entities = [
("WATER_001", {"type": "Sensor"}),
("DRAIN_001", {"type": "Drainage"}),
("ROAD_001", {"type": "Road"}),
("HOSPITAL_001", {"type": "Hospital"}),
("ZONE_A", {"type": "UrbanZone"}),
("TEAM_001", {"type": "MaintenanceTeam"})
]

for entity_id, properties in entities:
city_graph.add_node(entity_id, **properties)

Step 3: Add relationships

relationships = [
("WATER_001", "DRAIN_001", "MONITORS"),
("DRAIN_001", "ZONE_A", "SERVES"),
("ROAD_001", "ZONE_A", "LOCATED_IN"),
("HOSPITAL_001", "ZONE_A", "LOCATED_IN"),
("TEAM_001", "DRAIN_001", "MAINTAINS")
]

for source, target, relationship in relationships:
city_graph.add_edge(
source,
target,
relationship=relationship
)

Step 4: Explore connected infrastructure

for source, target, data in city_graph.edges(data=True):

print(
source,
"--",
data["relationship"],
"-->",
target
)
Illustrative output:
WATER_001 -- MONITORS --> DRAIN_001
DRAIN_001 -- SERVES --> ZONE_A
ROAD_001 -- LOCATED_IN --> ZONE_A
HOSPITAL_001 -- LOCATED_IN --> ZONE_A
TEAM_001 -- MAINTAINS --> DRAIN_001

Step 5: Find the infrastructure connected to a sensor

sensor_id = "WATER_001"

connected_assets = nx.descendants(
city_graph,
sensor_id
)

print("Connected infrastructure:")

for asset in connected_assets:
print(asset)
This explores the directed paths that can be reached from the selected sensor.
The example is deliberately small. A production graph would require additional relationships, data validation, access controls, and query optimization.

Step 6: Visualize the graph

import matplotlib.pyplot as plt

pos = nx.spring_layout(
city_graph,
seed=42
)

nx.draw(
city_graph,
pos,
with_labels=True,
node_size=2500,
font_size=8,
arrows=True
)

edge_labels = nx.get_edge_attributes(
city_graph,
"relationship"
)

nx.draw_networkx_edge_labels(
city_graph,
pos,
edge_labels=edge_labels,
font_size=7
)

plt.title("Illustrative Smart City Knowledge Graph")
plt.show()
This creates a simple visual representation of the connected infrastructure.
The purpose is to understand the data model before moving to a managed graph database.

7. Moving the graph model to Amazon Neptune

Once the graph structure is understood, we can design a Neptune implementation.
A property graph can be created with nodes and relationships.
For example, an illustrative openCypher query to create a sensor and drainage asset is:
CREATE
(s:Sensor {
id: 'WATER_001',
type: 'water_level',
zone: 'ZONE_A'
}),
(d:Drainage {
id: 'DRAIN_001',
zone: 'ZONE_A'
}),
(s)-[:MONITORS]->(d)
To query the relationship:
MATCH (s:Sensor)-[:MONITORS]->(d:Drainage)
RETURN s.id, d.id, d.zone
To identify connected assets through a zone:
MATCH
(s:Sensor {id: 'WATER_001'})
-[:MONITORS]->(d:Drainage)
-[:SERVES]->(z:UrbanZone)
RETURN
s.id,
d.id,
z.id
These are illustrative openCypher statements. A real implementation needs a provisioned Neptune endpoint, authentication and network access, suitable permissions, and application-side query execution.

8. The interesting part: Investigating cascading urban risks

Now let's connect the previous episodes.
Suppose Part 3's anomaly detection model identifies unusual water-level readings.
The system has already stored the sensor information.
The knowledge graph now provides additional context.
A proposed investigation workflow could be:
Step 1 — Detect
The anomaly detection system identifies an unusual reading from WATER_001.
Step 2 — Locate
The graph identifies the drainage network monitored by that sensor.
Step 3 — Connect
The application traverses verified relationships to find connected roads, urban zones, and nearby public facilities.
Step 4 — Retrieve
The system retrieves relevant historical incident records and recent sensor measurements.
Step 5 — Analyze
The application evaluates whether the available evidence suggests a wider infrastructure concern.
Step 6 — Explain
An AI application generates a summary containing the affected assets, supporting evidence, and uncertainties.
Step 7 — Review
An authorized operator investigates the alert and determines the appropriate response.
This is an important distinction.
A graph can show that two assets are connected or geographically related. It does not independently prove that one asset's failure will cause another asset to fail.
Causal relationships require engineering evidence, validated models, and domain expertise.

9. Going further: Graph algorithms for urban intelligence

Once a city infrastructure graph becomes sufficiently detailed, we can explore graph algorithms.
Amazon Neptune Analytics offers graph algorithms that can support several useful analyses.

A. Pathfinding

Find a path between connected infrastructure assets.
Potential use:
Explore connections between a drainage network and a monitored urban zone.

B. Centrality

Identify highly connected or structurally important nodes.
Potential use:
Identify infrastructure hubs whose disruption may deserve additional investigation.

C. Community detection

Identify clusters of closely connected entities.
Potential use:
Discover infrastructure groups that share connections or dependencies.

D. Connected components

Identify disconnected sections of an infrastructure network.
Potential use:
Investigate isolated network segments or incomplete infrastructure records.

E. Similarity analysis

Compare graph neighborhoods to discover similar infrastructure patterns.
Potential use:
Identify assets with similar surrounding infrastructure relationships.
These algorithms provide analytical capabilities, but their outputs must be interpreted within the actual engineering context.
A highly connected node is not automatically a critical asset. Criticality depends on service function, redundancy, capacity, population served, and other domain-specific factors.

10. Connecting the knowledge graph with a digital twin

A graph describes relationships.
A digital twin can provide a richer representation of physical infrastructure and its state.
AWS IoT TwinMaker provides capabilities for creating digital twins using entities, components, relationships, and connected data sources.
For example, a digital twin representation might include:
  • A drainage asset
  • Its location
  • Associated sensor readings
  • Maintenance information
  • Related infrastructure
  • A visual representation in a scene
This could help operators move from a graph query to a visual understanding of the infrastructure.
A useful architectural distinction:
  • Amazon Neptune can provide a general-purpose graph database for connected urban data.
  • AWS IoT TwinMaker can model and visualize digital representations of physical systems.
  • They solve related but different problems and should only be combined when the application requires both.

11. Engineering challenges

Incomplete relationships

Some infrastructure records may be missing or outdated.
The graph must identify unknown relationships rather than silently assume them.

Incorrect relationships

A wrong connection can lead to misleading impact analysis.
Relationships need source references, validation status, and ownership.

Geographic accuracy

Nearby assets are not necessarily connected.
Use reliable coordinates, network topology, and verified infrastructure records.

Graph growth

Large cities may contain millions of entities and relationships.
Plan for ingestion, query patterns, indexing, and performance.

Data freshness

A road closure, pipeline replacement, or new facility can make an old graph inaccurate.
Create update workflows and record when relationships become valid or expire.

Security

Infrastructure maps may be sensitive.
Apply least-privilege access, encryption, audit logging, and suitable network isolation.

Explainability

Every important relationship should have an understandable meaning and, where possible, a traceable source.

12. What have we designed in Part 4?

We have introduced a knowledge graph as the relationship intelligence layer of our proposed artificial nervous system.
Our technical journey now looks like this:
Part 1 — Define the city intelligence vision.
Part 2 — Collect and stream sensor information.
Part 3 — Identify unusual patterns using machine learning.
Part 4 — Connect infrastructure entities and understand their relationships.
The platform is gradually moving beyond individual sensor alerts towards connected infrastructure investigation.

13. What comes next? Part 5 of the series

We now have sensor intelligence, anomaly detection, and an infrastructure knowledge graph.
But what if the system could coordinate multiple specialized AI components to investigate a complex urban situation?
Imagine one agent retrieving sensor information, another exploring infrastructure relationships, and another checking historical incidents.
Could these agents work together to prepare an evidence-based investigation report?
In Part 5, we will explore:
Can AI Predict How One Infrastructure Failure Affects an Entire City?
We will examine:
  • Infrastructure dependency analysis
  • Scenario simulation
  • Multi-agent collaboration
  • Risk assessment
  • Amazon Bedrock
  • Strands Agents
  • Amazon Bedrock AgentCore
The city has learned to connect the dots.
Next, we explore how it can use those connections to investigate what might happen.
THE CITY THAT CAN FEEL — Seven days. Seven technical deep dives. One intelligent city vision.



References and further reading

Disclaimer: This article presents a proposed architecture and illustrative local graph prototype. The infrastructure entities and relationships are hypothetical. No real city infrastructure graph, deployed AWS system, or validated cascading-risk prediction is claimed. Real-world implementation requires verified asset records, engineering review, data governance, security controls, and human oversight.

Series: THE CITY THAT CAN FEEL: Building an Artificial Nervous System for Smart Cities Using AWS (7 articles)

  1. …
  2. 4
    Connecting the Dots: Building a Smart City Knowledge Graph | Part 4 This article
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article