Skip to main content

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:
where d(u, v) is the shortest-path distance from u to v. If v is unreachable from u, the term is 0. Nodes with high harmonic centrality scores are “close” to many other nodes on average, making them effective hubs for information spread, influence, or access within the graph.
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

The configuration argument is optional. Pass NULL or omit the argument to run on the full graph.

Parameters

Yield

Examples

Basic Usage — Full Graph

Create a small directed network:
Run harmonic centrality across all nodes and relationships:
Expected results: 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

Expected results: 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.
  • reachable field: The reachable yield 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 nodeLabels or relationshipTypes are 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.