relay_knowledge/domain/graph/retrieval/
evidence.rs1use serde::{Deserialize, Serialize};
2
3use super::super::{ConfidenceScore, FactStatus, GraphVersionRange};
4
5#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
7pub struct ContextEntity {
8 pub id: String,
9 pub label: String,
10}
11
12#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
14#[serde(rename_all = "snake_case")]
15pub enum ContextGraphFactKind {
16 Relation,
17 Claim,
18 Event,
19}
20
21impl ContextGraphFactKind {
22 pub const fn as_str(self) -> &'static str {
23 match self {
24 Self::Relation => "relation",
25 Self::Claim => "claim",
26 Self::Event => "event",
27 }
28 }
29}
30
31#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
33pub struct ContextGraphFact {
34 pub fact_id: String,
35 pub kind: ContextGraphFactKind,
36 pub subject: String,
37 pub predicate: String,
38 #[serde(skip_serializing_if = "Option::is_none")]
39 pub object: Option<String>,
40 pub evidence_ids: Vec<String>,
41 pub confidence: ConfidenceScore,
42 pub status: FactStatus,
43 pub version_range: GraphVersionRange,
44}
45
46#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
48pub struct ContextGraphPath {
49 pub path_id: String,
50 pub nodes: Vec<String>,
51 pub edges: Vec<ContextGraphPathEdge>,
52}
53
54#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
56pub struct ContextGraphPathEdge {
57 pub fact_id: String,
58 pub kind: ContextGraphFactKind,
59 pub from: String,
60 pub predicate: String,
61 #[serde(skip_serializing_if = "Option::is_none")]
62 pub to: Option<String>,
63 pub evidence_ids: Vec<String>,
64 pub confidence: ConfidenceScore,
65 pub status: FactStatus,
66 pub version_range: GraphVersionRange,
67}
68
69impl ContextGraphPath {
70 pub fn from_fact(fact: &ContextGraphFact) -> Self {
72 let mut nodes = vec![fact.subject.clone()];
73 if let Some(object) = &fact.object
74 && !nodes.contains(object)
75 {
76 nodes.push(object.clone());
77 }
78
79 Self {
80 path_id: format!("path:{}", fact.fact_id),
81 nodes,
82 edges: vec![ContextGraphPathEdge {
83 fact_id: fact.fact_id.clone(),
84 kind: fact.kind,
85 from: fact.subject.clone(),
86 predicate: fact.predicate.clone(),
87 to: fact.object.clone(),
88 evidence_ids: fact.evidence_ids.clone(),
89 confidence: fact.confidence,
90 status: fact.status,
91 version_range: fact.version_range,
92 }],
93 }
94 }
95}
96
97#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
99#[serde(rename_all = "snake_case")]
100pub enum CodeGraphArtifactKind {
101 Symbol,
102 Chunk,
103}
104
105impl CodeGraphArtifactKind {
106 pub const fn as_str(self) -> &'static str {
107 match self {
108 Self::Symbol => "symbol",
109 Self::Chunk => "chunk",
110 }
111 }
112}
113
114#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
116pub struct CodeGraphArtifact {
117 pub kind: CodeGraphArtifactKind,
118 pub artifact_id: String,
119 pub path: String,
120}
121
122#[cfg(test)]
123#[path = "evidence_tests.rs"]
124mod tests;