Skip to content

Algorithms

Reference

Algorithms

Native and NetworkX graph algorithms

15 min Intermediate
ReferenceAPIAlgorithms

The SDK provides two algorithm managers accessible from any InstanceConnection:

ManagerAccessEngineAlgorithms
AlgorithmManagerconn.algoNative RyugraphPageRank, WCC, SCC, Louvain, K-Core, Label Propagation, Triangle Count, Shortest Path
NetworkXManagerconn.networkxNetworkX bridge500+ algorithms — degree, betweenness, closeness, eigenvector centrality, clustering, and more

Both managers support three usage patterns:

  1. Discovery — list and inspect available algorithms
  2. Convenience methods — typed, documented methods for common algorithms
  3. Generic run() — call any algorithm by name with arbitrary parameters
1

Setup

Connect to the platform

# Cell 1 — Parameters
USERNAME = "_FILL_ME_IN_" # Set your email before running
# Cell 2 — Connect
from graph_olap import GraphOLAPClient
client = GraphOLAPClient(username=USERNAME)
# Cell 3 — Provision
from notebook_setup import provision
personas, conn = provision(USERNAME)
analyst = personas["analyst"]
admin = personas["admin"]
ops = personas["ops"]
client = analyst
print(f"Connected to {conn.name} | {conn.query_scalar('MATCH (n) RETURN count(n)')} nodes")
2

Algorithm Discovery

List and inspect available algorithms

conn.algo.algorithms(category=None) -> list[dict]

Section titled “conn.algo.algorithms(category=None) -> list[dict]”

List available native algorithms, optionally filtered by category.

ParameterTypeDefaultDescription
categorystr | NoneNoneFilter by category (centrality, community, path, etc.)

Returns: List of dicts with name, category, description.

# List all native algorithms
algos = conn.algo.algorithms()
for algo in algos:
print(f"{algo['name']:25s} {algo['category']}")
# Filter by category
centrality = conn.algo.algorithms(category="centrality")
print(f"\nCentrality algorithms: {len(centrality)}")

conn.algo.algorithm_info(algorithm) -> dict

Section titled “conn.algo.algorithm_info(algorithm) -> dict”

Get detailed information for a specific algorithm, including its parameters.

ParameterTypeDescription
algorithmstrAlgorithm name

Returns: Dict with name, category, description, parameters.

# Inspect an algorithm's parameters
info = conn.algo.algorithm_info("pagerank")
print(f"Algorithm: {info['name']}")
print(f"Category: {info['category']}")
print(f"\nParameters:")
for p in info.get("parameters", []):
print(f" {p['name']:20s} {p.get('type', ''):10s} {p.get('description', '')}")
3

Native Convenience Methods

Typed methods via conn.algo

Each convenience method wraps conn.algo.run() with typed parameters and sensible defaults. Results are written to a node property.

conn.algo.pagerank(node_label, property_name, edge_type=None, *, damping=0.85, max_iterations=100, tolerance=1e-6, timeout=300, wait=True) -> AlgorithmExecution

Section titled “conn.algo.pagerank(node_label, property_name, edge_type=None, *, damping=0.85, max_iterations=100, tolerance=1e-6, timeout=300, wait=True) -> AlgorithmExecution”

Run PageRank centrality. The damping factor controls the probability of following an edge vs. jumping to a random node.

ParameterTypeDefaultDescription
node_labelstrrequiredTarget node label
property_namestrrequiredProperty to store the PageRank score
edge_typestr | NoneNoneRelationship type to traverse
dampingfloat0.85Damping factor
max_iterationsint100Maximum iterations
tolerancefloat1e-6Convergence tolerance
timeoutint300Max execution time in seconds
waitboolTrueBlock until completion

Returns: AlgorithmExecution with status, execution_id, and result metadata.

# Run PageRank on Customer nodes
result = conn.algo.pagerank(
node_label="Customer",
property_name="pr_score",
edge_type="SHARES_ACCOUNT",
damping=0.85,
max_iterations=100,
)
print(f"Status: {result.status}")
print(f"Execution ID: {result.execution_id}")
# Query the results
top = conn.query(
"MATCH (c:Customer) WHERE c.pr_score IS NOT NULL "
"RETURN c.id, c.pr_score ORDER BY c.pr_score DESC LIMIT 5"
)
for row in top:
print(f" {row['c.id']:20s} {row['c.pr_score']:.6f}")

All convenience methods follow the same signature pattern: (node_label, property_name, edge_type=None, *, <algo-specific params>, timeout=300, wait=True).

MethodAlgorithmKey parameters
conn.algo.connected_components(...)Weakly Connected Components
conn.algo.scc(...)Strongly Connected Components (Tarjan)
conn.algo.scc_kosaraju(...)Strongly Connected Components (Kosaraju)
conn.algo.louvain(...)Louvain community detectionresolution=1.0
conn.algo.kcore(...)K-Core decomposition
conn.algo.label_propagation(...)Label Propagation communitiesmax_iterations=100
conn.algo.triangle_count(...)Triangle counting

conn.algo.shortest_path(source_id, target_id, *, relationship_types=None, max_depth=None, timeout=60) -> AlgorithmExecution

Section titled “conn.algo.shortest_path(source_id, target_id, *, relationship_types=None, max_depth=None, timeout=60) -> AlgorithmExecution”

shortest_path differs from the others: it takes source and target node IDs and returns the path in the result rather than writing to a property.

# Community detection with Louvain
louvain_result = conn.algo.louvain(
node_label="Customer",
edge_type="SHARES_ACCOUNT",
property_name="community_id",
resolution=1.0,
)
print(f"Louvain: {louvain_result.status}")
# Weakly Connected Components
wcc_result = conn.algo.connected_components(
node_label="Customer",
edge_type="SHARES_ACCOUNT",
property_name="wcc_id",
)
print(f"WCC: {wcc_result.status}")
4

NetworkX Methods

500+ algorithms via conn.networkx

The NetworkXManager provides access to the full NetworkX algorithm library. Discovery works identically to native algorithms.

conn.networkx.algorithms(category=None) -> list[dict]

Section titled “conn.networkx.algorithms(category=None) -> list[dict]”

List available NetworkX algorithms.

conn.networkx.algorithm_info(algorithm) -> dict

Section titled “conn.networkx.algorithm_info(algorithm) -> dict”

Get details for a specific NetworkX algorithm.

# List NetworkX centrality algorithms
nx_centrality = conn.networkx.algorithms(category="centrality")
for algo in nx_centrality:
print(f"{algo['name']:30s} {algo.get('description', '')[:60]}")

conn.networkx.degree_centrality(node_label, property_name, **kwargs) -> AlgorithmExecution

Section titled “conn.networkx.degree_centrality(node_label, property_name, **kwargs) -> AlgorithmExecution”

Calculate degree centrality for each node. Degree centrality is the fraction of nodes that a given node is connected to.

ParameterTypeDescription
node_labelstrTarget node label
property_namestrProperty to store result
**kwargsForwarded to run() (timeout, wait)
# Degree centrality via NetworkX
result = conn.networkx.degree_centrality(
node_label="Customer",
property_name="degree_cent",
)
print(f"Status: {result.status}")
# Query results
top = conn.query(
"MATCH (c:Customer) WHERE c.degree_cent IS NOT NULL "
"RETURN c.id, c.degree_cent ORDER BY c.degree_cent DESC LIMIT 5"
)
for row in top:
print(f" {row['c.id']:20s} {row['c.degree_cent']:.4f}")
MethodAlgorithmKey parameters
conn.networkx.betweenness_centrality(...)Betweenness centralityk=None (sample size)
conn.networkx.closeness_centrality(...)Closeness centrality
conn.networkx.eigenvector_centrality(...)Eigenvector centralitymax_iter=100
conn.networkx.clustering_coefficient(...)Clustering coefficient

All accept (node_label, property_name, **kwargs) and return AlgorithmExecution.

5

Generic Run Method

Call any algorithm by name

When a convenience method does not exist for the algorithm you need, use run() to call any algorithm by name with arbitrary parameters.

conn.algo.run(algorithm, node_label=None, property_name=None, edge_type=None, *, params=None, timeout=300, wait=True) -> AlgorithmExecution

Section titled “conn.algo.run(algorithm, node_label=None, property_name=None, edge_type=None, *, params=None, timeout=300, wait=True) -> AlgorithmExecution”
ParameterTypeDefaultDescription
algorithmstrrequiredAlgorithm name (e.g. "pagerank", "wcc", "louvain")
node_labelstr | NoneNoneTarget node label
property_namestr | NoneNoneProperty to store result
edge_typestr | NoneNoneRelationship type to traverse
paramsdict | NoneNoneAlgorithm-specific parameters
timeoutint300Max execution time in seconds
waitboolTrueBlock until completion

conn.networkx.run(algorithm, node_label=None, property_name=None, *, params=None, timeout=300, wait=True) -> AlgorithmExecution

Section titled “conn.networkx.run(algorithm, node_label=None, property_name=None, *, params=None, timeout=300, wait=True) -> AlgorithmExecution”

Same interface for NetworkX algorithms (no edge_type parameter).

# Native: run Louvain with custom resolution via generic method
exec1 = conn.algo.run(
"louvain",
node_label="Customer",
edge_type="SHARES_ACCOUNT",
property_name="community_hi_res",
params={"resolution": 2.0},
)
print(f"Native Louvain: {exec1.status}")
# NetworkX: run Katz centrality (no convenience method exists)
exec2 = conn.networkx.run(
"katz_centrality",
node_label="Customer",
property_name="katz_score",
params={"alpha": 0.1},
)
print(f"NetworkX Katz: {exec2.status}")

Key Takeaways

  • Pattern 1 -- Convenience methods (conn.algo.pagerank()) provide typed parameters and sensible defaults for common algorithms
  • Pattern 2 -- NetworkX bridge (conn.networkx.degree_centrality()) gives access to 500+ algorithms from the NetworkX ecosystem
  • Pattern 3 -- Generic run() calls any algorithm by name with arbitrary parameters when no convenience method exists
  • algorithms() and algorithm_info() let you discover what is available and inspect parameter schemas at runtime
  • All algorithm results are written to node properties and can be queried with Cypher immediately after execution