Skip to main content

origin_types/
entities.rs

1// SPDX-License-Identifier: Apache-2.0
2//! Knowledge graph types -- entities, observations, relations.
3
4use serde::{Deserialize, Serialize};
5
6/// A knowledge graph entity.
7#[derive(Debug, Clone, Serialize, Deserialize)]
8pub struct Entity {
9    pub id: String,
10    pub name: String,
11    pub entity_type: String,
12    #[serde(default, alias = "domain")]
13    pub space: Option<String>,
14    pub source_agent: Option<String>,
15    pub confidence: Option<f32>,
16    pub confirmed: bool,
17    pub created_at: i64,
18    pub updated_at: i64,
19}
20
21/// An entity search result with distance score.
22#[derive(Debug, Clone, Serialize, Deserialize)]
23pub struct EntitySearchResult {
24    pub entity: Entity,
25    pub distance: f32,
26}
27
28/// Full entity detail including observations and relations.
29#[derive(Debug, Clone, Serialize, Deserialize)]
30pub struct EntityDetail {
31    pub entity: Entity,
32    pub observations: Vec<Observation>,
33    pub relations: Vec<RelationWithEntity>,
34}
35
36/// An observation attached to an entity.
37#[derive(Debug, Clone, Serialize, Deserialize)]
38pub struct Observation {
39    pub id: String,
40    pub entity_id: String,
41    pub content: String,
42    pub source_agent: Option<String>,
43    pub confidence: Option<f32>,
44    pub confirmed: bool,
45    pub created_at: i64,
46}
47
48/// A relation between two entities.
49#[derive(Debug, Clone, Serialize, Deserialize)]
50pub struct Relation {
51    pub id: String,
52    pub from_entity: String,
53    pub to_entity: String,
54    pub relation_type: String,
55    pub source_agent: Option<String>,
56    pub created_at: i64,
57}
58
59/// A relation with resolved entity info (for detail views).
60#[derive(Debug, Clone, Serialize, Deserialize)]
61pub struct RelationWithEntity {
62    pub id: String,
63    pub relation_type: String,
64    pub direction: String,
65    pub entity_id: String,
66    pub entity_name: String,
67    pub entity_type: String,
68    pub source_agent: Option<String>,
69    pub created_at: i64,
70}
71
72/// A relation with both entity names resolved, for the home page connections feed.
73#[derive(Debug, Clone, Serialize, Deserialize)]
74pub struct RecentRelation {
75    pub id: String,
76    pub from_entity_id: String,
77    pub relation_type: String,
78    pub to_entity_id: String,
79    pub from_entity_name: String,
80    pub to_entity_name: String,
81    /// Unix seconds (same unit as the `created_at` column in the `relations` table).
82    pub created_at_ms: i64,
83}
84
85/// A pending entity suggestion from the refinement queue.
86#[derive(Debug, Serialize, Deserialize)]
87pub struct EntitySuggestion {
88    pub id: String,
89    pub entity_name: Option<String>,
90    pub source_ids: Vec<String>,
91    pub confidence: f64,
92    pub created_at: String,
93}