Create a brand-new memory: hash, embed, store, index, record history.
(
&self,
content: &str,
scope: MemoryScope,
)
| 204 | |
| 205 | /// Create a brand-new memory: hash, embed, store, index, record history. |
| 206 | async fn create_memory( |
| 207 | &self, |
| 208 | content: &str, |
| 209 | scope: MemoryScope, |
| 210 | ) -> GraphBitResult<Memory> { |
| 211 | let now = Utc::now(); |
| 212 | let hash = simple_hash(content); |
| 213 | let id = MemoryId::new(); |
| 214 | |
| 215 | let memory = Memory { |
| 216 | id: id.clone(), |
| 217 | content: content.to_string(), |
| 218 | scope, |
| 219 | metadata: HashMap::new(), |
| 220 | created_at: now, |
| 221 | updated_at: now, |
| 222 | hash, |
| 223 | }; |
| 224 | |
| 225 | self.store.insert_memory(&memory).await?; |
| 226 | |
| 227 | let embedding = self.embedding_service.embed_text(content).await?; |
| 228 | self.vector_index.insert(id.clone(), embedding).await; |
| 229 | |
| 230 | self.store |
| 231 | .insert_history(&MemoryHistory { |
| 232 | memory_id: id, |
| 233 | old_content: String::new(), |
| 234 | new_content: content.to_string(), |
| 235 | action: MemoryAction::Add, |
| 236 | timestamp: now, |
| 237 | }) |
| 238 | .await?; |
| 239 | |
| 240 | Ok(memory) |
| 241 | } |
| 242 | |
| 243 | /// Update an existing memory: re-hash, re-embed, persist, record history. |
| 244 | async fn update_memory_internal( |
no test coverage detected