Skip to main content

What are Communities?

Communities in Graphiti are automatically detected clusters of related entities discovered through graph analysis. Think of them as topics or themes that emerge organically from your knowledge graph without manual categorization. For example, in a graph containing information about California politics, Graphiti might detect:
  • A community of “California State Government Officials”
  • A community of “San Francisco Political Figures”
  • A community of “Technology Industry Leaders”

How Communities Work

Label Propagation Algorithm

Graphiti uses label propagation, a graph clustering algorithm that groups entities based on their connectivity:
  1. Initialize: Each entity starts in its own community
  2. Propagate: Each entity adopts the most common community label among its neighbors
  3. Iterate: Repeat until community assignments stabilize
  4. Summarize: Generate natural language descriptions for each community

Example

Consider these entities and relationships:
Label propagation will cluster these into a single community because they’re densely connected.

Community Schema

CommunityNode

Example

CommunityEdge (HAS_MEMBER)

These edges link communities to their member entities.

Building Communities

Bulk Community Detection

Generate communities for all entities in your graph:
Community building is a compute-intensive operation. For large graphs, consider running it as a background job or on a schedule rather than after every episode.

Incremental Community Updates

Update communities as you add new entities:
Setting update_communities=True adds latency to add_episode(). Use it when you need real-time community updates, otherwise run build_communities() periodically.

Community Generation Process

1. Graph Projection

Graphiti builds a weighted graph projection:
Example projection:

2. Cluster Detection

3. Summary Generation

For each cluster, Graphiti:
  1. Collects entity summaries:
  2. Hierarchically merges summaries using LLM:
  3. Generates community name:

4. Embedding Generation

Enables semantic search over communities.

Querying Communities

Find All Communities

Get Community Members

Find Entity’s Community

Updating Communities

Update Specific Community

When a new entity joins a community:
This:
  1. Determines which community the entity belongs to (based on neighbors)
  2. Merges the entity’s summary with the community summary
  3. Regenerates the community name
  4. Updates embeddings

Rebuild All Communities

Remove old communities and regenerate:
Rebuilding communities from scratch is useful after major changes to your graph structure or when community quality degrades over time.
Communities enable high-level topic retrieval:

Expand Community to Members

Use Cases

1. Topic Discovery

Identify themes in your knowledge graph:

2. Hierarchical Navigation

Browse from communities down to entities:

3. Contextual Retrieval

Use communities to scope search:

4. Graph Summarization

Provide high-level overviews:

Performance Considerations

Concurrency Control

Community building is parallelized but rate-limited:

Graph Size Impact

For large graphs (>10,000 entities):
  • Label propagation scales to O(E) where E = number of edges
  • Summary generation scales to O(C * log(M)) where C = communities, M = avg members per community
For graphs with >50,000 entities, consider:
  • Running community detection on subgraphs (per group_id)
  • Using scheduled batch jobs instead of real-time updates
  • Increasing MAX_COMMUNITY_BUILD_CONCURRENCY if your LLM provider allows higher throughput

Algorithm Details

Edge Weight Consideration

The label propagation algorithm weights neighbor votes by edge count:
Entities with more connections to a community have stronger influence.

Tie Breaking

When multiple communities have equal votes:
The largest community wins ties, favoring consolidation.

Convergence

The algorithm terminates when assignments stop changing:
Typically converges in 5-10 iterations for most graphs.

Best Practices

1. Run Community Detection Periodically

2. Use Group IDs for Isolation

3. Monitor Community Quality

Removing Communities

Delete all communities (keeps entities intact):

Source Code Reference

Key implementation files:
  • Label propagation: graphiti_core/utils/maintenance/community_operations.py:92
  • Community building: graphiti_core/utils/maintenance/community_operations.py:217
  • Summary generation: graphiti_core/utils/maintenance/community_operations.py:140
  • Community updates: graphiti_core/utils/maintenance/community_operations.py:326

Next Steps

Build Communities

Step-by-step guide to building and using communities

Nodes and Edges

Understand the complete graph schema

Search

Use communities in search queries

Knowledge Graphs

Back to knowledge graph fundamentals