Get all memories matching the given scope.
(&self, scope: &MemoryScope)
| 119 | |
| 120 | /// Get all memories matching the given scope. |
| 121 | pub async fn get_all_memories(&self, scope: &MemoryScope) -> GraphBitResult<Vec<Memory>> { |
| 122 | let user_id = scope.user_id.clone(); |
| 123 | let agent_id = scope.agent_id.clone(); |
| 124 | let run_id = scope.run_id.clone(); |
| 125 | let conn_arc = Arc::clone(&self.conn); |
| 126 | |
| 127 | tokio::task::spawn_blocking(move || -> GraphBitResult<Vec<Memory>> { |
| 128 | let conn = conn_arc.blocking_lock(); |
| 129 | let (where_clause, params) = build_scope_filter(&user_id, &agent_id, &run_id); |
| 130 | let sql = format!( |
| 131 | "SELECT id, content, user_id, agent_id, run_id, hash, metadata, created_at, updated_at FROM memories{}", |
| 132 | where_clause |
| 133 | ); |
| 134 | let mut stmt = conn.prepare(&sql)?; |
| 135 | let param_refs: Vec<&dyn rusqlite::types::ToSql> = |
| 136 | params.iter().map(|p| p as &dyn rusqlite::types::ToSql).collect(); |
| 137 | let mut rows = stmt.query(param_refs.as_slice())?; |
| 138 | let mut memories = Vec::new(); |
| 139 | while let Some(row) = rows.next()? { |
| 140 | memories.push(row_to_memory(row)?); |
| 141 | } |
| 142 | Ok(memories) |
| 143 | }) |
| 144 | .await |
| 145 | .map_err(|e| GraphBitError::memory(format!("Join error: {e}")))? |
| 146 | } |
| 147 | |
| 148 | /// Update content and metadata of an existing memory. |
| 149 | pub async fn update_memory( |