Chapter 24 · Graph Algorithms: Centrality, Community Detection, Similarity, Paths, and Topology Analytics
Choose an Algorithm from the Decision Question, Validate Assumptions, and Interpret Results Without Overclaiming
Choose GDS algorithms from decision questions, validate assumptions with fixtures/baselines/sensitivity evidence, and create a reproducible interpretation/runbook before moving to graph ML.
Learning outcomes
Map a decision question to a graph algorithm family and reject algorithms whose assumptions do not match the data.
Build an evidence card covering projection, orientation, weights, parameters, memory, concurrency, mode, baseline, and interpretation limits.
Validate centrality, communities, similarity, and paths with hand fixtures or simple baselines before scaling.
Test sensitivity/stability and distinguish exploratory analytics from production decision support.
Produce a reproducible Chapter 24 runbook and cleanly bridge into graph embeddings and ML pipelines.
Treat every command, query, configuration change, benchmark, security change, failure injection, and cleanup step in this lesson as scoped to the disposable AtlasMart course lab unless the text explicitly says otherwise. Verify the actual Neo4j, Cypher, driver, plugin/GDS, edition/tier, authentication, TLS, and deployment state before execution. Expected results describe invariants and evidence shapes; they are not fabricated claims that this generated lesson captured a live production run.
1. AtlasMart problem: an algorithm portfolio can become a cargo-cult portfolio
After four lessons, AtlasMart can run dozens of GDS algorithms. That capability creates a new risk: selecting the algorithm whose name sounds impressive, then fitting a business story to the score. Production analytics must reverse that sequence. Begin with a decision and a falsifiable structural hypothesis; then select the minimal algorithm family that tests it.
| Dimension | Chapter 24 reproducible assumption |
|---|---|
| Neo4j |
2026.07.1 Community, disposable local/container
deployment; database neo4j.
|
| Cypher | Cypher 25 for course examples; Cypher 5 differences are not needed for the GDS procedures used here. |
| Java | Java 21/25 supported by the 2026 line; container image supplies the runtime. |
| Auth/TLS |
User neo4j, password
atlasmart-course-2026; loopback Bolt without
TLS only for this isolated lab.
|
| Driver | No application driver is required for mandatory GDS procedure labs; cypher-shell/Browser is sufficient. |
| GDS | GDS Community 2026.07.0. Community includes all algorithms; maximum GDS concurrency is four CPU cores. |
| APOC | Not required. |
| Graph scope |
Only identifiers prefixed CH24- plus named
in-memory projections beginning
atlas-ch24- are created.
|
| Runtime evidence | This artifact does not execute Neo4j/GDS. Exact fixture counts and hand calculations are deterministic; timings, memory estimates, and algorithm scores must be measured locally. |
// Run in the disposable atlasmart-gds lab from Chapter 23.
RETURN gds.version() AS gdsVersion;
CALL dbms.components() YIELD name, versions, edition
RETURN name, versions, edition;
// Defensive cleanup of Chapter 24 projections if rerunning.
CALL gds.graph.list()
YIELD graphName
WITH graphName WHERE graphName STARTS WITH 'atlas-ch24-'
CALL gds.graph.drop(graphName) YIELD graphName AS dropped
RETURN dropped;
2. The decision-question matrix
| Decision question | Candidate algorithm | Key assumptions to validate | Minimum baseline |
|---|---|---|---|
| Which nodes have many direct ties? | Degree | Edge direction/type and optional weights mean direct exposure/connection. | Cypher COUNT of intended relationships. |
| Which nodes receive transitive influence? | PageRank / Eigenvector | Direction and iterative influence model match the process; damping for PageRank justified. | Degree + simple known graph. |
| Which nodes bridge shortest routes? | Betweenness | Shortest-path metric represents flow; exact vs sampled choice justified. | Hand shortest paths on tiny fixture. |
| Which nodes form dense structural groups? | Louvain / Leiden / LPA | Projection has community structure; weights/resolution/seed semantics valid. | Known two-block fixture + partition-stability check. |
| Which nodes share neighbors? | Node Similarity | Bipartite/outgoing-neighborhood model is meaningful. | Manual Jaccard/Overlap pairs. |
| Which nodes are near in property space? | KNN | Projected properties and metric represent similarity; approximation evaluated. | Exact small-set neighbor calculation. |
| What is the cheapest/reachable route? | Dijkstra / BFS / DFS / spanning family | Cost and termination semantics valid; projection fresh enough. | Manual route/reachability fixture. |
3. Algorithm evidence card: required before a production interpretation
decision_question: "Which catalog products act as structural bridges between co-interest groups?"
source_cutoff: "<record timestamp/CDC checkpoint>"
neo4j: "2026.07.1"
gds: "2026.07.0 Community"
projection:
name: "atlas-ch24-centrality"
node_labels: [Product]
relationship_types: [RELATED_TO]
orientation: NATURAL
node_count: "<measure>"
relationship_count: "<measure>"
degree_distribution: "<record p50/p95/p99/max>"
algorithm:
name: "gds.betweenness.stream"
mode: stream
relationship_weight_property: null
sampling_size: "<node count for exact, or justified sample>"
sampling_seed: "<set when sampling>"
concurrency: 2
resource_evidence:
estimate_required_memory: "<measure>"
compute_millis: "<measure>"
validation:
hand_fixture: "passed"
baseline: "degree ranking recorded"
sensitivity: "sampling/direction changes recorded"
interpretation_limit:
- "structural brokerage only"
- "not causal"
- "not profit/value"
refresh_and_rollback:
cadence: "<define>"
projection_drop: "CALL gds.graph.drop(...)"
persistent_write: false
4. One end-to-end bounded Chapter 24 validation run
The following is a runbook skeleton, not fabricated output. It deliberately separates deterministic checks from measurements you must capture locally.
// 1. Verify exact versions.
RETURN gds.version() AS gdsVersion;
// 2. Inspect projection evidence.
CALL gds.graph.list('atlas-ch24-centrality')
YIELD graphName, nodeCount, relationshipCount, schemaWithOrientation, degreeDistribution
RETURN *;
// 3. Estimate chosen algorithm before running.
CALL gds.betweenness.stream.estimate('atlas-ch24-centrality', {concurrency:2})
YIELD requiredMemory, bytesMin, bytesMax
RETURN *;
// 4. Run in stream mode first: no persistent side effect.
CALL gds.betweenness.stream('atlas-ch24-centrality', {concurrency:2})
YIELD nodeId, score
RETURN gds.util.asNode(nodeId).productId AS productId, score
ORDER BY score DESC, productId;
// 5. Compare with simple degree baseline.
CALL gds.degree.stream('atlas-ch24-centrality')
YIELD nodeId, score
RETURN gds.util.asNode(nodeId).productId AS productId, score
ORDER BY score DESC, productId;
// 6. Drop the in-memory artifact when the run is complete.
CALL gds.graph.drop('atlas-ch24-centrality') YIELD graphName
RETURN graphName;
5. Sensitivity is part of correctness for heuristic/approximate analytics
| Family | Sensitivity experiment | What instability means |
|---|---|---|
| PageRank | Vary damping/weights/direction within justified ranges. | Ranking depends on model assumptions; do not present as intrinsic node truth. |
| Betweenness | Compare exact tiny graph vs sampled larger graph; vary samplingSeed/sample size. | Approximation uncertainty can reorder candidates. |
| Leiden | Repeat across randomSeed and justified gamma/theta values. | Partition is not stable enough to become a governed business segment without more evidence. |
| Louvain/LPA | Vary weight use, projection, refresh data, iteration/tolerance/seedProperty where supported. | Partition sensitivity may dominate any business interpretation. |
| KNN | Compare approximate top-k with exact small-set neighbors; vary seed/metric. | Candidate recall may be insufficient. |
| Paths | Vary cost definition and direction; validate ties and unreachable cases. | Operational answer is driven by cost model/topology, not just algorithm implementation. |
6. Deliberately wrong: compare raw algorithm scores across unrelated graphs
A PageRank score from a six-node product projection and a PageRank score from a million-node supplier graph are not on a shared business scale. Betweenness depends on graph size/path structure; community IDs are labels; similarity metrics have distinct normalization. “Score 12 is twice as important as score 6” is often unsupported.
Repair by interpreting within the algorithm/projection context, using percentiles or rank where justified, and comparing against baselines on the same task. If cross-graph comparability is a requirement, design a validated normalization/calibration scheme rather than assuming raw outputs are portable.
7. Exploration versus production decision support
| Dimension | Exploration | Production decision support |
|---|---|---|
| Projection | Fast bounded hypothesis graph | Versioned reproducible specification with freshness/SLO |
| Mode | stream/stats preferred | write only when downstream contract and rollback are defined |
| Validation | Hand fixture + qualitative inspection | Ground truth/holdout/baseline + sensitivity + drift monitoring |
| Resources | Manual estimate/observation | Capacity envelope, concurrency budget, alerts and isolation |
| Interpretation | Generate hypotheses | Governed claim with explicit non-guarantees and audit trail |
| Refresh | Ad hoc | Scheduled/event-driven with source cutoff and lineage |
8. Production checklist across the Neo4j stack
| Area | Chapter 24 gate |
|---|---|
| Graph/workload fit | Algorithms answer topology questions that would be awkward/expensive to derive repeatedly from transactional patterns. |
| Correctness | Projection schema/orientation/weights and domain identities are documented; no internal IDs as durable keys. |
| Cardinality/degree | Node/relationship counts and degree distribution recorded; hubs/outliers investigated. |
| Transactions/concurrency | GDS work isolated from transaction latency; Community max concurrency four respected. |
| Memory/CPU/disk/network | Projection and algorithm estimates plus measured process memory/CPU; data movement/result size included. |
| Indexes/constraints | Source identities/invariants protected in Neo4j; indexes support projection/source preparation where relevant. |
| Driver/timeouts/retries | If automated by an app, jobs have bounded timeouts/idempotent orchestration and do not duplicate persistent writes on retry. |
| Security/tenant risk | Projection does not combine data the caller is not entitled to analyze; GDS unrestricted procedure surface is governed. |
| Backup/recovery | Transactional source is backed up; in-memory projections are reconstructible analytical state. |
| Observability | JobId/progress, estimate, compute timing, failure, projection lifecycle, refresh age and output distribution monitored. |
| Version/edition/tier | Neo4j/GDS compatibility pinned; Aura/Enterprise features not silently assumed in Community lab. |
| Migration/rollback | New algorithm/version is shadow-evaluated; previous decision artifact retained until validation passes. |
9. Chapter 24 final verification checklist
-
Run
RETURN gds.version()and record the exact version. - For each projection, record node count, relationship count, orientation, projected properties, and degree distribution.
-
Run an
*.estimateform for the chosen algorithm before scale testing. - Validate at least one output manually: Degree, Jaccard, or a shortest route.
- Run at least one baseline and one sensitivity experiment.
- State what the output proves and what it does not prove.
-
Prefer
stream/statsuntil persistent writes are explicitly justified. - Drop Chapter-24 projections and delete only Chapter-24 fixtures.
// Drop all Chapter 24 in-memory projections first.
CALL gds.graph.list()
YIELD graphName
WITH graphName WHERE graphName STARTS WITH 'atlas-ch24-'
CALL gds.graph.drop(graphName) YIELD graphName AS dropped
RETURN dropped;
// Then delete only synthetic Chapter 24 persisted fixtures.
MATCH (n)
WHERE n.chapter24 = true
DETACH DELETE n;
MATCH (n) WHERE n.chapter24 IS NOT NULL REMOVE n.chapter24;
RETURN 'Chapter 24 reset complete' AS status;
10. Bridge to Chapter 25: algorithms become features, and leakage becomes the next risk
Chapter 24 produces structural scores, communities, similarities, and paths. Chapter 25 will use topology and graph-algorithm outputs as embeddings/features in machine-learning workflows. The analytical discipline carries forward: projection cutoff, train/test separation, reproducible randomness, feature leakage, model catalog limits, and non-graph baselines all become mandatory. A graph feature is useful only if it adds measured predictive signal without leaking future or target information.
Check your understanding
- What should determine the algorithm family first?
-
Why is
streamthe default first mode in this chapter? - What is the minimum validation pattern before scaling?
- Why is sensitivity testing part of correctness?
- What does Chapter 25 add to the risk surface?
Review the answers
1. The decision question and a falsifiable structural hypothesis, not algorithm popularity.
2. It exposes results without mutating the in-memory projection or persistent Neo4j store, making exploration easier to verify/rollback.
3. A hand-checkable fixture or exact simple baseline plus projection/configuration evidence.
4. Heuristic/approximate/parameterized algorithms can materially change rankings/partitions/candidates when data, seeds, resolution, weights or orientation change.
5. Embeddings/ML introduce train-test splits, leakage, model selection, predictive metrics and model lifecycle on top of the graph/projection assumptions.
Summary and next step
Choose an Algorithm from the Decision Question, Validate Assumptions, and Interpret Results Without Overclaiming is useful only when its assumptions and observed evidence stay attached to the decision. The examples above establish a reproducible mechanism and boundary; they do not turn one lab result into a universal production rule.
Next, continue to Node Embeddings from Topology/Properties, FastRP/Node2Vec-Like Concepts, Dimensions, and Reproducibility. Carry forward the verified assumptions, fixture state, version/edition boundaries, and measurements from this lesson instead of treating the next topic as an isolated recipe.
Authoritative references
- GDS Manual v2026.07 — Current Graph Data Science manual and release baseline.
- GDS supported Neo4j versions — Compatibility matrix mapping Neo4j 2026.07 to GDS 2026.07.
- GDS editions — Community includes all algorithms but caps concurrency at four CPU cores and the model catalog at three models; Enterprise adds operational capabilities.
- Algorithm syntax and execution modes — stream/stats/mutate/write/estimate semantics and common algorithm configuration.
- Memory estimation — Estimate memory before allocating algorithm working state.
- Centrality algorithms — Current centrality family and quality tiers.
- Degree Centrality — Degree semantics and weighted/directed behavior.
- PageRank — PageRank iteration, damping, weights, and execution modes.
- Betweenness Centrality — Exact/sampled betweenness, samplingSize/samplingSeed, memory and concurrency tradeoffs.
- Eigenvector Centrality — Transitive influence and power-iteration semantics.
- Louvain — Modularity, levels, tolerance, seeding and execution modes.
- Leiden — Community detection with gamma, theta, randomSeed and connectivity refinement.
- Label Propagation — Fast topology-driven community detection, optional weights and seeds.
- Node Similarity — Structural neighborhood similarity with Jaccard, Overlap, or Cosine.
- K-Nearest Neighbors — Property-based approximate KNN and supported metrics.
- Path finding algorithms — Current shortest path, traversal, spanning, and flow families.
- Dijkstra Source-Target — Positive-cost shortest path semantics; sourceNode/targetNodes current syntax.
- Breadth First Search — Reachability traversal, targets, maxDepth, and stream/mutate modes.
- Graph algorithm operations reference — Current procedure/function names including spanningTree and similarity functions.
- Neo4j current versions — Current Neo4j database release and 5.26 LTS line.