Nodes, Edges, and Properties: The Building Blocks

Nodes, Edges, and Properties: The Building Blocks

Master the essential vocabulary of graph theory. Learn how to map real-world objects to nodes, actions to edges, and metadata to properties to create a rich Knowledge Graph.

Nodes, Edges, and Properties: The Building Blocks

Welcome to the technical foundation of the course. To build a Graph RAG system, you must stop being just an "AI Developer" and become a "Graph Architect." This requires a shared vocabulary. Whether you use Neo4j, Neptune, or a custom Python graph, the fundamental concepts remain the same.

In this lesson, we will explore the three "Building Blocks" of the Property Graph: Nodes (The Actors), Edges (The Actions), and Properties (The Details). We will learn how to transform a sentence into a structured graph element and how to design "Rich Edges" that prevent your graph from becoming a simple, flat list.


1. Nodes: The "Nouns" of the Graph

Definition: A Node (or Vertex) represents an object or entity in your world.

  • In a Corporate Graph: Employee, Project, Office, Budget.
  • In a Scientific Graph: Molecule, Reaction, Paper, Scientist.

Each node should have at least one Label (e.g., :Person). This allows the system to filter nodes quickly. "Show me all nodes labeled :Symptom."


2. Edges: The "Verbs" of the Graph

Definition: An Edge (or Relationship) defines the connection between two nodes.

Edges are what create the "Graphiness" of your data. Without edges, you just have a very expensive list.

  • Example: (Person) -[:WORKS_AT]-> (Company)

The Directional Rule:

In many graph systems, edges are directed. An edge from A -> B is not the same as B -> A.

  • (Sudeep) -[:MANAGES]-> (Jane) means Sudeep is the boss.
  • (Jane) -[:MANAGES]-> (Sudeep) means Jane is the boss.

3. Properties: The "Adjectives" of the Graph

Definition: Properties are Key-Value pairs attached to nodes or edges. This is what makes a "Property Graph" so much more powerful than a simple mathematical graph.

Node Properties:

Instead of creating a node for "Age," you add a property to the Person node: age: 32.

Edge Properties:

This is a "Pro" move in Graph RAG. You can store metadata on the relationship itself.

  • Example: (Sudeep) -[:WORKS_AT {startDate: '2020-01-01', status: 'Full-time'}]-> (London Office)

Why this matters for RAG: Your agent can now answer: "Where did Sudeep work BEFORE 2021?" by filtering the startDate property on the edges.

graph LR
    A((Person: Sudeep)) -- WORKS_AT {role: 'Lead'} --> B((Office: London))
    A -- BORN_ON --> C((Date: 1990))
    
    style A fill:#4285F4,color:#fff
    style B fill:#34A853,color:#fff
    style C fill:#f4b400,color:#fff

4. Modeling Exercise: Sentences to Triplets

Let's practice "Graph Thinking" by mapping natural language to our building blocks.

Sentence: "Apollo 11 landed on the Moon in July 1969 with Neil Armstrong as commander."

The Graph Representation:

  1. Node: [Apollo 11] (Label: :Mission)
  2. Node: [The Moon] (Label: :CelestialBody)
  3. Node: [Neil Armstrong] (Label: :Person)
  4. Edge: (Apollo 11) -[:LANDED_ON {year: 1969}]-> (The Moon)
  5. Edge: (Neil Armstrong) -[:COMMANDED]-> (Apollo 11)

By breaking the sentence down, we have created a Queryable Structure. We can now ask: "Which celestial bodies did COMMANDED missions land on?"


5. Implementation: Defining a Property Graph in Python

Using the networkx library, we can build a programmatic Property Graph.

import networkx as nx

# 1. Create the Graph object
G = nx.MultiDiGraph()

# 2. Add Nodes with properties
G.add_node("Sudeep", label="Person", age=32)
G.add_node("London", label="City", population=9000000)

# 3. Add Edges with properties
G.add_edge("Sudeep", "London", type="LIVES_IN", since=2015)

# 4. Query the building blocks
node_data = G.nodes["Sudeep"]
edge_data = G.get_edge_data("Sudeep", "London")[0]

print(f"Node Properties: {node_data}")
print(f"Relationship Property: since {edge_data['since']}")

# RESULT:
# Node Properties: {'label': 'Person', 'age': 32}
# Relationship Property: since 2015

6. Summary and Exercises

Nodes, Edges, and Properties are the "Holy Trinity" of Graph RAG.

  • Nodes are the entities (Nouns).
  • Edges are the relationships (Verbs).
  • Properties are the metadata (Adjectives).

Exercises

  1. Modeling Challenge: Take a single paragraph from a news article. Identify 5 Nodes and the 5 Edges that connect them.
  2. Property vs. Node: Decisions, decisions! Would you model "Salary" as a Node or as a Property on the :WORKS_AT relationship? Hint: Do you need to aggregate "Salary" as a concept, or just know its value for a specific employee?
  3. Visual Draft: Draw a graph of your family. Use directed edges for [:PARENT_OF]. Are there any nodes that have multiple incoming edges? This is a "Fan-in" topology.

In the next lesson, we will look at Directed vs Undirected Graphs and how the flow of information changes your agent's reasoning.

Subscribe to our newsletter

Get the latest posts delivered right to your inbox.

Subscribe on LinkedIn