llm_brain/models.rs
1// src/models.rs
2// Define core data structures here (e.g., MemoryFragment)
3
4use serde::{Deserialize, Serialize};
5use serde_json::Value as JsonValue;
6
7// Helper function for serde default
8fn json_null() -> JsonValue {
9 JsonValue::Null
10}
11
12/// Represents a single piece of memory stored in the database.
13#[derive(Serialize, Deserialize, Debug, Clone)]
14pub struct MemoryFragment {
15 /// The textual content of the memory fragment.
16 pub content: String,
17
18 /// The vector embedding representing the content's semantics.
19 pub embedding: Vec<f32>,
20
21 /// Flexible field for storing additional metadata (tags, source, etc.).
22 pub metadata: JsonValue,
23
24 /// Timestamp when the memory fragment was created (handled as `JsonValue`).
25 #[serde(default = "json_null")]
26 pub created_at: JsonValue,
27
28 /// Timestamp when the memory fragment was last accessed (handled as
29 /// `JsonValue`).
30 #[serde(default = "json_null")]
31 pub last_accessed_at: JsonValue, // Use JsonValue::Null for Option::None
32}
33
34impl MemoryFragment {
35 /// Creates a new `MemoryFragment`. Timestamps treated as `JsonValue`.
36 pub fn new(content: String, embedding: Vec<f32>, metadata: JsonValue) -> Self {
37 Self {
38 content,
39 embedding,
40 metadata,
41 created_at: JsonValue::Null, // Default to Null, DB handles actual value
42 last_accessed_at: JsonValue::Null, // Default to Null
43 }
44 }
45}
46
47// Example of a more structured metadata type (alternative to JsonValue)
48// #[derive(Serialize, Deserialize, Debug, Clone, Default)]
49// pub struct Metadata {
50// pub source: Option<String>,
51// pub tags: Vec<String>,
52// // Add other common fields here
53// }