Overview
TheRelationship class represents an edge in the knowledge graph, connecting two entities. Relationships are extracted from documents and describe how entities are related to each other. Each relationship has a source entity, target entity, and optional weight indicating the strength of the connection.
Relationships inherit from the Identified base class, which provides id and short_id fields.
Schema
Core fields
Unique identifier for the relationship.
Human-readable ID used to refer to this relationship in prompts or texts displayed to users.
The source entity name. This is the entity from which the relationship originates.
The target entity name. This is the entity to which the relationship points.
The edge weight indicating the strength or importance of the relationship. Higher values indicate stronger connections.
A textual description of the relationship explaining the nature of the connection between source and target entities.
Embeddings
The semantic embedding vector for the relationship description. Used for similarity search and semantic queries.
Relationships
List of text unit IDs in which the relationship appears. Links the relationship back to its source text chunks.
Metadata
Rank of the relationship, used for sorting and prioritization. Higher rank indicates more important relationship. This can be based on centrality or other metrics.
Additional attributes associated with the relationship. These attributes are included in search prompts and can contain custom metadata.
Example
Creating from dictionary
TheRelationship class provides a from_dict() class method to create instances from dictionary data:
Use cases
Relationships are used throughout GraphRAG for:- Graph traversal: Following connections between entities during search
- Community detection: Identifying clusters of related entities
- Importance ranking: Using edge weights to prioritize relevant information
- Context retrieval: Accessing source text through text_unit_ids