You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
Graph algorithms unlock insights hidden in the structure of connected data. Neo4j provides the Graph Data Science (GDS) library — a comprehensive collection of algorithms for pathfinding, centrality, community detection, similarity, and more.
GDS is a Neo4j plugin that provides:
| Environment | Method |
|---|---|
| Neo4j Desktop | Install from the Plugins tab |
| Neo4j AuraDS | Pre-installed |
| Docker | Use the GDS-enabled Docker image |
| Server | Download and install the GDS plugin |
Before running algorithms, you project a subgraph into memory:
// Native projection
CALL gds.graph.project(
'social-graph', // projection name
'Person', // node labels
'FRIENDS_WITH' // relationship types
)
| Option | Description |
|---|---|
| Node labels | Which node types to include |
| Relationship types | Which relationship types to include |
| Properties | Node/relationship properties to include |
| Orientation | NATURAL, REVERSE, or UNDIRECTED |
CALL gds.graph.drop('social-graph')
| Category | Purpose | Example Algorithms |
|---|---|---|
| Pathfinding | Find routes between nodes | Shortest Path, Dijkstra, A* |
| Centrality | Identify important nodes | PageRank, Betweenness, Degree |
| Community Detection | Find clusters and groups | Louvain, Label Propagation, WCC |
| Similarity | Find similar nodes | Node Similarity, K-Nearest Neighbours |
| Node Embedding | Generate vector representations | FastRP, Node2Vec, GraphSAGE |
| Link Prediction | Predict future connections | Common Neighbours, Preferential Attachment |
Find the shortest weighted path between two nodes:
MATCH (source:City {name: "London"}), (target:City {name: "Paris"})
CALL gds.shortestPath.dijkstra.stream('transport-graph', {
sourceNode: source,
targetNode: target,
relationshipWeightProperty: 'distance'
})
YIELD index, sourceNode, targetNode, totalCost, nodeIds, costs, path
RETURN totalCost, [nodeId IN nodeIds | gds.util.asNode(nodeId).name] AS route
Find all shortest paths between two nodes:
MATCH (source:Person {name: "Alice"}), (target:Person {name: "Dave"})
CALL gds.shortestPath.dijkstra.stream('social-graph', {
sourceNode: source,
targetNode: target
})
YIELD totalCost, path
RETURN totalCost, path
Neo4j also has a built-in shortest path function:
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.