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