brainwires_cognition/knowledge/
types.rs1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3
4#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
8pub struct CaptureThoughtRequest {
9 pub content: String,
11 #[serde(default)]
14 pub category: Option<String>,
15 #[serde(default)]
17 pub tags: Option<Vec<String>>,
18 #[serde(default)]
20 pub importance: Option<f32>,
21 #[serde(default)]
23 pub source: Option<String>,
24}
25
26#[derive(Debug, Clone, Serialize, Deserialize)]
28pub struct CaptureThoughtResponse {
29 pub id: String,
31 pub category: String,
33 pub tags: Vec<String>,
35 pub importance: f32,
37 pub facts_extracted: usize,
39}
40
41#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
45pub struct SearchMemoryRequest {
46 pub query: String,
48 #[serde(default = "default_limit")]
50 pub limit: usize,
51 #[serde(default = "default_min_score")]
53 pub min_score: f32,
54 #[serde(default)]
56 pub category: Option<String>,
57 #[serde(default)]
59 pub sources: Option<Vec<String>>,
60}
61
62#[derive(Debug, Clone, Serialize, Deserialize)]
64pub struct SearchMemoryResponse {
65 pub results: Vec<MemorySearchResult>,
67 pub total: usize,
69}
70
71#[derive(Debug, Clone, Serialize, Deserialize)]
73pub struct MemorySearchResult {
74 pub content: String,
76 pub score: f32,
78 pub source: String,
80 #[serde(skip_serializing_if = "Option::is_none")]
82 pub thought_id: Option<String>,
83 #[serde(skip_serializing_if = "Option::is_none")]
85 pub category: Option<String>,
86 #[serde(skip_serializing_if = "Option::is_none")]
88 pub tags: Option<Vec<String>>,
89 #[serde(skip_serializing_if = "Option::is_none")]
91 pub created_at: Option<i64>,
92}
93
94#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
98pub struct ListRecentRequest {
99 #[serde(default = "default_list_limit")]
101 pub limit: usize,
102 #[serde(default)]
104 pub category: Option<String>,
105 #[serde(default)]
107 pub since: Option<String>,
108}
109
110#[derive(Debug, Clone, Serialize, Deserialize)]
112pub struct ListRecentResponse {
113 pub thoughts: Vec<ThoughtSummary>,
115 pub total: usize,
117}
118
119#[derive(Debug, Clone, Serialize, Deserialize)]
121pub struct ThoughtSummary {
122 pub id: String,
124 pub content: String,
126 pub category: String,
128 pub tags: Vec<String>,
130 pub importance: f32,
132 pub created_at: i64,
134}
135
136#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
140pub struct GetThoughtRequest {
141 pub id: String,
143}
144
145#[derive(Debug, Clone, Serialize, Deserialize)]
147pub struct GetThoughtResponse {
148 pub id: String,
150 pub content: String,
152 pub category: String,
154 pub tags: Vec<String>,
156 pub source: String,
158 pub importance: f32,
160 pub created_at: i64,
162 pub updated_at: i64,
164}
165
166#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
170pub struct SearchKnowledgeRequest {
171 pub query: String,
173 #[serde(default)]
175 pub source: Option<String>,
176 #[serde(default)]
178 pub category: Option<String>,
179 #[serde(default = "default_min_confidence")]
181 pub min_confidence: f32,
182 #[serde(default = "default_limit")]
184 pub limit: usize,
185}
186
187#[derive(Debug, Clone, Serialize, Deserialize)]
189pub struct SearchKnowledgeResponse {
190 pub results: Vec<KnowledgeResult>,
192 pub total: usize,
194}
195
196#[derive(Debug, Clone, Serialize, Deserialize)]
198pub struct KnowledgeResult {
199 pub source: String,
201 pub category: String,
203 pub key: String,
205 pub value: String,
207 pub confidence: f32,
209 #[serde(skip_serializing_if = "Option::is_none")]
211 pub context: Option<String>,
212}
213
214#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
219pub struct MemoryStatsRequest {}
220
221#[derive(Debug, Clone, Serialize, Deserialize)]
223pub struct MemoryStatsResponse {
224 pub thoughts: ThoughtStats,
226 pub pks: PksStats,
228 pub bks: BksStats,
230}
231
232#[derive(Debug, Clone, Serialize, Deserialize)]
234pub struct ThoughtStats {
235 pub total: usize,
237 pub by_category: std::collections::HashMap<String, usize>,
239 pub recent_24h: usize,
241 pub recent_7d: usize,
243 pub recent_30d: usize,
245 pub top_tags: Vec<(String, usize)>,
247}
248
249#[derive(Debug, Clone, Serialize, Deserialize)]
251pub struct PksStats {
252 pub total_facts: u32,
254 pub by_category: std::collections::HashMap<String, u32>,
256 pub avg_confidence: f32,
258}
259
260#[derive(Debug, Clone, Serialize, Deserialize)]
262pub struct BksStats {
263 pub total_truths: u32,
265 pub by_category: std::collections::HashMap<String, u32>,
267}
268
269#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
273pub struct DeleteThoughtRequest {
274 pub id: String,
276}
277
278#[derive(Debug, Clone, Serialize, Deserialize)]
280pub struct DeleteThoughtResponse {
281 pub deleted: bool,
283 pub id: String,
285}
286
287fn default_limit() -> usize {
290 10
291}
292
293fn default_list_limit() -> usize {
294 20
295}
296
297fn default_min_score() -> f32 {
298 0.6
299}
300
301fn default_min_confidence() -> f32 {
302 0.5
303}