$npx -y skills add spencermarx/open-code-review --skill v3-memory-unificationUnify 6+ memory systems into AgentDB with HNSW indexing for 150x-12,500x search improvements. Implements ADR-006 (Unified Memory Service) and ADR-009 (Hybrid Memory Backend).
| 1 | # V3 Memory Unification |
| 2 | |
| 3 | ## What This Skill Does |
| 4 | |
| 5 | Consolidates disparate memory systems into unified AgentDB backend with HNSW vector search, achieving 150x-12,500x search performance improvements while maintaining backward compatibility. |
| 6 | |
| 7 | ## Quick Start |
| 8 | |
| 9 | ```bash |
| 10 | # Initialize memory unification |
| 11 | Task("Memory architecture", "Design AgentDB unification strategy", "v3-memory-specialist") |
| 12 | |
| 13 | # AgentDB integration |
| 14 | Task("AgentDB setup", "Configure HNSW indexing and vector search", "v3-memory-specialist") |
| 15 | |
| 16 | # Data migration |
| 17 | Task("Memory migration", "Migrate SQLite/Markdown to AgentDB", "v3-memory-specialist") |
| 18 | ``` |
| 19 | |
| 20 | ## Systems to Unify |
| 21 | |
| 22 | ### Legacy Systems → AgentDB |
| 23 | ``` |
| 24 | ┌─────────────────────────────────────────┐ |
| 25 | │ • MemoryManager (basic operations) │ |
| 26 | │ • DistributedMemorySystem (clustering) │ |
| 27 | │ • SwarmMemory (agent-specific) │ |
| 28 | │ • AdvancedMemoryManager (features) │ |
| 29 | │ • SQLiteBackend (structured) │ |
| 30 | │ • MarkdownBackend (file-based) │ |
| 31 | │ • HybridBackend (combination) │ |
| 32 | └─────────────────────────────────────────┘ |
| 33 | ↓ |
| 34 | ┌─────────────────────────────────────────┐ |
| 35 | │ 🚀 AgentDB with HNSW │ |
| 36 | │ • 150x-12,500x faster search │ |
| 37 | │ • Unified query interface │ |
| 38 | │ • Cross-agent memory sharing │ |
| 39 | │ • SONA learning integration │ |
| 40 | └─────────────────────────────────────────┘ |
| 41 | ``` |
| 42 | |
| 43 | ## Implementation Architecture |
| 44 | |
| 45 | ### Unified Memory Service |
| 46 | ```typescript |
| 47 | class UnifiedMemoryService implements IMemoryBackend { |
| 48 | constructor( |
| 49 | private agentdb: AgentDBAdapter, |
| 50 | private indexer: HNSWIndexer, |
| 51 | private migrator: DataMigrator |
| 52 | ) {} |
| 53 | |
| 54 | async store(entry: MemoryEntry): Promise<void> { |
| 55 | await this.agentdb.store(entry); |
| 56 | await this.indexer.index(entry); |
| 57 | } |
| 58 | |
| 59 | async query(query: MemoryQuery): Promise<MemoryEntry[]> { |
| 60 | if (query.semantic) { |
| 61 | return this.indexer.search(query); // 150x-12,500x faster |
| 62 | } |
| 63 | return this.agentdb.query(query); |
| 64 | } |
| 65 | } |
| 66 | ``` |
| 67 | |
| 68 | ### HNSW Vector Search |
| 69 | ```typescript |
| 70 | class HNSWIndexer { |
| 71 | constructor(dimensions: number = 1536) { |
| 72 | this.index = new HNSWIndex({ |
| 73 | dimensions, |
| 74 | efConstruction: 200, |
| 75 | M: 16, |
| 76 | speedupTarget: '150x-12500x' |
| 77 | }); |
| 78 | } |
| 79 | |
| 80 | async search(query: MemoryQuery): Promise<MemoryEntry[]> { |
| 81 | const embedding = await this.embedContent(query.content); |
| 82 | const results = this.index.search(embedding, query.limit || 10); |
| 83 | return this.retrieveEntries(results); |
| 84 | } |
| 85 | } |
| 86 | ``` |
| 87 | |
| 88 | ## Migration Strategy |
| 89 | |
| 90 | ### Phase 1: Foundation |
| 91 | ```typescript |
| 92 | // AgentDB adapter setup |
| 93 | const agentdb = new AgentDBAdapter({ |
| 94 | dimensions: 1536, |
| 95 | indexType: 'HNSW', |
| 96 | speedupTarget: '150x-12500x' |
| 97 | }); |
| 98 | ``` |
| 99 | |
| 100 | ### Phase 2: Data Migration |
| 101 | ```typescript |
| 102 | // SQLite → AgentDB |
| 103 | const migrateFromSQLite = async () => { |
| 104 | const entries = await sqlite.getAll(); |
| 105 | for (const entry of entries) { |
| 106 | const embedding = await generateEmbedding(entry.content); |
| 107 | await agentdb.store({ ...entry, embedding }); |
| 108 | } |
| 109 | }; |
| 110 | |
| 111 | // Markdown → AgentDB |
| 112 | const migrateFromMarkdown = async () => { |
| 113 | const files = await glob('**/*.md'); |
| 114 | for (const file of files) { |
| 115 | const content = await fs.readFile(file, 'utf-8'); |
| 116 | await agentdb.store({ |
| 117 | id: generateId(), |
| 118 | content, |
| 119 | embedding: await generateEmbedding(content), |
| 120 | metadata: { originalFile: file } |
| 121 | }); |
| 122 | } |
| 123 | }; |
| 124 | ``` |
| 125 | |
| 126 | ## SONA Integration |
| 127 | |
| 128 | ### Learning Pattern Storage |
| 129 | ```typescript |
| 130 | class SONAMemoryIntegration { |
| 131 | async storePattern(pattern: LearningPattern): Promise<void> { |
| 132 | await this.memory.store({ |
| 133 | id: pattern.id, |
| 134 | content: pattern.data, |
| 135 | metadata: { |
| 136 | sonaMode: pattern.mode, |
| 137 | reward: pattern.reward, |
| 138 | adaptationTime: pattern.adaptationTime |
| 139 | }, |
| 140 | embedding: await this.generateEmbedding(pattern.data) |
| 141 | }); |
| 142 | } |
| 143 | |
| 144 | async retrieveSimilarPatterns(query: string): Promise<LearningPattern[]> { |
| 145 | return this.memory.query({ |
| 146 | type: 'semantic', |
| 147 | content: query, |
| 148 | filters: { type: 'learning_pattern' } |
| 149 | }); |
| 150 | } |
| 151 | } |
| 152 | ``` |
| 153 | |
| 154 | ## Performance Targets |
| 155 | |
| 156 | - **Search Speed**: 150x-12,500x improvement via HNSW |
| 157 | - **Memory Usage**: 50-75% reduction through optimization |
| 158 | - **Query Latency**: <100ms for 1M+ entries |
| 159 | - **Cross-Agent Sharing**: Real-time memory synchronization |
| 160 | - **SONA Integration**: <0.05ms adaptation time |
| 161 | |
| 162 | ## Success Metrics |
| 163 | |
| 164 | - [ ] All 7 legacy memory systems migrated to AgentDB |
| 165 | - [ ] 150x-12,500x search performance validated |
| 166 | - [ ] 50-75% memory usage reduction achieved |
| 167 | - [ ] Backward compatibility maintained |
| 168 | - [ ] SONA learning patterns integrated |
| 169 | - [ ] Cross-agent memory sharing operational |