Graph Algorithms¶
Grafeo includes a library of built-in graph algorithms for common analysis tasks.
Coming Soon
The algorithms module is under active development. This page documents the planned API and available algorithms.
Algorithm Categories¶
-
Path Finding
Shortest paths, all paths, and path analysis.
-
Centrality
PageRank, betweenness, closeness, and degree centrality.
-
Community Detection
Louvain, label propagation, and connected components.
-
Link Prediction
Predict missing or future relationships.
-
Similarity
Node similarity and graph matching.
-
Graph Metrics
Density, diameter, clustering coefficient.
Quick Reference¶
| Algorithm | Category | Complexity | Use Case |
|---|---|---|---|
| Shortest Path | Path | O(V + E) | Navigation, routing |
| PageRank | Centrality | O(V + E) | Ranking, importance |
| Louvain | Community | O(V log V) | Clustering |
| Connected Components | Community | O(V + E) | Graph structure |
| Triangle Count | Metrics | O(E^1.5) | Clustering analysis |
Using Algorithms¶
From GQL¶
-- PageRank
CALL grafeo.pagerank({
node_label: 'Page',
relationship_type: 'LINKS',
damping: 0.85,
iterations: 20
})
YIELD nodeId, score
MATCH (p:Page) WHERE id(p) = nodeId
RETURN p.url, score
ORDER BY score DESC
LIMIT 10
From Python¶
import grafeo
from grafeo.algorithms import pagerank, shortest_path
db = grafeo.Database()
# Run PageRank
scores = pagerank(db, damping=0.85, iterations=20)
for node_id, score in scores.items():
print(f"Node {node_id}: {score:.4f}")
# Find shortest path
path = shortest_path(db, source_id=1, target_id=100)
print(f"Path length: {len(path)}")
From Rust¶
use grafeo::algorithms::{pagerank, PageRankConfig};
let config = PageRankConfig {
damping: 0.85,
iterations: 20,
tolerance: 1e-6,
};
let scores = pagerank(&db, config)?;
for (node_id, score) in scores.iter() {
println!("Node {}: {:.4}", node_id, score);
}
Algorithm Configuration¶
Most algorithms accept configuration parameters:
# PageRank configuration
pagerank(db,
damping=0.85, # Damping factor (0-1)
iterations=20, # Max iterations
tolerance=1e-6, # Convergence threshold
node_label='Page', # Filter by label
relationship_type='LINKS' # Filter by type
)
Custom Algorithms¶
See Extending Grafeo to learn how to add custom algorithms.
Performance Considerations¶
- Graph Size - Large graphs may require more memory
- Iterations - More iterations = better accuracy, longer runtime
- Parallelism - Many algorithms support parallel execution
- Caching - Results can be cached for repeated queries