Traversal and Sampling

algo.randomWalk

Property Value

Procedure

algo.randomWalk

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

startNode

Vertex

Yes

Starting vertex

steps

Integer

Yes

Maximum number of steps to walk

relTypes

String

No

all types

Comma-separated relationship types

direction

String

No

"BOTH"

Traversal direction: "IN", "OUT", or "BOTH"

seed

Long

No

current time

Random seed for reproducibility

Yield Fields

Field Type Description

path

List<RID>

Ordered list of vertex identities visited

steps

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