TrackMemory 追踪一个新记忆。
(memoryID string, metadata *LineageMetadata)
| 46 | |
| 47 | // TrackMemory 追踪一个新记忆。 |
| 48 | func (lg *LineageGraph) TrackMemory(memoryID string, metadata *LineageMetadata) { |
| 49 | lg.mu.Lock() |
| 50 | defer lg.mu.Unlock() |
| 51 | |
| 52 | lg.memoryMetadata[memoryID] = metadata |
| 53 | |
| 54 | // 建立派生关系 |
| 55 | for _, parentID := range metadata.DerivedFromIDs { |
| 56 | if _, exists := lg.parentToChildren[parentID]; !exists { |
| 57 | lg.parentToChildren[parentID] = []string{} |
| 58 | } |
| 59 | lg.parentToChildren[parentID] = append(lg.parentToChildren[parentID], memoryID) |
| 60 | |
| 61 | if _, exists := lg.childToParents[memoryID]; !exists { |
| 62 | lg.childToParents[memoryID] = []string{} |
| 63 | } |
| 64 | lg.childToParents[memoryID] = append(lg.childToParents[memoryID], parentID) |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | // GetDerivedMemories 获取派生自指定记忆的所有记忆(递归)。 |
| 69 | func (lg *LineageGraph) GetDerivedMemories(memoryID string) []string { |
no outgoing calls