Algorithms
Algorithms
Native and NetworkX graph algorithms
Algorithms
Section titled “Algorithms”The SDK provides two algorithm managers accessible from any
InstanceConnection:
| Manager | Access | Engine | Algorithms |
|---|---|---|---|
AlgorithmManager | conn.algo | Native Ryugraph | PageRank, WCC, SCC, Louvain, K-Core, Label Propagation, Triangle Count, Shortest Path |
NetworkXManager | conn.networkx | NetworkX bridge | 500+ algorithms — degree, betweenness, closeness, eigenvector centrality, clustering, and more |
Both managers support three usage patterns:
- Discovery — list and inspect available algorithms
- Convenience methods — typed, documented methods for common algorithms
- Generic
run()— call any algorithm by name with arbitrary parameters
Setup
Connect to the platform
# Cell 1 — ParametersUSERNAME = "_FILL_ME_IN_" # Set your email before running# Cell 2 — Connectfrom graph_olap import GraphOLAPClientclient = GraphOLAPClient(username=USERNAME)# Cell 3 — Provisionfrom notebook_setup import provisionpersonas, conn = provision(USERNAME)analyst = personas["analyst"]admin = personas["admin"]ops = personas["ops"]client = analystprint(f"Connected to {conn.name} | {conn.query_scalar('MATCH (n) RETURN count(n)')} nodes")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.
| Parameter | Type | Default | Description |
|---|---|---|---|
category | str | None | None | Filter by category (centrality, community, path, etc.) |
Returns: List of dicts with name, category, description.
# List all native algorithmsalgos = conn.algo.algorithms()for algo in algos: print(f"{algo['name']:25s} {algo['category']}")
# Filter by categorycentrality = 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.
| Parameter | Type | Description |
|---|---|---|
algorithm | str | Algorithm name |
Returns: Dict with name, category, description, parameters.
# Inspect an algorithm's parametersinfo = 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', '')}")Native Convenience Methods
Typed methods via conn.algo
Pattern 1: Convenience methods
Section titled “Pattern 1: Convenience methods”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.
| Parameter | Type | Default | Description |
|---|---|---|---|
node_label | str | required | Target node label |
property_name | str | required | Property to store the PageRank score |
edge_type | str | None | None | Relationship type to traverse |
damping | float | 0.85 | Damping factor |
max_iterations | int | 100 | Maximum iterations |
tolerance | float | 1e-6 | Convergence tolerance |
timeout | int | 300 | Max execution time in seconds |
wait | bool | True | Block until completion |
Returns: AlgorithmExecution with status, execution_id, and result metadata.
# Run PageRank on Customer nodesresult = 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 resultstop = 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}")Other native convenience methods
Section titled “Other native convenience methods”All convenience methods follow the same signature pattern:
(node_label, property_name, edge_type=None, *, <algo-specific params>, timeout=300, wait=True).
| Method | Algorithm | Key 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 detection | resolution=1.0 |
conn.algo.kcore(...) | K-Core decomposition | — |
conn.algo.label_propagation(...) | Label Propagation communities | max_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 Louvainlouvain_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 Componentswcc_result = conn.algo.connected_components( node_label="Customer", edge_type="SHARES_ACCOUNT", property_name="wcc_id",)print(f"WCC: {wcc_result.status}")NetworkX Methods
500+ algorithms via conn.networkx
Pattern 2: NetworkX bridge
Section titled “Pattern 2: NetworkX bridge”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 algorithmsnx_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.
| Parameter | Type | Description |
|---|---|---|
node_label | str | Target node label |
property_name | str | Property to store result |
**kwargs | Forwarded to run() (timeout, wait) |
# Degree centrality via NetworkXresult = conn.networkx.degree_centrality( node_label="Customer", property_name="degree_cent",)
print(f"Status: {result.status}")
# Query resultstop = 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}")Other NetworkX convenience methods
Section titled “Other NetworkX convenience methods”| Method | Algorithm | Key parameters |
|---|---|---|
conn.networkx.betweenness_centrality(...) | Betweenness centrality | k=None (sample size) |
conn.networkx.closeness_centrality(...) | Closeness centrality | — |
conn.networkx.eigenvector_centrality(...) | Eigenvector centrality | max_iter=100 |
conn.networkx.clustering_coefficient(...) | Clustering coefficient | — |
All accept (node_label, property_name, **kwargs) and return AlgorithmExecution.
Generic Run Method
Call any algorithm by name
Pattern 3: Generic run()
Section titled “Pattern 3: Generic run()”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”| Parameter | Type | Default | Description |
|---|---|---|---|
algorithm | str | required | Algorithm name (e.g. "pagerank", "wcc", "louvain") |
node_label | str | None | None | Target node label |
property_name | str | None | None | Property to store result |
edge_type | str | None | None | Relationship type to traverse |
params | dict | None | None | Algorithm-specific parameters |
timeout | int | 300 | Max execution time in seconds |
wait | bool | True | Block 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 methodexec1 = 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()andalgorithm_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