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 |
|---|---|---|
|
List<RID> |
Ordered list of vertex identities visited |
|
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.
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