Graph Algorithms Reference

GraphQLite provides 18 built-in graph algorithms accessible via Cypher functions, the Python Graph API, and the Rust Graph API.

For guidance on choosing the right algorithm for your use case, see Using Graph Algorithms.


PageRank

Cypher

CALL pageRank([damping, iterations]) YIELD node, score

Python

graph.pagerank(damping=0.85, iterations=20)

Rust

#![allow(unused)]
fn main() {
graph.pagerank(damping: f64, iterations: usize) -> Result<Vec<PageRankResult>>
}

Parameters

ParameterTypeDefaultDescription
dampingFloat0.85Damping factor
iterationsInteger20Number of power iterations

Return shape

Python: list[dict] with keys node_id, user_id, score

Rust: Vec<PageRankResult> — fields: node_id: i64, user_id: String, score: f64

Complexity: O(iterations × (V + E))

Example

results = graph.pagerank(damping=0.85, iterations=30)
for r in sorted(results, key=lambda x: x['score'], reverse=True)[:5]:
    print(r['user_id'], r['score'])

Degree Centrality

Cypher

CALL degreeCentrality() YIELD node, in_degree, out_degree, degree

Python

graph.degree_centrality()

Rust

#![allow(unused)]
fn main() {
graph.degree_centrality() -> Result<Vec<DegreeCentralityResult>>
}

Parameters: none

Return shape

Python: list[dict] with keys node_id, user_id, in_degree, out_degree, degree

Rust: Vec<DegreeCentralityResult> — fields: node_id: i64, user_id: String, in_degree: usize, out_degree: usize, degree: usize

Complexity: O(V + E)

Example

for r in graph.degree_centrality():
    print(r['user_id'], 'in:', r['in_degree'], 'out:', r['out_degree'])

Betweenness Centrality

Cypher

CALL betweennessCentrality() YIELD node, score

Python

graph.betweenness_centrality()

Rust

#![allow(unused)]
fn main() {
graph.betweenness_centrality() -> Result<Vec<BetweennessCentralityResult>>
}

Parameters: none

Return shape

Python: list[dict] with keys node_id, user_id, score

Rust: Vec<BetweennessCentralityResult> — fields: node_id: i64, user_id: String, score: f64

Complexity: O(V × E)

Example

results = graph.betweenness_centrality()

Closeness Centrality

Cypher

CALL closenessCentrality() YIELD node, score

Python

graph.closeness_centrality()

Rust

#![allow(unused)]
fn main() {
graph.closeness_centrality() -> Result<Vec<ClosenessCentralityResult>>
}

Parameters: none

Return shape

Python: list[dict] with keys node_id, user_id, score

Rust: Vec<ClosenessCentralityResult> — fields: node_id: i64, user_id: String, score: f64

Complexity: O(V × (V + E))

Example

results = graph.closeness_centrality()

Eigenvector Centrality

Cypher

CALL eigenvectorCentrality([iterations]) YIELD node, score

Python

graph.eigenvector_centrality(iterations=100)

Rust

#![allow(unused)]
fn main() {
graph.eigenvector_centrality(iterations: usize) -> Result<Vec<EigenvectorCentralityResult>>
}

Parameters

ParameterTypeDefaultDescription
iterationsInteger100Power iteration count

Return shape

Python: list[dict] with keys node_id, user_id, score

Rust: Vec<EigenvectorCentralityResult> — fields: node_id: i64, user_id: String, score: f64

Complexity: O(iterations × E)


Louvain Community Detection

Cypher

CALL louvain([resolution]) YIELD node, community

Python

graph.louvain(resolution=1.0)

Rust

#![allow(unused)]
fn main() {
graph.louvain(resolution: f64) -> Result<Vec<CommunityResult>>
}

Parameters

ParameterTypeDefaultDescription
resolutionFloat1.0Resolution parameter controlling community granularity

Return shape

Python: list[dict] with keys node_id, user_id, community

Rust: Vec<CommunityResult> — fields: node_id: i64, user_id: String, community: i64

Example

communities = graph.louvain(resolution=0.5)

Leiden Community Detection

Python only

graph.leiden_communities(resolution=1.0, random_seed=None)

Parameters

ParameterTypeDefaultDescription
resolutionFloat1.0Resolution parameter
random_seedInteger | NoneNoneSeed for reproducibility

Return shape: list[dict] with keys node_id, user_id, community


Label Propagation

Cypher

CALL labelPropagation([iterations]) YIELD node, community

Python

graph.community_detection(iterations=10)

Rust

#![allow(unused)]
fn main() {
graph.community_detection(iterations: usize) -> Result<Vec<CommunityResult>>
}

Parameters

ParameterTypeDefaultDescription
iterationsInteger10Maximum iterations

Return shape

Python: list[dict] with keys node_id, user_id, community

Rust: Vec<CommunityResult> — fields: node_id: i64, user_id: String, community: i64


Weakly Connected Components

Cypher

CALL weaklyConnectedComponents() YIELD node, component

Python

graph.weakly_connected_components()

Rust

#![allow(unused)]
fn main() {
graph.weakly_connected_components() -> Result<Vec<ComponentResult>>
}

Parameters: none

Return shape

Python: list[dict] with keys node_id, user_id, component

Rust: Vec<ComponentResult> — fields: node_id: i64, user_id: String, component: i64

Complexity: O(V + E)


Strongly Connected Components

Cypher

CALL stronglyConnectedComponents() YIELD node, component

Python

graph.strongly_connected_components()

Rust

#![allow(unused)]
fn main() {
graph.strongly_connected_components() -> Result<Vec<ComponentResult>>
}

Parameters: none

Return shape

Python: list[dict] with keys node_id, user_id, component

Rust: Vec<ComponentResult> — fields: node_id: i64, user_id: String, component: i64

Complexity: O(V + E) (Tarjan or Kosaraju)


Shortest Path

Cypher (path function)

MATCH p = shortestPath((a)-[*]->(b))
RETURN p

Cypher (Dijkstra)

CALL dijkstra(source, target[, weight_property]) YIELD path, distance

Python

graph.shortest_path(source, target, weight_property=None)

Rust

#![allow(unused)]
fn main() {
graph.shortest_path(source: &str, target: &str, weight_property: Option<&str>) -> Result<ShortestPathResult>
}

Parameters

ParameterTypeDefaultDescription
sourceStringrequiredSource node user ID
targetStringrequiredTarget node user ID
weight_propertyString | NoneNoneEdge property to use as weight; unweighted BFS if None

Return shape

Python: dict with keys path (list of user IDs), distance (float), found (bool)

Rust: ShortestPathResult — fields: path: Vec<String>, distance: f64, found: bool

Example

result = graph.shortest_path('alice', 'bob', weight_property='cost')
if result['found']:
    print(result['path'], result['distance'])

A* (A-Star)

Cypher

CALL astar(source, target[, lat_prop, lon_prop]) YIELD path, distance

Python

graph.astar(source, target, lat_prop=None, lon_prop=None)

Rust

#![allow(unused)]
fn main() {
graph.astar(source: &str, target: &str, lat_prop: Option<&str>, lon_prop: Option<&str>) -> Result<AStarResult>
}

Parameters

ParameterTypeDefaultDescription
sourceStringrequiredSource node user ID
targetStringrequiredTarget node user ID
lat_propString | NoneNoneNode property for latitude
lon_propString | NoneNoneNode property for longitude

Return shape

Python: dict with keys path, distance, found, nodes_explored

Rust: AStarResult — fields: path: Vec<String>, distance: f64, found: bool, nodes_explored: usize


All-Pairs Shortest Path

Cypher

CALL apsp() YIELD source, target, distance

Python

graph.all_pairs_shortest_path()

Rust

#![allow(unused)]
fn main() {
graph.all_pairs_shortest_path() -> Result<Vec<ApspResult>>
}

Parameters: none

Return shape

Python: list[dict] with keys source, target, distance

Rust: Vec<ApspResult> — fields: source: String, target: String, distance: f64

Complexity: O(V × (V + E))


Cypher

CALL bfs(start[, max_depth]) YIELD node, depth, order

Python

graph.bfs(start, max_depth=-1)

Rust

#![allow(unused)]
fn main() {
graph.bfs(start: &str, max_depth: i64) -> Result<Vec<TraversalResult>>
}

Parameters

ParameterTypeDefaultDescription
startStringrequiredStarting node user ID
max_depthInteger-1Maximum depth; -1 means unlimited

Return shape

Python: list[dict] with keys user_id, depth, order

Rust: Vec<TraversalResult> — fields: user_id: String, depth: usize, order: usize


Cypher

CALL dfs(start[, max_depth]) YIELD node, depth, order

Python

graph.dfs(start, max_depth=-1)

Rust

#![allow(unused)]
fn main() {
graph.dfs(start: &str, max_depth: i64) -> Result<Vec<TraversalResult>>
}

Parameters

ParameterTypeDefaultDescription
startStringrequiredStarting node user ID
max_depthInteger-1Maximum depth; -1 means unlimited

Return shape: same as BFS — list[dict] / Vec<TraversalResult> with user_id, depth, order


Node Similarity

Cypher

CALL nodeSimilarity([node1, node2, threshold, top_k]) YIELD node1, node2, similarity

Python

graph.node_similarity(node1_id=None, node2_id=None, threshold=0.0, top_k=0)

Rust

#![allow(unused)]
fn main() {
graph.node_similarity(node1_id: Option<i64>, node2_id: Option<i64>, threshold: f64, top_k: usize) -> Result<Vec<NodeSimilarityResult>>
}

Parameters

ParameterTypeDefaultDescription
node1_idInteger | NoneNoneFix first node; None means all pairs
node2_idInteger | NoneNoneFix second node; None means all pairs
thresholdFloat0.0Minimum similarity to include
top_kInteger0Return at most top_k results; 0 means all

Algorithm: Jaccard similarity based on shared neighbors.

Return shape

Python: list[dict] with keys node1, node2, similarity

Rust: Vec<NodeSimilarityResult> — fields: node1: String, node2: String, similarity: f64


KNN (k-Nearest Neighbors)

Cypher

CALL knn(node, k) YIELD neighbor, similarity, rank

Python

graph.knn(node_id, k=10)

Rust

#![allow(unused)]
fn main() {
graph.knn(node_id: i64, k: usize) -> Result<Vec<KnnResult>>
}

Parameters

ParameterTypeDefaultDescription
node_idIntegerrequiredSource node internal ID
kInteger10Number of neighbors to return

Return shape

Python: list[dict] with keys neighbor, similarity, rank

Rust: Vec<KnnResult> — fields: neighbor: String, similarity: f64, rank: usize


Triangle Count

Cypher

CALL triangleCount() YIELD node, triangles, clustering_coefficient

Python

graph.triangle_count()

Rust

#![allow(unused)]
fn main() {
graph.triangle_count() -> Result<Vec<TriangleCountResult>>
}

Parameters: none

Return shape

Python: list[dict] with keys node_id, user_id, triangles, clustering_coefficient

Rust: Vec<TriangleCountResult> — fields: node_id: i64, user_id: String, triangles: usize, clustering_coefficient: f64

Complexity: O(V × degree²)

Example

for r in graph.triangle_count():
    print(r['user_id'], r['triangles'], r['clustering_coefficient'])