Entity Model¶
Stores resolved identities (people, organizations, places, etc.).
Class: FactDb::Models::Entity¶
Attributes¶
| Attribute | Type | Description |
|---|---|---|
id |
Integer | Primary key |
name |
String | Authoritative name |
kind |
String | Kind (person, organization, place, etc.) |
resolution_status |
String | Status (unresolved, resolved, merged) |
canonical_id |
Integer | Points to canonical entity if merged |
metadata |
Hash | Additional attributes (JSONB) |
embedding |
Vector | Semantic search vector |
created_at |
DateTime | Record creation time |
Entity Kinds¶
person- Individual peopleorganization- Companies, teams, groupsplace- Locationsproduct- Products, servicesevent- Named events
Resolution Status¶
unresolved- Entity created but not confirmedresolved- Entity identity confirmedmerged- Entity merged into another
Associations¶
has_many :entity_aliases, dependent: :destroy
has_many :entity_mentions
has_many :facts, through: :entity_mentions
belongs_to :merged_into, class_name: 'Entity', optional: true
Instance Methods¶
add_alias¶
Add an alias to the entity.
Example:
merged?¶
Returns true if entity has been merged into another.
canonical¶
Returns the canonical entity (follows merge chain).
Example:
Scopes¶
by_kind¶
Filter by entity kind.
active¶
Exclude merged entities.
resolved¶
Only resolved entities.
search_name¶
Search by name.
Usage Examples¶
Create Entity¶
entity = Entity.create!(
name: "Paula Chen",
kind: "person",
metadata: {
department: "Engineering",
employee_id: "E12345"
}
)
Add Aliases¶
entity.add_alias("Paula")
entity.add_alias("P. Chen", kind: "abbreviation")
entity.add_alias("Chen, Paula", kind: "formal")
Check Aliases¶
Get Related Facts¶
Find Similar Entities¶
# By name
similar = Entity.search_name("Microsoft")
# By embedding
similar = Entity
.where.not(embedding: nil)
.order(Arel.sql("embedding <=> '#{query_embedding}'"))
.limit(10)