Skip to content
Blog

PageRank

The PageRank algorithm ranks entities in a network based on their importance by analyzing connections between them. Each entity (e.g., nodes in a social network, documents, or proteins) gets a score, with higher scores for those linked to by other high-scoring entities. Scores are iteratively calculated, distributing an entity’s rank across its outgoing connections, until stable. In general domains, like citation networks or recommendation systems, it identifies influential nodes, such as highly cited papers or key influencers.

Kuzu implements a parallelized version of PageRank based on Ligra.

Syntax

CALL page_rank(
graph_name,
dampingFactor := 0.85,
maxIterations := 20,
tolerance := 0.0000001
normalizeInitial := true
)
RETURN node, rank

Alias: pr

Parameters

ParameterTypeOptionalDefaultDescription
graph_nameSTRINGNo-Name of the projected graph to run the algorithm on
dampingFactorFLOAT64Yes0.85Probability of following an outgoing edge, must between 0 and 1
maxIterationsINT64Yes20Maximum number of iterations to run
toleranceFLOAT64Yes0.00001Minimum change in scores between iterations to continue
normalizeInitialBOOLEANYestrueWhether to normalize initial scores to sum to 1

Return

ColumnTypeDescription
nodeNODENode object
rankFLOAT64PageRank score of the node

Example

Define schema

CREATE NODE TABLE Node(id STRING PRIMARY KEY);
CREATE REL TABLE Edge(FROM Node to Node);

Insert nodes and edges

CREATE (u0:Node {id: 'A'}),
(u1:Node {id: 'B'}),
(u2:Node {id: 'C'}),
(u3:Node {id: 'D'}),
(u4:Node {id: 'E'}),
(u0)-[:Edge]->(u1),
(u0)-[:Edge]->(u4),
(u1)-[:Edge]->(u4),
(u2)-[:Edge]->(u4),
(u3)-[:Edge]->(u4);

We’ll first create a projected graph from the node and edge tables.

CALL project_graph('Graph', ['Node'], ['Edge']);

Run PageRank on the projected graph as follows:

CALL page_rank('Graph') RETURN node.id, rank ORDER BY rank DESC;
┌─────────┬──────────┐
│ node.id │ rank │
│ STRING │ DOUBLE │
├─────────┼──────────┤
│ E │ 0.130088 │
│ B │ 0.042750 │
│ D │ 0.030000 │
│ C │ 0.030000 │
│ A │ 0.030000 │
└─────────┴──────────┘