Traversal and Sampling
algo.randomWalk
| Property | Value |
|---|---|
Procedure |
|
Category |
Traversal / Sampling |
Complexity |
CPU |
Min Args |
2 |
Max Args |
5 |
Syntax
CALL algo.randomWalk(startNode, steps [, relTypes, direction, seed])
YIELD path, steps
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
|
Vertex |
Yes |
— |
Starting vertex |
|
Integer |
Yes |
— |
Maximum number of steps to walk |
|
String |
No |
all types |
Comma-separated relationship types |
|
String |
No |
|
Traversal direction: |
|
Long |
No |
current time |
Random seed for reproducibility |
Yield Fields
| Field | Type | Description |
|---|---|---|
|
Path |
The walk: the nodes visited and the relationships stepped over (see reference/graph-algorithms/path-finding.adoc#graph-algo-path-value) |
|
Integer |
Actual number of steps taken (may be less than requested if dead-end reached) |
Description
Performs a single random walk starting from the given vertex. At each step, one neighbor is chosen uniformly at random from available edges matching the direction and type constraints. The walk stops when the requested number of steps is reached or a dead-end (no valid neighbors) is encountered. Since v26.12.1 the walk reads the neighbours of the vertices it steps on and nothing else, with or without a Graph Analytical View, so its cost follows the number of steps rather than the size of the database (issue #12176).
Use Cases
-
Graph embedding feature generation (node2vec-style)
-
Sampling large graphs for approximate analysis
-
Stochastic exploration of graph neighborhoods
Example
MATCH (start:Page {id:'home'})
CALL algo.randomWalk(start, 20, 'LINKS_TO', 'OUT', 42)
YIELD path, steps
RETURN path, steps
References