Algorithm
Leiden community detection
activeNeeds verification
Refinement of Louvain that guarantees well-connected communities and converges to better partitions; used for community summaries in Microsoft GraphRAG.
Definition
Intuition
Like Louvain, but adds a refinement phase that may split communities so every community stays internally connected.
Complexity
| Time | Near-linear in E in practice |
|---|---|
| Space | O(V + E) |
Python
import igraph as ig
g = ig.Graph.Famous('Zachary')
part = g.community_leiden(objective_function='modularity')Cypher (Neo4j GDS)
CALL gds.leiden.stream('myGraph')
YIELD nodeId, communityId RETURN communityId, count(*) AS sizeProcedure names and options vary between GDS versions; check the GDS docs for your version.
An interactive step-by-step visualizer for this algorithm is planned for phase 3.
Profile
| Time complexity | Near-linear in E in practice |
|---|---|
| Space complexity | O(V + E) |
Relationships
- Belongs to
- Prerequisite of
- Part of
- Succeeds
- Louvain community detection(Algorithm)— Leiden fixes badly connected communities
- Implemented by
- igraph(Library / framework)
- Microsoft GraphRAG(Library / framework)
- Neo4j Graph Data Science(Library / framework)
- Related
- Leiden algorithm(Timeline event)