Overview
TheCommunity class represents a cluster of related entities in the knowledge graph. Communities are detected using graph algorithms and form a hierarchical structure with parent-child relationships. Each community aggregates entities, relationships, and text units that are semantically related.
Communities inherit from the Named base class, which provides id, short_id, and title fields.
Schema
Core fields
string
required
Unique identifier for the community.
string | null
Human-readable ID used to refer to this community in prompts or texts displayed to users, such as in a report text.
string
required
The name/title of the community, typically describing its theme or topic.
Hierarchy
string
required
Community level in the hierarchical structure. Lower levels contain more granular communities, while higher levels represent broader themes.
string
required
Community ID of the parent node of this community in the hierarchy. Root-level communities may have a null or special parent value.
string[]
required
List of community IDs of the child nodes of this community. Leaf communities have an empty list.
Relationships
string[]
List of entity IDs that belong to this community. These are the entities clustered together based on their relationships.
string[]
List of relationship IDs that connect entities within this community.
string[]
List of text unit IDs related to the community. These are the source text chunks that mention entities or relationships in this community.
object
Dictionary mapping covariate types to lists of covariate IDs. For example,
{"claim": ["claim1", "claim2"]} associates claims with the community.Metadata
object
A dictionary of additional attributes associated with the community. These attributes are included in search prompts and can contain custom metadata.
integer
The size of the community, measured as the number of text units associated with it. Larger communities represent more prevalent themes.
string
Temporal period associated with the community, if applicable.
Example
Creating from dictionary
TheCommunity class provides a from_dict() class method to create instances from dictionary data:
Hierarchical structure
Communities form a tree structure where:- Leaf communities (level 0): Most specific clusters with no children
- Intermediate communities: Aggregate multiple child communities
- Root communities: Top-level themes that encompass broad topics
Use cases
- Summarization: Generate summaries at different levels of detail
- Topic clustering: Group related entities and relationships by theme
- Hierarchical search: Query at appropriate abstraction levels
- Context aggregation: Combine information from related text units