Introduction
Harmonic Centrality is a graph algorithm that measures the “importance” of each node based on its average closeness to all other reachable nodes in the graph. Unlike traditional Closeness Centrality, which does not work on disconnected graphs, Harmonic Centrality uses the sum of inverse distances and naturally handles unreachable nodes by treating their contribution as zero. This makes it the preferred centrality measure when working with graphs that may not be fully connected.Algorithm Overview
For each node u, the harmonic centrality score is:Note: FalkorDB computes harmonic centrality using an approximate algorithm based on HyperLogLog (HLL) sketches and GraphBLAS sparse matrix operations. Scores are estimates, not exact values, though they are typically very close to the true score for large graphs.
Syntax
NULL or omit the argument to run on the full graph.
Parameters
Yield
Examples
Basic Usage — Full Graph
Create a small directed network:
Alice has the highest score because she can reach all other nodes, and directly
reaches two of them. Bob and Charlie each reach only David (d=1) and Eve (d=2),
giving
1/1 + 1/2 = 1.50.
Filtering by Label and Relationship Type
John is not given a score, and the connection to John does not affect the score of Central.
Usage Notes
- Directed graph: The algorithm treats the graph as directed. A path from u to v does not imply a path from v to u.
- Score interpretation: Higher scores indicate nodes that are, on average, closer to more nodes. A score of 0 means the node cannot reach any other node.
reachablefield: Thereachableyield provides an estimated count of nodes reachable from each node via HLL sketch. Yield it explicitly when you need this information.- Label/type filtering: When
nodeLabelsorrelationshipTypesare provided, only matching nodes and edges participate in the computation. All named labels and types must exist in the graph, or an error is returned. - Performance: The algorithm uses sparse matrix operations and scales well on large graphs.
Frequently Asked Questions
What is harmonic centrality in a graph?
What is harmonic centrality in a graph?
Harmonic centrality measures how close a node is to every other node it can reach, by summing the inverse shortest-path distances:
H(u) = Σ 1 / d(u, v). Nodes that reach many others through short paths score highest, which makes them good hubs for information spread, influence, or access.How do I run harmonic centrality in FalkorDB?
How do I run harmonic centrality in FalkorDB?
Call
CALL algo.HarmonicCentrality() YIELD node, score. The configuration map is optional — omit it or pass NULL to run on the entire graph.What is the difference between harmonic centrality and closeness centrality?
What is the difference between harmonic centrality and closeness centrality?
Closeness centrality sums distances directly, so a single unreachable node makes the score undefined and the measure breaks on disconnected graphs. Harmonic centrality sums inverse distances and scores unreachable nodes as
0, so it works on disconnected graphs without special handling.Does harmonic centrality work on disconnected graphs?
Does harmonic centrality work on disconnected graphs?
Yes. This is its main advantage. Unreachable nodes contribute
0 to the sum instead of infinity, so disconnected components are handled naturally.Why does a node have a harmonic centrality score of 0?
Why does a node have a harmonic centrality score of 0?
A score of
0 means the node cannot reach any other node along the selected labels and relationship types. Because FalkorDB treats the graph as directed, a node with only incoming edges scores 0 even though other nodes can reach it.Are FalkorDB harmonic centrality scores exact?
Are FalkorDB harmonic centrality scores exact?
No. FalkorDB computes an approximation using HyperLogLog sketches and GraphBLAS sparse matrix operations. Scores are estimates, though they are typically very close to the true values on large graphs.
Can I run harmonic centrality on only part of my graph?
Can I run harmonic centrality on only part of my graph?
Yes. Pass
nodeLabels and relationshipTypes to restrict the computation to a subgraph — only matching nodes receive scores and only matching edges are traversed. Every label and type you name must exist in the graph, or the query returns an error.What does the reachable field return?
What does the reachable field return?
reachable is an estimated count of how many nodes can be reached from each node, derived from the HLL sketch. It is only populated when you yield it explicitly, as in YIELD node, score, reachable.