@claude-flow/memory 3.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (214) hide show
  1. package/.agentic-flow/intelligence.json +16 -0
  2. package/README.md +249 -0
  3. package/__tests__/coverage/base.css +224 -0
  4. package/__tests__/coverage/block-navigation.js +87 -0
  5. package/__tests__/coverage/coverage-final.json +19 -0
  6. package/__tests__/coverage/favicon.png +0 -0
  7. package/__tests__/coverage/index.html +206 -0
  8. package/__tests__/coverage/lcov-report/base.css +224 -0
  9. package/__tests__/coverage/lcov-report/block-navigation.js +87 -0
  10. package/__tests__/coverage/lcov-report/favicon.png +0 -0
  11. package/__tests__/coverage/lcov-report/index.html +206 -0
  12. package/__tests__/coverage/lcov-report/prettify.css +1 -0
  13. package/__tests__/coverage/lcov-report/prettify.js +2 -0
  14. package/__tests__/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  15. package/__tests__/coverage/lcov-report/sorter.js +210 -0
  16. package/__tests__/coverage/lcov-report/src/agentdb-adapter.ts.html +2737 -0
  17. package/__tests__/coverage/lcov-report/src/agentdb-backend.ts.html +3130 -0
  18. package/__tests__/coverage/lcov-report/src/application/commands/delete-memory.command.ts.html +601 -0
  19. package/__tests__/coverage/lcov-report/src/application/commands/index.html +131 -0
  20. package/__tests__/coverage/lcov-report/src/application/commands/store-memory.command.ts.html +394 -0
  21. package/__tests__/coverage/lcov-report/src/application/queries/index.html +116 -0
  22. package/__tests__/coverage/lcov-report/src/application/queries/search-memory.query.ts.html +796 -0
  23. package/__tests__/coverage/lcov-report/src/application/services/index.html +116 -0
  24. package/__tests__/coverage/lcov-report/src/application/services/memory-application-service.ts.html +793 -0
  25. package/__tests__/coverage/lcov-report/src/cache-manager.ts.html +1633 -0
  26. package/__tests__/coverage/lcov-report/src/database-provider.ts.html +1618 -0
  27. package/__tests__/coverage/lcov-report/src/domain/entities/index.html +116 -0
  28. package/__tests__/coverage/lcov-report/src/domain/entities/memory-entry.ts.html +952 -0
  29. package/__tests__/coverage/lcov-report/src/domain/services/index.html +116 -0
  30. package/__tests__/coverage/lcov-report/src/domain/services/memory-domain-service.ts.html +1294 -0
  31. package/__tests__/coverage/lcov-report/src/hnsw-index.ts.html +3124 -0
  32. package/__tests__/coverage/lcov-report/src/hybrid-backend.ts.html +2167 -0
  33. package/__tests__/coverage/lcov-report/src/index.html +266 -0
  34. package/__tests__/coverage/lcov-report/src/infrastructure/repositories/hybrid-memory-repository.ts.html +1633 -0
  35. package/__tests__/coverage/lcov-report/src/infrastructure/repositories/index.html +116 -0
  36. package/__tests__/coverage/lcov-report/src/migration.ts.html +2092 -0
  37. package/__tests__/coverage/lcov-report/src/query-builder.ts.html +1711 -0
  38. package/__tests__/coverage/lcov-report/src/sqlite-backend.ts.html +2281 -0
  39. package/__tests__/coverage/lcov-report/src/sqljs-backend.ts.html +2374 -0
  40. package/__tests__/coverage/lcov-report/src/types.ts.html +2266 -0
  41. package/__tests__/coverage/lcov.info +10238 -0
  42. package/__tests__/coverage/prettify.css +1 -0
  43. package/__tests__/coverage/prettify.js +2 -0
  44. package/__tests__/coverage/sort-arrow-sprite.png +0 -0
  45. package/__tests__/coverage/sorter.js +210 -0
  46. package/__tests__/coverage/src/agentdb-adapter.ts.html +2737 -0
  47. package/__tests__/coverage/src/agentdb-backend.ts.html +3130 -0
  48. package/__tests__/coverage/src/application/commands/delete-memory.command.ts.html +601 -0
  49. package/__tests__/coverage/src/application/commands/index.html +131 -0
  50. package/__tests__/coverage/src/application/commands/store-memory.command.ts.html +394 -0
  51. package/__tests__/coverage/src/application/queries/index.html +116 -0
  52. package/__tests__/coverage/src/application/queries/search-memory.query.ts.html +796 -0
  53. package/__tests__/coverage/src/application/services/index.html +116 -0
  54. package/__tests__/coverage/src/application/services/memory-application-service.ts.html +793 -0
  55. package/__tests__/coverage/src/cache-manager.ts.html +1633 -0
  56. package/__tests__/coverage/src/database-provider.ts.html +1618 -0
  57. package/__tests__/coverage/src/domain/entities/index.html +116 -0
  58. package/__tests__/coverage/src/domain/entities/memory-entry.ts.html +952 -0
  59. package/__tests__/coverage/src/domain/services/index.html +116 -0
  60. package/__tests__/coverage/src/domain/services/memory-domain-service.ts.html +1294 -0
  61. package/__tests__/coverage/src/hnsw-index.ts.html +3124 -0
  62. package/__tests__/coverage/src/hybrid-backend.ts.html +2167 -0
  63. package/__tests__/coverage/src/index.html +266 -0
  64. package/__tests__/coverage/src/infrastructure/repositories/hybrid-memory-repository.ts.html +1633 -0
  65. package/__tests__/coverage/src/infrastructure/repositories/index.html +116 -0
  66. package/__tests__/coverage/src/migration.ts.html +2092 -0
  67. package/__tests__/coverage/src/query-builder.ts.html +1711 -0
  68. package/__tests__/coverage/src/sqlite-backend.ts.html +2281 -0
  69. package/__tests__/coverage/src/sqljs-backend.ts.html +2374 -0
  70. package/__tests__/coverage/src/types.ts.html +2266 -0
  71. package/benchmarks/cache-hit-rate.bench.ts +535 -0
  72. package/benchmarks/hnsw-indexing.bench.ts +552 -0
  73. package/benchmarks/memory-write.bench.ts +469 -0
  74. package/benchmarks/vector-search.bench.ts +449 -0
  75. package/dist/agentdb-adapter.d.ts +146 -0
  76. package/dist/agentdb-adapter.d.ts.map +1 -0
  77. package/dist/agentdb-adapter.js +679 -0
  78. package/dist/agentdb-adapter.js.map +1 -0
  79. package/dist/agentdb-backend.d.ts +214 -0
  80. package/dist/agentdb-backend.d.ts.map +1 -0
  81. package/dist/agentdb-backend.js +827 -0
  82. package/dist/agentdb-backend.js.map +1 -0
  83. package/dist/agentdb-backend.test.d.ts +7 -0
  84. package/dist/agentdb-backend.test.d.ts.map +1 -0
  85. package/dist/agentdb-backend.test.js +258 -0
  86. package/dist/agentdb-backend.test.js.map +1 -0
  87. package/dist/application/commands/delete-memory.command.d.ts +65 -0
  88. package/dist/application/commands/delete-memory.command.d.ts.map +1 -0
  89. package/dist/application/commands/delete-memory.command.js +129 -0
  90. package/dist/application/commands/delete-memory.command.js.map +1 -0
  91. package/dist/application/commands/store-memory.command.d.ts +48 -0
  92. package/dist/application/commands/store-memory.command.d.ts.map +1 -0
  93. package/dist/application/commands/store-memory.command.js +72 -0
  94. package/dist/application/commands/store-memory.command.js.map +1 -0
  95. package/dist/application/index.d.ts +12 -0
  96. package/dist/application/index.d.ts.map +1 -0
  97. package/dist/application/index.js +15 -0
  98. package/dist/application/index.js.map +1 -0
  99. package/dist/application/queries/search-memory.query.d.ts +72 -0
  100. package/dist/application/queries/search-memory.query.d.ts.map +1 -0
  101. package/dist/application/queries/search-memory.query.js +143 -0
  102. package/dist/application/queries/search-memory.query.js.map +1 -0
  103. package/dist/application/services/memory-application-service.d.ts +121 -0
  104. package/dist/application/services/memory-application-service.d.ts.map +1 -0
  105. package/dist/application/services/memory-application-service.js +190 -0
  106. package/dist/application/services/memory-application-service.js.map +1 -0
  107. package/dist/cache-manager.d.ts +134 -0
  108. package/dist/cache-manager.d.ts.map +1 -0
  109. package/dist/cache-manager.js +407 -0
  110. package/dist/cache-manager.js.map +1 -0
  111. package/dist/database-provider.d.ts +86 -0
  112. package/dist/database-provider.d.ts.map +1 -0
  113. package/dist/database-provider.js +385 -0
  114. package/dist/database-provider.js.map +1 -0
  115. package/dist/database-provider.test.d.ts +7 -0
  116. package/dist/database-provider.test.d.ts.map +1 -0
  117. package/dist/database-provider.test.js +285 -0
  118. package/dist/database-provider.test.js.map +1 -0
  119. package/dist/domain/entities/memory-entry.d.ts +143 -0
  120. package/dist/domain/entities/memory-entry.d.ts.map +1 -0
  121. package/dist/domain/entities/memory-entry.js +226 -0
  122. package/dist/domain/entities/memory-entry.js.map +1 -0
  123. package/dist/domain/index.d.ts +11 -0
  124. package/dist/domain/index.d.ts.map +1 -0
  125. package/dist/domain/index.js +12 -0
  126. package/dist/domain/index.js.map +1 -0
  127. package/dist/domain/repositories/memory-repository.interface.d.ts +102 -0
  128. package/dist/domain/repositories/memory-repository.interface.d.ts.map +1 -0
  129. package/dist/domain/repositories/memory-repository.interface.js +11 -0
  130. package/dist/domain/repositories/memory-repository.interface.js.map +1 -0
  131. package/dist/domain/services/memory-domain-service.d.ts +105 -0
  132. package/dist/domain/services/memory-domain-service.d.ts.map +1 -0
  133. package/dist/domain/services/memory-domain-service.js +297 -0
  134. package/dist/domain/services/memory-domain-service.js.map +1 -0
  135. package/dist/hnsw-index.d.ts +111 -0
  136. package/dist/hnsw-index.d.ts.map +1 -0
  137. package/dist/hnsw-index.js +781 -0
  138. package/dist/hnsw-index.js.map +1 -0
  139. package/dist/hybrid-backend.d.ts +217 -0
  140. package/dist/hybrid-backend.d.ts.map +1 -0
  141. package/dist/hybrid-backend.js +491 -0
  142. package/dist/hybrid-backend.js.map +1 -0
  143. package/dist/hybrid-backend.test.d.ts +8 -0
  144. package/dist/hybrid-backend.test.d.ts.map +1 -0
  145. package/dist/hybrid-backend.test.js +320 -0
  146. package/dist/hybrid-backend.test.js.map +1 -0
  147. package/dist/index.d.ts +188 -0
  148. package/dist/index.d.ts.map +1 -0
  149. package/dist/index.js +345 -0
  150. package/dist/index.js.map +1 -0
  151. package/dist/infrastructure/index.d.ts +17 -0
  152. package/dist/infrastructure/index.d.ts.map +1 -0
  153. package/dist/infrastructure/index.js +16 -0
  154. package/dist/infrastructure/index.js.map +1 -0
  155. package/dist/infrastructure/repositories/hybrid-memory-repository.d.ts +66 -0
  156. package/dist/infrastructure/repositories/hybrid-memory-repository.d.ts.map +1 -0
  157. package/dist/infrastructure/repositories/hybrid-memory-repository.js +409 -0
  158. package/dist/infrastructure/repositories/hybrid-memory-repository.js.map +1 -0
  159. package/dist/migration.d.ts +68 -0
  160. package/dist/migration.d.ts.map +1 -0
  161. package/dist/migration.js +513 -0
  162. package/dist/migration.js.map +1 -0
  163. package/dist/query-builder.d.ts +211 -0
  164. package/dist/query-builder.d.ts.map +1 -0
  165. package/dist/query-builder.js +438 -0
  166. package/dist/query-builder.js.map +1 -0
  167. package/dist/sqlite-backend.d.ts +121 -0
  168. package/dist/sqlite-backend.d.ts.map +1 -0
  169. package/dist/sqlite-backend.js +564 -0
  170. package/dist/sqlite-backend.js.map +1 -0
  171. package/dist/sqljs-backend.d.ts +128 -0
  172. package/dist/sqljs-backend.d.ts.map +1 -0
  173. package/dist/sqljs-backend.js +598 -0
  174. package/dist/sqljs-backend.js.map +1 -0
  175. package/dist/types.d.ts +481 -0
  176. package/dist/types.d.ts.map +1 -0
  177. package/dist/types.js +58 -0
  178. package/dist/types.js.map +1 -0
  179. package/docs/AGENTDB-INTEGRATION.md +388 -0
  180. package/docs/CROSS_PLATFORM.md +505 -0
  181. package/docs/WINDOWS_SUPPORT.md +422 -0
  182. package/examples/agentdb-example.ts +345 -0
  183. package/examples/cross-platform-usage.ts +326 -0
  184. package/framework/benchmark.ts +112 -0
  185. package/package.json +31 -0
  186. package/src/agentdb-adapter.ts +884 -0
  187. package/src/agentdb-backend.test.ts +339 -0
  188. package/src/agentdb-backend.ts +1016 -0
  189. package/src/application/commands/delete-memory.command.ts +172 -0
  190. package/src/application/commands/store-memory.command.ts +103 -0
  191. package/src/application/index.ts +36 -0
  192. package/src/application/queries/search-memory.query.ts +237 -0
  193. package/src/application/services/memory-application-service.ts +236 -0
  194. package/src/cache-manager.ts +516 -0
  195. package/src/database-provider.test.ts +364 -0
  196. package/src/database-provider.ts +511 -0
  197. package/src/domain/entities/memory-entry.ts +289 -0
  198. package/src/domain/index.ts +35 -0
  199. package/src/domain/repositories/memory-repository.interface.ts +120 -0
  200. package/src/domain/services/memory-domain-service.ts +403 -0
  201. package/src/hnsw-index.ts +1013 -0
  202. package/src/hybrid-backend.test.ts +399 -0
  203. package/src/hybrid-backend.ts +694 -0
  204. package/src/index.ts +515 -0
  205. package/src/infrastructure/index.ts +23 -0
  206. package/src/infrastructure/repositories/hybrid-memory-repository.ts +516 -0
  207. package/src/migration.ts +669 -0
  208. package/src/query-builder.ts +542 -0
  209. package/src/sqlite-backend.ts +732 -0
  210. package/src/sqljs-backend.ts +763 -0
  211. package/src/types.ts +727 -0
  212. package/tsconfig.json +9 -0
  213. package/tsconfig.tsbuildinfo +1 -0
  214. package/verify-cross-platform.ts +170 -0
@@ -0,0 +1,388 @@
1
+ # AgentDB Integration Guide
2
+
3
+ ## Overview
4
+
5
+ The V3 memory module now integrates with **agentdb@2.0.0-alpha.3.4** to provide high-performance vector search capabilities with HNSW indexing (150x-12,500x faster than brute-force approaches).
6
+
7
+ ## Features
8
+
9
+ ### AgentDBBackend
10
+
11
+ The `AgentDBBackend` class provides:
12
+
13
+ - **HNSW Vector Search**: Approximate nearest neighbor search with sub-millisecond query times
14
+ - **Graceful Fallback**: Works without native dependencies (hnswlib-node)
15
+ - **Optional Dependency Handling**: Automatically falls back to pure JavaScript/WASM if native bindings unavailable
16
+ - **Hybrid Integration**: Seamlessly works with `HybridBackend` for combined SQLite + AgentDB queries
17
+
18
+ ### Performance Targets
19
+
20
+ Based on ADR-006 and ADR-009:
21
+
22
+ - **150x-12,500x** faster vector search compared to brute-force
23
+ - **Sub-millisecond** query latency for k-NN search
24
+ - **Automatic backend selection**: Native hnswlib → ruvector → WASM fallback
25
+
26
+ ## Installation
27
+
28
+ ```bash
29
+ # Core package (required)
30
+ npm install agentdb@2.0.0-alpha.3.4
31
+
32
+ # Optional native dependencies for maximum performance
33
+ npm install hnswlib-node@^3.0.0 better-sqlite3@^11.0.0
34
+ ```
35
+
36
+ ## Usage
37
+
38
+ ### Basic Setup
39
+
40
+ ```typescript
41
+ import { AgentDBBackend } from '@claude-flow/memory';
42
+
43
+ const backend = new AgentDBBackend({
44
+ dbPath: './data/memory.db',
45
+ namespace: 'default',
46
+ vectorDimension: 1536, // For OpenAI embeddings
47
+ hnswM: 16,
48
+ hnswEfConstruction: 200,
49
+ hnswEfSearch: 100,
50
+ embeddingGenerator: async (text) => {
51
+ // Your embedding function
52
+ return embeddings.embed(text);
53
+ },
54
+ });
55
+
56
+ await backend.initialize();
57
+ ```
58
+
59
+ ### Hybrid Backend (Recommended)
60
+
61
+ Per ADR-009, the recommended approach is to use `HybridBackend`:
62
+
63
+ ```typescript
64
+ import { HybridBackend } from '@claude-flow/memory';
65
+
66
+ const memory = new HybridBackend({
67
+ // SQLite for structured queries
68
+ sqlite: {
69
+ dbPath: './data/memory-sqlite.db',
70
+ },
71
+
72
+ // AgentDB for vector search
73
+ agentdb: {
74
+ dbPath: './data/memory-agentdb.db',
75
+ vectorDimension: 1536,
76
+ hnswM: 16,
77
+ hnswEfConstruction: 200,
78
+ },
79
+
80
+ embeddingGenerator: embedFn,
81
+ dualWrite: true, // Write to both backends
82
+ });
83
+
84
+ await memory.initialize();
85
+
86
+ // Structured queries go to SQLite
87
+ const user = await memory.getByKey('users', 'john@example.com');
88
+
89
+ // Semantic queries go to AgentDB (150x faster)
90
+ const similar = await memory.querySemantic({
91
+ content: 'authentication patterns',
92
+ k: 10,
93
+ threshold: 0.7,
94
+ });
95
+
96
+ // Hybrid queries combine both
97
+ const results = await memory.queryHybrid({
98
+ semantic: { content: 'security vulnerabilities', k: 20 },
99
+ structured: { namespace: 'security', createdAfter: Date.now() - 86400000 },
100
+ combineStrategy: 'intersection',
101
+ });
102
+ ```
103
+
104
+ ### Semantic Search
105
+
106
+ ```typescript
107
+ // Store entries with embeddings
108
+ await backend.store({
109
+ id: 'entry-1',
110
+ key: 'auth-patterns',
111
+ content: 'OAuth 2.0 implementation patterns for secure authentication',
112
+ embedding: await embedFn('OAuth 2.0 implementation patterns...'),
113
+ // ... other fields
114
+ });
115
+
116
+ // Semantic search by content
117
+ const results = await backend.query({
118
+ type: 'semantic',
119
+ content: 'user authentication best practices',
120
+ limit: 10,
121
+ threshold: 0.8,
122
+ });
123
+
124
+ // Or search with pre-computed embedding
125
+ const results = await backend.search(
126
+ queryEmbedding,
127
+ { k: 10, threshold: 0.7 }
128
+ );
129
+ ```
130
+
131
+ ### Query Routing
132
+
133
+ The `HybridBackend` automatically routes queries to the optimal backend:
134
+
135
+ ```typescript
136
+ // Exact match → SQLite
137
+ await memory.query({ type: 'exact', namespace: 'users', key: 'john@example.com' });
138
+
139
+ // Prefix search → SQLite (indexed)
140
+ await memory.query({ type: 'prefix', keyPrefix: 'auth-' });
141
+
142
+ // Semantic search → AgentDB (HNSW)
143
+ await memory.query({ type: 'semantic', content: 'security patterns', limit: 10 });
144
+
145
+ // Hybrid → Both backends with intelligent merging
146
+ await memory.query({ type: 'hybrid', content: 'patterns', namespace: 'security' });
147
+ ```
148
+
149
+ ## Configuration Options
150
+
151
+ ### AgentDBBackendConfig
152
+
153
+ ```typescript
154
+ interface AgentDBBackendConfig {
155
+ /** Database path (default: ':memory:') */
156
+ dbPath?: string;
157
+
158
+ /** Namespace for memory organization */
159
+ namespace?: string;
160
+
161
+ /** Force WASM backend (skip native hnswlib) */
162
+ forceWasm?: boolean;
163
+
164
+ /** Vector backend: 'auto', 'ruvector', 'hnswlib' */
165
+ vectorBackend?: 'auto' | 'ruvector' | 'hnswlib';
166
+
167
+ /** Vector dimensions (default: 1536) */
168
+ vectorDimension?: number;
169
+
170
+ /** HNSW M parameter (connections per layer, default: 16) */
171
+ hnswM?: number;
172
+
173
+ /** HNSW efConstruction (build quality, default: 200) */
174
+ hnswEfConstruction?: number;
175
+
176
+ /** HNSW efSearch (search quality, default: 100) */
177
+ hnswEfSearch?: number;
178
+
179
+ /** Enable caching */
180
+ cacheEnabled?: boolean;
181
+
182
+ /** Embedding generator function */
183
+ embeddingGenerator?: EmbeddingGenerator;
184
+
185
+ /** Maximum entries */
186
+ maxEntries?: number;
187
+ }
188
+ ```
189
+
190
+ ### HNSW Tuning
191
+
192
+ - **M (16-64)**: Higher = better recall, more memory
193
+ - 16: Fast, less memory (recommended for most cases)
194
+ - 32: Balanced
195
+ - 64: High recall, more memory
196
+
197
+ - **efConstruction (100-400)**: Build time vs. quality
198
+ - 100: Fast build, lower quality
199
+ - 200: Balanced (recommended)
200
+ - 400: Slow build, high quality
201
+
202
+ - **efSearch (50-200)**: Search time vs. recall
203
+ - 50: Fast search, lower recall
204
+ - 100: Balanced (recommended)
205
+ - 200: Slower search, high recall
206
+
207
+ ## Graceful Degradation
208
+
209
+ The backend handles missing dependencies gracefully:
210
+
211
+ ```typescript
212
+ // 1. Try native hnswlib (fastest)
213
+ // 2. Fallback to ruvector (fast, pure JS)
214
+ // 3. Fallback to WASM (compatible)
215
+ // 4. Fallback to in-memory brute-force (always works)
216
+
217
+ const backend = new AgentDBBackend();
218
+ await backend.initialize();
219
+
220
+ // Check availability
221
+ if (backend.isAvailable()) {
222
+ console.log('Using AgentDB with HNSW');
223
+ } else {
224
+ console.log('Using fallback in-memory storage');
225
+ }
226
+ ```
227
+
228
+ ## Performance Metrics
229
+
230
+ ### Benchmarks (from agentdb@2.0.0-alpha.3.4)
231
+
232
+ | Operation | Brute Force | HNSW (hnswlib) | Speedup |
233
+ |-----------|-------------|----------------|---------|
234
+ | 10k vectors, k=10 | 150ms | 1ms | 150x |
235
+ | 100k vectors, k=10 | 1500ms | 2ms | 750x |
236
+ | 1M vectors, k=10 | 15000ms | 3ms | 5000x |
237
+
238
+ ### Memory Usage
239
+
240
+ - **No quantization**: ~4 bytes per dimension per vector
241
+ - **8-bit quantization**: ~1 byte per dimension (4x reduction)
242
+ - **4-bit quantization**: ~0.5 bytes per dimension (8x reduction)
243
+
244
+ ## Advanced Features
245
+
246
+ ### Vector Quantization
247
+
248
+ ```typescript
249
+ const backend = new AgentDBBackend({
250
+ // Enable quantization for 50-75% memory reduction
251
+ quantization: {
252
+ type: 'scalar',
253
+ bits: 8, // 4, 8, or 16
254
+ },
255
+ });
256
+ ```
257
+
258
+ ### Custom Distance Metrics
259
+
260
+ ```typescript
261
+ const backend = new AgentDBBackend({
262
+ vectorBackend: 'hnswlib',
263
+ distanceMetric: 'cosine', // 'cosine', 'euclidean', 'dot'
264
+ });
265
+ ```
266
+
267
+ ### Health Monitoring
268
+
269
+ ```typescript
270
+ const health = await backend.healthCheck();
271
+
272
+ console.log(health.status); // 'healthy' | 'degraded' | 'unhealthy'
273
+ console.log(health.components.index); // HNSW index health
274
+
275
+ if (health.status === 'degraded') {
276
+ console.log('Issues:', health.issues);
277
+ console.log('Recommendations:', health.recommendations);
278
+ }
279
+ ```
280
+
281
+ ### Statistics
282
+
283
+ ```typescript
284
+ const stats = await backend.getStats();
285
+
286
+ console.log('Total entries:', stats.totalEntries);
287
+ console.log('Avg query time:', stats.avgQueryTime, 'ms');
288
+ console.log('Avg search time:', stats.avgSearchTime, 'ms');
289
+
290
+ if (stats.hnswStats) {
291
+ console.log('HNSW vectors:', stats.hnswStats.vectorCount);
292
+ console.log('HNSW build time:', stats.hnswStats.buildTime, 'ms');
293
+ }
294
+ ```
295
+
296
+ ## Migration from Legacy Systems
297
+
298
+ The memory module includes migration support for legacy systems:
299
+
300
+ ```typescript
301
+ import { MemoryMigrator } from '@claude-flow/memory';
302
+
303
+ const migrator = new MemoryMigrator(
304
+ backend,
305
+ {
306
+ source: 'memory-manager',
307
+ sourcePath: './old-memory.json',
308
+ batchSize: 1000,
309
+ },
310
+ embeddingGenerator
311
+ );
312
+
313
+ const result = await migrator.migrate();
314
+
315
+ console.log('Migrated:', result.totalMigrated);
316
+ console.log('Failed:', result.totalFailed);
317
+ ```
318
+
319
+ ## Troubleshooting
320
+
321
+ ### AgentDB not available
322
+
323
+ ```
324
+ AgentDB not available. Install agentdb@2.0.0-alpha.3.4 for vector search support.
325
+ ```
326
+
327
+ **Solution**: Install agentdb:
328
+ ```bash
329
+ npm install agentdb@2.0.0-alpha.3.4
330
+ ```
331
+
332
+ ### Native bindings failed
333
+
334
+ ```
335
+ Failed to load hnswlib-node, falling back to WASM
336
+ ```
337
+
338
+ **Solution**: This is normal. The system automatically falls back to WASM. For maximum performance, install build tools:
339
+
340
+ ```bash
341
+ # Ubuntu/Debian
342
+ sudo apt-get install build-essential python3
343
+
344
+ # macOS
345
+ xcode-select --install
346
+
347
+ # Then reinstall
348
+ npm install hnswlib-node@^3.0.0
349
+ ```
350
+
351
+ ### Force WASM backend
352
+
353
+ ```typescript
354
+ const backend = new AgentDBBackend({
355
+ forceWasm: true, // Skip native bindings
356
+ });
357
+ ```
358
+
359
+ ## Testing
360
+
361
+ ```bash
362
+ # Run AgentDB backend tests
363
+ npm test -- agentdb-backend.test.ts
364
+
365
+ # Run all memory tests
366
+ npm test
367
+
368
+ # Run benchmarks
369
+ npm run bench
370
+ ```
371
+
372
+ ## Architecture Decision Records
373
+
374
+ This integration implements:
375
+
376
+ - **ADR-006**: Unified Memory Service with AgentDB
377
+ - **ADR-009**: Hybrid Memory Backend (SQLite + AgentDB) as default
378
+
379
+ ## Related Documentation
380
+
381
+ - [AgentDB GitHub](https://github.com/ruvnet/agentic-flow/tree/main/packages/agentdb)
382
+ - [HNSW Algorithm Paper](https://arxiv.org/abs/1603.09320)
383
+ - [V3 Memory Architecture](./README.md)
384
+ - [HybridBackend Documentation](./docs/hybrid-backend.md)
385
+
386
+ ## License
387
+
388
+ MIT