| 394 | const STORAGE_DEDUP_THRESHOLD: f32 = 0.85; |
| 395 | |
| 396 | pub fn remember_project(&self, entry: MemoryEntry) -> Result<String> { |
| 397 | let mut entry = entry; |
| 398 | if self.should_generate_embedding_for_entry(&entry) { |
| 399 | entry.ensure_embedding(); |
| 400 | } |
| 401 | |
| 402 | let mut graph = self.load_project_graph()?; |
| 403 | |
| 404 | if let Some(ref emb) = entry.embedding { |
| 405 | if let Some(existing_id) = |
| 406 | Self::find_duplicate_in_graph(&graph, emb, Self::STORAGE_DEDUP_THRESHOLD) |
| 407 | && let Some(existing) = graph.get_memory_mut(&existing_id) |
| 408 | { |
| 409 | existing.reinforce(entry.source.as_deref().unwrap_or("dedup"), 0); |
| 410 | self.save_project_graph(&graph)?; |
| 411 | return Ok(existing_id); |
| 412 | } |
| 413 | |
| 414 | // Cross-store dedup: also check global graph |
| 415 | if let Ok(mut global_graph) = self.load_global_graph() |
| 416 | && let Some(existing_id) = |
| 417 | Self::find_duplicate_in_graph(&global_graph, emb, Self::STORAGE_DEDUP_THRESHOLD) |
| 418 | && let Some(existing) = global_graph.get_memory_mut(&existing_id) |
| 419 | { |
| 420 | existing.reinforce(entry.source.as_deref().unwrap_or("cross-dedup"), 0); |
| 421 | self.save_global_graph(&global_graph)?; |
| 422 | return Ok(existing_id); |
| 423 | } |
| 424 | } |
| 425 | |
| 426 | let id = graph.add_memory(entry); |
| 427 | self.save_project_graph(&graph)?; |
| 428 | Ok(id) |
| 429 | } |
| 430 | |
| 431 | pub fn remember_global(&self, entry: MemoryEntry) -> Result<String> { |
| 432 | let mut entry = entry; |