Insert a new memory.
(&self, memory: &Memory)
| 73 | |
| 74 | /// Insert a new memory. |
| 75 | pub async fn insert_memory(&self, memory: &Memory) -> GraphBitResult<()> { |
| 76 | let id = memory.id.to_string(); |
| 77 | let content = memory.content.clone(); |
| 78 | let user_id = memory.scope.user_id.clone(); |
| 79 | let agent_id = memory.scope.agent_id.clone(); |
| 80 | let run_id = memory.scope.run_id.clone(); |
| 81 | let hash = memory.hash.clone(); |
| 82 | let metadata = serde_json::to_string(&memory.metadata)?; |
| 83 | let created_at = memory.created_at.to_rfc3339(); |
| 84 | let updated_at = memory.updated_at.to_rfc3339(); |
| 85 | |
| 86 | let conn_arc = Arc::clone(&self.conn); |
| 87 | tokio::task::spawn_blocking(move || -> GraphBitResult<()> { |
| 88 | let conn = conn_arc.blocking_lock(); |
| 89 | conn.execute( |
| 90 | "INSERT INTO memories (id, content, user_id, agent_id, run_id, hash, metadata, created_at, updated_at) |
| 91 | VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9)", |
| 92 | rusqlite::params![id, content, user_id, agent_id, run_id, hash, metadata, created_at, updated_at], |
| 93 | )?; |
| 94 | Ok(()) |
| 95 | }) |
| 96 | .await |
| 97 | .map_err(|e| GraphBitError::memory(format!("Join error: {e}")))? |
| 98 | } |
| 99 | |
| 100 | /// Get a single memory by ID. |
| 101 | pub async fn get_memory(&self, memory_id: &MemoryId) -> GraphBitResult<Option<Memory>> { |