@yamo/memory-mesh 2.3.2 → 3.0.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 (124) hide show
  1. package/README.md +8 -2
  2. package/bin/memory_mesh.js +1 -1
  3. package/lib/llm/client.d.ts +86 -0
  4. package/lib/llm/client.js +300 -357
  5. package/lib/llm/client.ts +334 -0
  6. package/lib/llm/index.d.ts +17 -0
  7. package/lib/llm/index.js +16 -8
  8. package/lib/llm/index.ts +18 -0
  9. package/lib/memory/adapters/client.d.ts +120 -0
  10. package/lib/memory/adapters/client.js +519 -0
  11. package/lib/memory/adapters/client.ts +519 -0
  12. package/lib/memory/adapters/config.d.ts +130 -0
  13. package/lib/memory/adapters/config.js +190 -0
  14. package/lib/memory/adapters/config.ts +190 -0
  15. package/lib/memory/adapters/errors.d.ts +84 -0
  16. package/lib/memory/adapters/errors.js +129 -0
  17. package/lib/memory/adapters/errors.ts +129 -0
  18. package/lib/memory/context-manager.d.ts +41 -0
  19. package/lib/memory/context-manager.js +345 -0
  20. package/lib/memory/context-manager.ts +345 -0
  21. package/lib/memory/embeddings/factory.d.ts +57 -0
  22. package/lib/memory/embeddings/factory.js +149 -0
  23. package/lib/memory/embeddings/factory.ts +149 -0
  24. package/lib/memory/embeddings/index.d.ts +2 -0
  25. package/lib/memory/embeddings/index.js +3 -0
  26. package/lib/memory/embeddings/index.ts +3 -0
  27. package/lib/memory/embeddings/service.d.ts +134 -0
  28. package/lib/memory/embeddings/service.js +516 -0
  29. package/lib/memory/embeddings/service.ts +516 -0
  30. package/lib/memory/index.d.ts +9 -0
  31. package/lib/memory/index.js +10 -1
  32. package/lib/memory/index.ts +10 -0
  33. package/lib/memory/memory-mesh.d.ts +332 -0
  34. package/lib/memory/memory-mesh.js +1470 -678
  35. package/lib/memory/memory-mesh.ts +1517 -0
  36. package/lib/memory/memory-translator.d.ts +14 -0
  37. package/lib/memory/memory-translator.js +126 -0
  38. package/lib/memory/memory-translator.ts +126 -0
  39. package/lib/memory/schema.d.ts +130 -0
  40. package/lib/memory/schema.js +184 -0
  41. package/lib/memory/schema.ts +184 -0
  42. package/lib/memory/scorer.d.ts +25 -0
  43. package/lib/memory/scorer.js +78 -0
  44. package/lib/memory/scorer.ts +78 -0
  45. package/lib/memory/search/index.d.ts +1 -0
  46. package/lib/memory/search/index.js +2 -0
  47. package/lib/memory/search/index.ts +2 -0
  48. package/lib/memory/search/keyword-search.d.ts +46 -0
  49. package/lib/memory/search/keyword-search.js +136 -0
  50. package/lib/memory/search/keyword-search.ts +136 -0
  51. package/lib/scrubber/config/defaults.d.ts +46 -0
  52. package/lib/scrubber/config/defaults.js +50 -57
  53. package/lib/scrubber/config/defaults.ts +55 -0
  54. package/lib/scrubber/errors/scrubber-error.d.ts +22 -0
  55. package/lib/scrubber/errors/scrubber-error.js +28 -32
  56. package/lib/scrubber/errors/scrubber-error.ts +44 -0
  57. package/lib/scrubber/index.d.ts +5 -0
  58. package/lib/scrubber/index.js +4 -23
  59. package/lib/scrubber/index.ts +6 -0
  60. package/lib/scrubber/scrubber.d.ts +44 -0
  61. package/lib/scrubber/scrubber.js +100 -121
  62. package/lib/scrubber/scrubber.ts +109 -0
  63. package/lib/scrubber/stages/chunker.d.ts +25 -0
  64. package/lib/scrubber/stages/chunker.js +74 -91
  65. package/lib/scrubber/stages/chunker.ts +104 -0
  66. package/lib/scrubber/stages/metadata-annotator.d.ts +17 -0
  67. package/lib/scrubber/stages/metadata-annotator.js +55 -65
  68. package/lib/scrubber/stages/metadata-annotator.ts +75 -0
  69. package/lib/scrubber/stages/normalizer.d.ts +16 -0
  70. package/lib/scrubber/stages/normalizer.js +42 -50
  71. package/lib/scrubber/stages/normalizer.ts +60 -0
  72. package/lib/scrubber/stages/semantic-filter.d.ts +16 -0
  73. package/lib/scrubber/stages/semantic-filter.js +42 -52
  74. package/lib/scrubber/stages/semantic-filter.ts +62 -0
  75. package/lib/scrubber/stages/structural-cleaner.d.ts +18 -0
  76. package/lib/scrubber/stages/structural-cleaner.js +66 -75
  77. package/lib/scrubber/stages/structural-cleaner.ts +83 -0
  78. package/lib/scrubber/stages/validator.d.ts +17 -0
  79. package/lib/scrubber/stages/validator.js +46 -56
  80. package/lib/scrubber/stages/validator.ts +67 -0
  81. package/lib/scrubber/telemetry.d.ts +29 -0
  82. package/lib/scrubber/telemetry.js +54 -58
  83. package/lib/scrubber/telemetry.ts +62 -0
  84. package/lib/scrubber/utils/hash.d.ts +14 -0
  85. package/lib/scrubber/utils/hash.js +30 -32
  86. package/lib/scrubber/utils/hash.ts +40 -0
  87. package/lib/scrubber/utils/html-parser.d.ts +14 -0
  88. package/lib/scrubber/utils/html-parser.js +32 -39
  89. package/lib/scrubber/utils/html-parser.ts +46 -0
  90. package/lib/scrubber/utils/pattern-matcher.d.ts +12 -0
  91. package/lib/scrubber/utils/pattern-matcher.js +48 -57
  92. package/lib/scrubber/utils/pattern-matcher.ts +64 -0
  93. package/lib/scrubber/utils/token-counter.d.ts +18 -0
  94. package/lib/scrubber/utils/token-counter.js +24 -25
  95. package/lib/scrubber/utils/token-counter.ts +32 -0
  96. package/lib/utils/logger.d.ts +19 -0
  97. package/lib/utils/logger.js +65 -0
  98. package/lib/utils/logger.ts +65 -0
  99. package/lib/utils/skill-metadata.d.ts +24 -0
  100. package/lib/utils/skill-metadata.js +133 -0
  101. package/lib/utils/skill-metadata.ts +133 -0
  102. package/lib/yamo/emitter.d.ts +46 -0
  103. package/lib/yamo/emitter.js +79 -143
  104. package/lib/yamo/emitter.ts +171 -0
  105. package/lib/yamo/index.d.ts +14 -0
  106. package/lib/yamo/index.js +6 -7
  107. package/lib/yamo/index.ts +16 -0
  108. package/lib/yamo/schema.d.ts +56 -0
  109. package/lib/yamo/schema.js +82 -108
  110. package/lib/yamo/schema.ts +133 -0
  111. package/package.json +13 -8
  112. package/index.d.ts +0 -111
  113. package/lib/embeddings/factory.js +0 -151
  114. package/lib/embeddings/index.js +0 -2
  115. package/lib/embeddings/service.js +0 -586
  116. package/lib/index.js +0 -6
  117. package/lib/lancedb/client.js +0 -633
  118. package/lib/lancedb/config.js +0 -215
  119. package/lib/lancedb/errors.js +0 -144
  120. package/lib/lancedb/index.js +0 -4
  121. package/lib/lancedb/schema.js +0 -217
  122. package/lib/search/index.js +0 -1
  123. package/lib/search/keyword-search.js +0 -144
  124. package/lib/utils/index.js +0 -1
@@ -0,0 +1,332 @@
1
+ /**
2
+ * MemoryMesh class for managing vector memory storage
3
+ */
4
+ export declare class MemoryMesh {
5
+ client: any;
6
+ config: any;
7
+ embeddingFactory: any;
8
+ keywordSearch: any;
9
+ isInitialized: any;
10
+ vectorDimension: any;
11
+ enableYamo: any;
12
+ enableLLM: any;
13
+ enableMemory: any;
14
+ agentId: any;
15
+ yamoTable: any;
16
+ skillTable: any;
17
+ llmClient: any;
18
+ scrubber: any;
19
+ queryCache: any;
20
+ cacheConfig: any;
21
+ skillDirectories: any;
22
+ dbDir: any;
23
+ /**
24
+ * Create a new MemoryMesh instance
25
+ * @param {Object} [options={}]
26
+ */
27
+ constructor(options?: {});
28
+ /**
29
+ * Generate a cache key from query and options
30
+ * @private
31
+ */
32
+ _generateCacheKey(query: any, options?: {}): string;
33
+ /**
34
+ * Get cached result if valid
35
+ * @private
36
+ *
37
+ * Race condition fix: The delete-then-set pattern for LRU tracking creates a window
38
+ * where another operation could observe the key as missing. We use a try-finally
39
+ * pattern to ensure atomicity at the application level.
40
+ */
41
+ _getCachedResult(key: any): any;
42
+ /**
43
+ * Cache a search result
44
+ * @private
45
+ */
46
+ _cacheResult(key: any, result: any): void;
47
+ /**
48
+ * Clear all cached results
49
+ */
50
+ clearCache(): void;
51
+ /**
52
+ * Get cache statistics
53
+ */
54
+ getCacheStats(): {
55
+ size: any;
56
+ maxSize: any;
57
+ ttlMs: any;
58
+ };
59
+ /**
60
+ * Validate and sanitize metadata to prevent prototype pollution
61
+ * @private
62
+ */
63
+ _validateMetadata(metadata: any): {};
64
+ /**
65
+ * Sanitize and validate content before storage
66
+ * @private
67
+ */
68
+ _sanitizeContent(content: any): string;
69
+ /**
70
+ * Initialize the LanceDB client
71
+ */
72
+ init(): Promise<void>;
73
+ /**
74
+ * Add content to memory with auto-generated embedding and scrubbing.
75
+ *
76
+ * This is the primary method for storing information in the memory mesh.
77
+ * The content goes through several processing steps:
78
+ *
79
+ * 1. **Scrubbing**: PII and sensitive data are sanitized (if enabled)
80
+ * 2. **Validation**: Content length and metadata are validated
81
+ * 3. **Embedding**: Content is converted to a vector representation
82
+ * 4. **Storage**: Record is stored in LanceDB with metadata
83
+ * 5. **Emission**: Optional YAMO block emitted for provenance tracking
84
+ *
85
+ * @param content - The text content to store in memory
86
+ * @param metadata - Optional metadata (type, source, tags, etc.)
87
+ * @returns Promise with memory record containing id, content, metadata, created_at
88
+ *
89
+ * @example
90
+ * ```typescript
91
+ * const memory = await mesh.add("User likes TypeScript", {
92
+ * type: "preference",
93
+ * source: "chat",
94
+ * tags: ["programming", "languages"]
95
+ * });
96
+ * ```
97
+ *
98
+ * @throws {Error} If content exceeds max length (100KB)
99
+ * @throws {Error} If embedding generation fails
100
+ * @throws {Error} If database client is not initialized
101
+ */
102
+ add(content: any, metadata?: {}): Promise<{
103
+ id: any;
104
+ content: string;
105
+ metadata: {};
106
+ created_at: string;
107
+ }>;
108
+ /**
109
+ * Reflect on recent memories
110
+ */
111
+ reflect(options?: {}): Promise<{
112
+ topic: any;
113
+ count: number;
114
+ context: {
115
+ content: any;
116
+ type: any;
117
+ id: any;
118
+ }[];
119
+ prompt: string;
120
+ id?: undefined;
121
+ reflection?: undefined;
122
+ confidence?: undefined;
123
+ sourceMemoryCount?: undefined;
124
+ yamoBlock?: undefined;
125
+ createdAt?: undefined;
126
+ } | {
127
+ id: string;
128
+ topic: any;
129
+ reflection: string;
130
+ confidence: number;
131
+ sourceMemoryCount: number;
132
+ yamoBlock: any;
133
+ createdAt: string;
134
+ count?: undefined;
135
+ context?: undefined;
136
+ prompt?: undefined;
137
+ }>;
138
+ /**
139
+ * Ingest synthesized skill
140
+ * @param sourceFilePath - If provided, skip file write (file already exists)
141
+ */
142
+ ingestSkill(yamoText: any, metadata: {}, sourceFilePath: any): Promise<{
143
+ id: string;
144
+ name: any;
145
+ intent: any;
146
+ }>;
147
+ /**
148
+ * Recursive Skill Synthesis
149
+ */
150
+ synthesize(options?: {}): Promise<{
151
+ status: string;
152
+ analysis: string;
153
+ skill_id: string;
154
+ skill_name: any;
155
+ yamo_text: string;
156
+ error?: undefined;
157
+ } | {
158
+ status: string;
159
+ analysis: string;
160
+ skill_name: any;
161
+ skill_id?: undefined;
162
+ yamo_text?: undefined;
163
+ error?: undefined;
164
+ } | {
165
+ status: string;
166
+ error: any;
167
+ analysis: string;
168
+ skill_id?: undefined;
169
+ skill_name?: undefined;
170
+ yamo_text?: undefined;
171
+ } | {
172
+ status: string;
173
+ analysis: string;
174
+ skill_id?: undefined;
175
+ skill_name?: undefined;
176
+ yamo_text?: undefined;
177
+ error?: undefined;
178
+ }>;
179
+ /**
180
+ * Update reliability
181
+ */
182
+ updateSkillReliability(id: any, success: any): Promise<{
183
+ id: any;
184
+ reliability: any;
185
+ use_count: any;
186
+ }>;
187
+ /**
188
+ * Prune skills
189
+ */
190
+ pruneSkills(threshold?: number): Promise<{
191
+ pruned_count: number;
192
+ total_remaining: number;
193
+ }>;
194
+ /**
195
+ * List all synthesized skills
196
+ * @param {Object} [options={}] - Search options
197
+ * @returns {Promise<Array>} Normalized skill results
198
+ */
199
+ listSkills(options?: {}): Promise<any>;
200
+ /**
201
+ * Search for synthesized skills by semantic intent
202
+ * @param {string} query - Search query (intent description)
203
+ * @param {Object} [options={}] - Search options
204
+ * @returns {Promise<Array>} Normalized skill results
205
+ */
206
+ searchSkills(query: any, options?: {}): Promise<any>;
207
+ /**
208
+ * Get recent YAMO logs for the heartbeat
209
+ * @param {Object} options
210
+ */
211
+ getYamoLog(options?: {}): Promise<any>;
212
+ /**
213
+ * Emit a YAMO block to the YAMO blocks table
214
+ * @private
215
+ *
216
+ * Note: YAMO emission is non-critical - failures are logged but don't throw
217
+ * to prevent disrupting the main operation.
218
+ */
219
+ _emitYamoBlock(operationType: any, memoryId: any, yamoText: any): Promise<void>;
220
+ /**
221
+ * Search memory using hybrid vector + keyword search with Reciprocal Rank Fusion (RRF).
222
+ *
223
+ * This method performs semantic search by combining:
224
+ * 1. **Vector Search**: Uses embeddings to find semantically similar content
225
+ * 2. **Keyword Search**: Uses BM25-style keyword matching
226
+ * 3. **RRF Fusion**: Combines both result sets using Reciprocal Rank Fusion
227
+ *
228
+ * The RRF algorithm scores each document as: `sum(1 / (k + rank))` where k=60.
229
+ * This gives higher scores to documents that rank well in BOTH searches.
230
+ *
231
+ * **Performance**: Uses adaptive sorting strategy
232
+ * - Small datasets (≤ 2× limit): Full sort O(n log n)
233
+ * - Large datasets: Partial selection sort O(n×k) where k=limit
234
+ *
235
+ * **Caching**: Results are cached for 5 minutes by default (configurable via options)
236
+ *
237
+ * @param query - The search query text
238
+ * @param options - Search options
239
+ * @param options.limit - Maximum results to return (default: 10)
240
+ * @param options.filter - LanceDB filter expression (e.g., "type == 'preference'")
241
+ * @param options.useCache - Enable/disable result caching (default: true)
242
+ * @returns Promise with array of search results, sorted by relevance score
243
+ *
244
+ * @example
245
+ * ```typescript
246
+ * // Simple search
247
+ * const results = await mesh.search("TypeScript preferences");
248
+ *
249
+ * // Search with filter
250
+ * const code = await mesh.search("bug fix", { filter: "type == 'error'" });
251
+ *
252
+ * // Search with limit
253
+ * const top3 = await mesh.search("security issues", { limit: 3 });
254
+ * ```
255
+ *
256
+ * @throws {Error} If embedding generation fails
257
+ * @throws {Error} If database client is not initialized
258
+ */
259
+ search(query: any, options?: {}): Promise<any>;
260
+ _normalizeScores(results: any): any;
261
+ /**
262
+ * Tokenize query for keyword matching (private helper for searchSkills)
263
+ * Converts text to lowercase tokens, filtering out short tokens and punctuation.
264
+ * Handles camelCase/PascalCase by splitting on uppercase letters.
265
+ */
266
+ _tokenizeQuery(text: any): any;
267
+ formatResults(results: any): string;
268
+ get(id: any): Promise<{
269
+ id: any;
270
+ content: any;
271
+ metadata: any;
272
+ created_at: any;
273
+ updated_at: any;
274
+ }>;
275
+ getAll(options?: {}): Promise<any>;
276
+ stats(): Promise<{
277
+ count: number;
278
+ totalMemories: number;
279
+ totalSkills: number;
280
+ tableName: string;
281
+ uri: string;
282
+ isConnected: boolean;
283
+ embedding: {
284
+ configured: boolean;
285
+ primary: any;
286
+ fallbacks: any[];
287
+ };
288
+ status: string;
289
+ } | {
290
+ count: any;
291
+ totalMemories: any;
292
+ totalSkills: number;
293
+ tableName: any;
294
+ uri: any;
295
+ isConnected: any;
296
+ embedding: any;
297
+ status?: undefined;
298
+ }>;
299
+ _parseEmbeddingConfig(): {
300
+ modelType: string;
301
+ modelName: string;
302
+ dimension: number;
303
+ priority: number;
304
+ apiKey: string;
305
+ }[];
306
+ /**
307
+ * Close database connections and release resources
308
+ *
309
+ * This should be called when done with the MemoryMesh to properly:
310
+ * - Close LanceDB connections
311
+ * - Release file handles
312
+ * - Clean up resources
313
+ *
314
+ * Important for tests and cleanup to prevent connection leaks.
315
+ *
316
+ * @returns {Promise<void>}
317
+ *
318
+ * @example
319
+ * ```typescript
320
+ * const mesh = new MemoryMesh();
321
+ * await mesh.init();
322
+ * // ... use mesh ...
323
+ * await mesh.close(); // Clean up
324
+ * ```
325
+ */
326
+ close(): Promise<void>;
327
+ }
328
+ /**
329
+ * Main CLI handler
330
+ */
331
+ export declare function run(): Promise<void>;
332
+ export default MemoryMesh;