Update an existing memory: re-hash, re-embed, persist, record history.
(
&self,
memory_id: &MemoryId,
new_content: &str,
old_content: &str,
)
| 242 | |
| 243 | /// Update an existing memory: re-hash, re-embed, persist, record history. |
| 244 | async fn update_memory_internal( |
| 245 | &self, |
| 246 | memory_id: &MemoryId, |
| 247 | new_content: &str, |
| 248 | old_content: &str, |
| 249 | ) -> GraphBitResult<Memory> { |
| 250 | let hash = simple_hash(new_content); |
| 251 | self.store |
| 252 | .update_memory(memory_id, new_content, &hash) |
| 253 | .await?; |
| 254 | |
| 255 | let embedding = self.embedding_service.embed_text(new_content).await?; |
| 256 | self.vector_index.update(memory_id, embedding).await; |
| 257 | |
| 258 | self.store |
| 259 | .insert_history(&MemoryHistory { |
| 260 | memory_id: memory_id.clone(), |
| 261 | old_content: old_content.to_string(), |
| 262 | new_content: new_content.to_string(), |
| 263 | action: MemoryAction::Update, |
| 264 | timestamp: Utc::now(), |
| 265 | }) |
| 266 | .await?; |
| 267 | |
| 268 | self.store |
| 269 | .get_memory(memory_id) |
| 270 | .await? |
| 271 | .ok_or_else(|| GraphBitError::memory("Memory disappeared after update")) |
| 272 | } |
| 273 | |
| 274 | /// Delete a memory from store and index, record history. |
| 275 | async fn delete_memory_internal( |
no test coverage detected