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:- Initialize: Each entity starts in its own community
- Propagate: Each entity adopts the most common community label among its neighbors
- Iterate: Repeat until community assignments stabilize
- Summarize: Generate natural language descriptions for each community
Example
Consider these entities and relationships:Community Schema
CommunityNode
Example
CommunityEdge (HAS_MEMBER)
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:2. Cluster Detection
3. Summary Generation
For each cluster, Graphiti:-
Collects entity summaries:
-
Hierarchically merges summaries using LLM:
-
Generates community name:
4. Embedding Generation
Querying Communities
Find All Communities
Get Community Members
Find Entity’s Community
Updating Communities
Update Specific Community
When a new entity joins a community:- Determines which community the entity belongs to (based on neighbors)
- Merges the entity’s summary with the community summary
- Regenerates the community name
- Updates embeddings
Rebuild All Communities
Remove old communities and regenerate:Community-Based Search
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_CONCURRENCYif your LLM provider allows higher throughput
Algorithm Details
Edge Weight Consideration
The label propagation algorithm weights neighbor votes by edge count:Tie Breaking
When multiple communities have equal votes:Convergence
The algorithm terminates when assignments stop changing:Best Practices
1. Run Community Detection Periodically
2. Use Group IDs for Isolation
3. Monitor Community Quality
4. Combine with Search
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