1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
//! Engine::inspect — diagnostics API (05 §6, 09 §4.5).
use crate::{Engine, EngineResult, InspectQuery};
use hippmem_core::model::links::RecallChannel;
impl Engine {
/// Diagnostic query: StoreStats/QueueStatus, etc.
pub fn inspect(&self, query: InspectQuery) -> EngineResult<crate::InspectReport> {
match query {
InspectQuery::StoreStats => {
let units = crate::retrieve_api::load_all_units(self.store.db_arc());
let mut edge_count = 0u64;
for u in &units {
edge_count += u.links.len() as u64;
}
Ok(crate::InspectReport::StoreStats(crate::StoreStats {
memory_count: units.len() as u64,
edge_count,
observing_edge_count: 0,
per_index_size: vec![
(RecallChannel::Bm25, 0),
(RecallChannel::EntityInverted, 0),
],
queue_backlog: 0,
store_bytes: 0,
}))
}
InspectQuery::QueueStatus => {
Ok(crate::InspectReport::QueueStatus(crate::QueueStatus {
pending_enrich: 0,
pending_consolidate: 0,
in_flight: 0,
oldest_pending_age_ms: 0,
}))
}
InspectQuery::Memory(id) => {
let units = crate::retrieve_api::load_all_units(self.store.db_arc());
let unit = units
.iter()
.find(|u| u.id == id)
.cloned()
.ok_or(crate::EngineError::NotFound(id))?;
let out_edges: Vec<crate::EdgeView> = unit
.links
.iter()
.map(|l| crate::EdgeView {
from: unit.id,
to: l.target_id,
link_type: l.link_type,
strength: l.strength.value(),
confidence: l.confidence.value(),
activation_count: l.activation_count,
evidence: l.evidence.note.clone().unwrap_or_default(),
})
.collect();
// In-edges: iterate over all memories, finding edges where target_id == queried id
let in_edges: Vec<crate::EdgeView> = units
.iter()
.flat_map(|other| {
other.links.iter().filter_map(move |l| {
if l.target_id == id {
Some(crate::EdgeView {
from: other.id,
to: l.target_id,
link_type: l.link_type,
strength: l.strength.value(),
confidence: l.confidence.value(),
activation_count: l.activation_count,
evidence: l.evidence.note.clone().unwrap_or_default(),
})
} else {
None
}
})
})
.collect();
let stage = unit.stage;
let lifecycle = unit.lifecycle.clone();
Ok(crate::InspectReport::Memory(Box::new(
crate::MemoryInspect {
unit,
out_edges,
in_edges,
stage,
lifecycle,
},
)))
}
_ => Ok(crate::InspectReport::StoreStats(crate::StoreStats {
memory_count: 0,
edge_count: 0,
observing_edge_count: 0,
per_index_size: vec![],
queue_backlog: 0,
store_bytes: 0,
})),
}
}
}