sqlite_graphrag/storage/memories/rows.rs
1//! Typed row shapes exchanged with the `memories` table.
2
3use serde::{Deserialize, Serialize};
4
5/// Input payload for inserting or updating a memory.
6///
7/// `body_hash` must be the BLAKE3 digest of `body`. The `metadata` field is
8/// stored as a TEXT column containing JSON.
9#[derive(Debug, Serialize, Deserialize)]
10pub struct NewMemory {
11 /// Namespace scope.
12 pub namespace: String,
13 /// Name of this item.
14 pub name: String,
15 /// Memory type classification.
16 pub memory_type: String,
17 /// Human-readable description.
18 pub description: String,
19 /// Full text body.
20 pub body: String,
21 /// Body hash.
22 pub body_hash: String,
23 /// Session ID.
24 pub session_id: Option<String>,
25 /// Source side of the relationship.
26 pub source: String,
27 /// Arbitrary metadata.
28 pub metadata: serde_json::Value,
29}
30
31/// Fully materialized row from the `memories` table.
32///
33/// Returned by `read_by_name`, `read_full`, `list` and `fts_search`.
34/// The `metadata` field is kept as a JSON string to avoid double parsing.
35#[derive(Debug, Serialize)]
36pub struct MemoryRow {
37 /// Unique identifier.
38 pub id: i64,
39 /// Namespace scope.
40 pub namespace: String,
41 /// Name of this item.
42 pub name: String,
43 /// Memory type classification.
44 pub memory_type: String,
45 /// Human-readable description.
46 pub description: String,
47 /// Full text body.
48 pub body: String,
49 /// Body hash.
50 pub body_hash: String,
51 /// Session ID.
52 pub session_id: Option<String>,
53 /// Source side of the relationship.
54 pub source: String,
55 /// Arbitrary metadata.
56 pub metadata: String,
57 /// Creation timestamp.
58 pub created_at: i64,
59 /// Last-update timestamp.
60 pub updated_at: i64,
61 /// Unix epoch when the memory was soft-deleted, or `None` for active memories.
62 /// Surfaced in `list --include-deleted --json` so LLM consumers can distinguish
63 /// active from soft-deleted rows without a second SQL query (v1.0.37 H7+M9 fix).
64 #[serde(skip_serializing_if = "Option::is_none")]
65 pub deleted_at: Option<i64>,
66}