universal-agent-memory 0.7.0 → 0.7.2
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.
- package/dist/benchmarks/improved-benchmark.d.ts.map +1 -1
- package/dist/benchmarks/improved-benchmark.js +3 -1
- package/dist/benchmarks/improved-benchmark.js.map +1 -1
- package/dist/benchmarks/multi-turn-agent.d.ts.map +1 -1
- package/dist/benchmarks/multi-turn-agent.js +6 -2
- package/dist/benchmarks/multi-turn-agent.js.map +1 -1
- package/dist/bin/cli.js +4 -1
- package/dist/bin/cli.js.map +1 -1
- package/dist/cli/update.d.ts +3 -0
- package/dist/cli/update.d.ts.map +1 -1
- package/dist/cli/update.js +155 -11
- package/dist/cli/update.js.map +1 -1
- package/dist/index.d.ts +8 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -1
- package/dist/index.js.map +1 -1
- package/dist/memory/backends/factory.d.ts.map +1 -1
- package/dist/memory/backends/factory.js +1 -0
- package/dist/memory/backends/factory.js.map +1 -1
- package/dist/memory/backends/qdrant-cloud.d.ts +14 -1
- package/dist/memory/backends/qdrant-cloud.d.ts.map +1 -1
- package/dist/memory/backends/qdrant-cloud.js +59 -4
- package/dist/memory/backends/qdrant-cloud.js.map +1 -1
- package/dist/memory/dynamic-retrieval.d.ts +62 -1
- package/dist/memory/dynamic-retrieval.d.ts.map +1 -1
- package/dist/memory/dynamic-retrieval.js +154 -32
- package/dist/memory/dynamic-retrieval.js.map +1 -1
- package/dist/memory/embeddings.d.ts +25 -2
- package/dist/memory/embeddings.d.ts.map +1 -1
- package/dist/memory/embeddings.js +72 -2
- package/dist/memory/embeddings.js.map +1 -1
- package/dist/memory/memory-consolidator.d.ts +36 -0
- package/dist/memory/memory-consolidator.d.ts.map +1 -1
- package/dist/memory/memory-consolidator.js +166 -0
- package/dist/memory/memory-consolidator.js.map +1 -1
- package/dist/memory/multi-view-memory.d.ts +134 -0
- package/dist/memory/multi-view-memory.d.ts.map +1 -0
- package/dist/memory/multi-view-memory.js +420 -0
- package/dist/memory/multi-view-memory.js.map +1 -0
- package/dist/memory/semantic-compression.d.ts +77 -0
- package/dist/memory/semantic-compression.d.ts.map +1 -0
- package/dist/memory/semantic-compression.js +344 -0
- package/dist/memory/semantic-compression.js.map +1 -0
- package/dist/memory/speculative-cache.d.ts +3 -0
- package/dist/memory/speculative-cache.d.ts.map +1 -1
- package/dist/memory/speculative-cache.js +2 -0
- package/dist/memory/speculative-cache.js.map +1 -1
- package/dist/utils/dijkstra.d.ts +17 -0
- package/dist/utils/dijkstra.d.ts.map +1 -0
- package/dist/utils/dijkstra.js +91 -0
- package/dist/utils/dijkstra.js.map +1 -0
- package/dist/utils/validate-json.d.ts +3 -4
- package/dist/utils/validate-json.d.ts.map +1 -1
- package/dist/utils/validate-json.js +31 -31
- package/dist/utils/validate-json.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Multi-View Memory System for UAM
|
|
3
|
+
*
|
|
4
|
+
* Implements:
|
|
5
|
+
* 1. Multi-view indexing (entity, temporal, semantic type views)
|
|
6
|
+
* 2. ENGRAM-style memory typing (episodic, semantic, procedural)
|
|
7
|
+
* 3. Async embedding generation
|
|
8
|
+
* 4. Speculative cache integration with task classifier
|
|
9
|
+
*
|
|
10
|
+
* Based on SimpleMem (2026) and ENGRAM (2025) research
|
|
11
|
+
*/
|
|
12
|
+
import { getEmbeddingService } from './embeddings.js';
|
|
13
|
+
import { getSpeculativeCache } from './speculative-cache.js';
|
|
14
|
+
import { classifyTask } from './task-classifier.js';
|
|
15
|
+
/**
|
|
16
|
+
* Classify memory into ENGRAM type
|
|
17
|
+
*/
|
|
18
|
+
export function classifyENGRAMType(content, context) {
|
|
19
|
+
// Procedural: how-to, commands, steps
|
|
20
|
+
if (/how to|step \d|first.*then|run |execute |use |install /i.test(content)) {
|
|
21
|
+
return 'procedural';
|
|
22
|
+
}
|
|
23
|
+
// Check explicit type hints
|
|
24
|
+
if (context?.type === 'action' || context?.type === 'goal') {
|
|
25
|
+
return 'procedural';
|
|
26
|
+
}
|
|
27
|
+
// Episodic: specific events, past tense, temporal markers
|
|
28
|
+
if (/yesterday|today|last week|earlier|just now|happened|occurred|found that/i.test(content)) {
|
|
29
|
+
return 'episodic';
|
|
30
|
+
}
|
|
31
|
+
if (context?.type === 'observation') {
|
|
32
|
+
return 'episodic';
|
|
33
|
+
}
|
|
34
|
+
// Semantic: general facts, definitions, patterns
|
|
35
|
+
if (/is a|are |means|defined as|always|never|typically|pattern/i.test(content)) {
|
|
36
|
+
return 'semantic';
|
|
37
|
+
}
|
|
38
|
+
// Default based on content characteristics
|
|
39
|
+
const hasCommand = /`[^`]+`/.test(content);
|
|
40
|
+
const hasPath = /\/[\w/.-]+/.test(content);
|
|
41
|
+
if (hasCommand || hasPath) {
|
|
42
|
+
return 'procedural';
|
|
43
|
+
}
|
|
44
|
+
return 'semantic'; // Default
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Extract temporal bucket from content/timestamp
|
|
48
|
+
*/
|
|
49
|
+
export function extractTemporalBucket(content, timestamp) {
|
|
50
|
+
// Check for relative time markers
|
|
51
|
+
if (/just now|moments ago/i.test(content))
|
|
52
|
+
return 'now';
|
|
53
|
+
if (/today|this morning|this afternoon/i.test(content))
|
|
54
|
+
return 'today';
|
|
55
|
+
if (/yesterday/i.test(content))
|
|
56
|
+
return 'yesterday';
|
|
57
|
+
if (/this week|past few days/i.test(content))
|
|
58
|
+
return 'this-week';
|
|
59
|
+
if (/last week/i.test(content))
|
|
60
|
+
return 'last-week';
|
|
61
|
+
if (/this month/i.test(content))
|
|
62
|
+
return 'this-month';
|
|
63
|
+
// Use timestamp if available
|
|
64
|
+
if (timestamp) {
|
|
65
|
+
return timestamp.split('T')[0]; // YYYY-MM-DD
|
|
66
|
+
}
|
|
67
|
+
return 'unknown';
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Multi-View Memory Manager
|
|
71
|
+
*/
|
|
72
|
+
export class MultiViewMemoryManager {
|
|
73
|
+
memories = new Map();
|
|
74
|
+
index = {
|
|
75
|
+
byEntity: new Map(),
|
|
76
|
+
byTemporal: new Map(),
|
|
77
|
+
bySemanticType: new Map(),
|
|
78
|
+
byENGRAMType: new Map(),
|
|
79
|
+
};
|
|
80
|
+
embeddingQueue = [];
|
|
81
|
+
isProcessingEmbeddings = false;
|
|
82
|
+
/**
|
|
83
|
+
* Add memory with multi-view indexing
|
|
84
|
+
*/
|
|
85
|
+
async add(content, options = {}) {
|
|
86
|
+
const id = options.id || `mem-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
87
|
+
// Classify ENGRAM type
|
|
88
|
+
const memoryType = classifyENGRAMType(content, { type: options.semanticType });
|
|
89
|
+
// Extract temporal bucket
|
|
90
|
+
const temporalBucket = extractTemporalBucket(content, options.timestamp);
|
|
91
|
+
// Extract entities if not provided
|
|
92
|
+
const entities = options.entities || this.extractEntities(content);
|
|
93
|
+
const memory = {
|
|
94
|
+
id,
|
|
95
|
+
content,
|
|
96
|
+
memoryType,
|
|
97
|
+
entities,
|
|
98
|
+
temporalBucket,
|
|
99
|
+
semanticType: options.semanticType || 'general',
|
|
100
|
+
importance: options.importance || 5,
|
|
101
|
+
accessCount: 0,
|
|
102
|
+
lastAccessed: new Date(),
|
|
103
|
+
qualityScore: options.importance || 5,
|
|
104
|
+
embeddingPending: options.generateEmbedding !== false,
|
|
105
|
+
};
|
|
106
|
+
// Store memory
|
|
107
|
+
this.memories.set(id, memory);
|
|
108
|
+
// Update indices
|
|
109
|
+
this.indexMemory(memory);
|
|
110
|
+
// Queue embedding generation if requested
|
|
111
|
+
if (options.generateEmbedding !== false) {
|
|
112
|
+
this.embeddingQueue.push(id);
|
|
113
|
+
this.processEmbeddingQueue();
|
|
114
|
+
}
|
|
115
|
+
return memory;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Index memory in all views
|
|
119
|
+
*/
|
|
120
|
+
indexMemory(memory) {
|
|
121
|
+
// Entity index
|
|
122
|
+
for (const entity of memory.entities) {
|
|
123
|
+
if (!this.index.byEntity.has(entity)) {
|
|
124
|
+
this.index.byEntity.set(entity, new Set());
|
|
125
|
+
}
|
|
126
|
+
this.index.byEntity.get(entity).add(memory.id);
|
|
127
|
+
}
|
|
128
|
+
// Temporal index
|
|
129
|
+
if (!this.index.byTemporal.has(memory.temporalBucket)) {
|
|
130
|
+
this.index.byTemporal.set(memory.temporalBucket, new Set());
|
|
131
|
+
}
|
|
132
|
+
this.index.byTemporal.get(memory.temporalBucket).add(memory.id);
|
|
133
|
+
// Semantic type index
|
|
134
|
+
if (!this.index.bySemanticType.has(memory.semanticType)) {
|
|
135
|
+
this.index.bySemanticType.set(memory.semanticType, new Set());
|
|
136
|
+
}
|
|
137
|
+
this.index.bySemanticType.get(memory.semanticType).add(memory.id);
|
|
138
|
+
// ENGRAM type index
|
|
139
|
+
if (!this.index.byENGRAMType.has(memory.memoryType)) {
|
|
140
|
+
this.index.byENGRAMType.set(memory.memoryType, new Set());
|
|
141
|
+
}
|
|
142
|
+
this.index.byENGRAMType.get(memory.memoryType).add(memory.id);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Query by entity
|
|
146
|
+
*/
|
|
147
|
+
queryByEntity(entity) {
|
|
148
|
+
const ids = this.index.byEntity.get(entity);
|
|
149
|
+
if (!ids)
|
|
150
|
+
return [];
|
|
151
|
+
return Array.from(ids).map(id => this.memories.get(id)).filter(Boolean);
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Query by ENGRAM type
|
|
155
|
+
*/
|
|
156
|
+
queryByENGRAMType(type) {
|
|
157
|
+
const ids = this.index.byENGRAMType.get(type);
|
|
158
|
+
if (!ids)
|
|
159
|
+
return [];
|
|
160
|
+
return Array.from(ids).map(id => this.memories.get(id)).filter(Boolean);
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Query by temporal bucket
|
|
164
|
+
*/
|
|
165
|
+
queryByTemporal(bucket) {
|
|
166
|
+
const ids = this.index.byTemporal.get(bucket);
|
|
167
|
+
if (!ids)
|
|
168
|
+
return [];
|
|
169
|
+
return Array.from(ids).map(id => this.memories.get(id)).filter(Boolean);
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Smart query using task classification to select best view
|
|
173
|
+
*/
|
|
174
|
+
async smartQuery(query, limit = 10) {
|
|
175
|
+
const classification = classifyTask(query);
|
|
176
|
+
const results = [];
|
|
177
|
+
const seen = new Set();
|
|
178
|
+
// Check speculative cache first
|
|
179
|
+
const cache = getSpeculativeCache();
|
|
180
|
+
const cached = cache.get(query);
|
|
181
|
+
if (cached) {
|
|
182
|
+
return cached.result;
|
|
183
|
+
}
|
|
184
|
+
// Determine best retrieval strategy based on task type
|
|
185
|
+
const strategy = this.getRetrievalStrategy(classification);
|
|
186
|
+
// Execute strategy
|
|
187
|
+
for (const step of strategy) {
|
|
188
|
+
const stepResults = await this.executeStrategyStep(step, query, classification);
|
|
189
|
+
for (const mem of stepResults) {
|
|
190
|
+
if (!seen.has(mem.id)) {
|
|
191
|
+
seen.add(mem.id);
|
|
192
|
+
results.push(mem);
|
|
193
|
+
this.recordAccess(mem.id);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
if (results.length >= limit)
|
|
197
|
+
break;
|
|
198
|
+
}
|
|
199
|
+
// Sort by quality score and recency
|
|
200
|
+
results.sort((a, b) => {
|
|
201
|
+
const scoreA = a.qualityScore * (1 + a.accessCount * 0.1);
|
|
202
|
+
const scoreB = b.qualityScore * (1 + b.accessCount * 0.1);
|
|
203
|
+
return scoreB - scoreA;
|
|
204
|
+
});
|
|
205
|
+
const finalResults = results.slice(0, limit);
|
|
206
|
+
// Cache results
|
|
207
|
+
cache.set(query, finalResults);
|
|
208
|
+
// Pre-warm cache for predicted follow-up queries
|
|
209
|
+
cache.preWarm(query, async (q) => {
|
|
210
|
+
const r = await this.smartQuery(q, limit);
|
|
211
|
+
return r;
|
|
212
|
+
});
|
|
213
|
+
return finalResults;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Get retrieval strategy based on task classification
|
|
217
|
+
*/
|
|
218
|
+
getRetrievalStrategy(classification) {
|
|
219
|
+
const strategies = {
|
|
220
|
+
'sysadmin': [
|
|
221
|
+
{ view: 'engram', filter: 'procedural', weight: 1.5 },
|
|
222
|
+
{ view: 'semantic', filter: 'action', weight: 1.2 },
|
|
223
|
+
{ view: 'embedding', weight: 1.0 },
|
|
224
|
+
],
|
|
225
|
+
'debugging': [
|
|
226
|
+
{ view: 'engram', filter: 'episodic', weight: 1.5 },
|
|
227
|
+
{ view: 'temporal', filter: 'today', weight: 1.3 },
|
|
228
|
+
{ view: 'embedding', weight: 1.0 },
|
|
229
|
+
],
|
|
230
|
+
'coding': [
|
|
231
|
+
{ view: 'engram', filter: 'procedural', weight: 1.3 },
|
|
232
|
+
{ view: 'engram', filter: 'semantic', weight: 1.2 },
|
|
233
|
+
{ view: 'embedding', weight: 1.0 },
|
|
234
|
+
],
|
|
235
|
+
'security': [
|
|
236
|
+
{ view: 'engram', filter: 'semantic', weight: 1.5 },
|
|
237
|
+
{ view: 'semantic', filter: 'gotcha', weight: 1.3 },
|
|
238
|
+
{ view: 'embedding', weight: 1.0 },
|
|
239
|
+
],
|
|
240
|
+
'default': [
|
|
241
|
+
{ view: 'embedding', weight: 1.0 },
|
|
242
|
+
{ view: 'engram', filter: 'semantic', weight: 0.8 },
|
|
243
|
+
],
|
|
244
|
+
};
|
|
245
|
+
return strategies[classification.category] || strategies['default'];
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Execute a single strategy step
|
|
249
|
+
*/
|
|
250
|
+
async executeStrategyStep(step, query, _classification) {
|
|
251
|
+
switch (step.view) {
|
|
252
|
+
case 'entity': {
|
|
253
|
+
const entities = this.extractEntities(query);
|
|
254
|
+
const results = [];
|
|
255
|
+
for (const entity of entities) {
|
|
256
|
+
results.push(...this.queryByEntity(entity));
|
|
257
|
+
}
|
|
258
|
+
return results;
|
|
259
|
+
}
|
|
260
|
+
case 'temporal': {
|
|
261
|
+
if (step.filter) {
|
|
262
|
+
return this.queryByTemporal(step.filter);
|
|
263
|
+
}
|
|
264
|
+
// Return recent memories
|
|
265
|
+
return this.queryByTemporal('today').concat(this.queryByTemporal('yesterday'));
|
|
266
|
+
}
|
|
267
|
+
case 'semantic': {
|
|
268
|
+
if (step.filter) {
|
|
269
|
+
const ids = this.index.bySemanticType.get(step.filter);
|
|
270
|
+
if (ids) {
|
|
271
|
+
return Array.from(ids).map(id => this.memories.get(id)).filter(Boolean);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
return [];
|
|
275
|
+
}
|
|
276
|
+
case 'engram': {
|
|
277
|
+
if (step.filter) {
|
|
278
|
+
return this.queryByENGRAMType(step.filter);
|
|
279
|
+
}
|
|
280
|
+
return [];
|
|
281
|
+
}
|
|
282
|
+
case 'embedding': {
|
|
283
|
+
return this.semanticSearch(query, 10);
|
|
284
|
+
}
|
|
285
|
+
default:
|
|
286
|
+
return [];
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Semantic search using embeddings
|
|
291
|
+
*/
|
|
292
|
+
async semanticSearch(query, limit = 10) {
|
|
293
|
+
const embeddingService = getEmbeddingService();
|
|
294
|
+
try {
|
|
295
|
+
const queryEmbedding = await embeddingService.embed(query);
|
|
296
|
+
const scored = [];
|
|
297
|
+
for (const memory of this.memories.values()) {
|
|
298
|
+
if (memory.embedding) {
|
|
299
|
+
const score = embeddingService.cosineSimilarity(queryEmbedding, memory.embedding);
|
|
300
|
+
if (score > 0.5) {
|
|
301
|
+
scored.push({ memory, score });
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
scored.sort((a, b) => b.score - a.score);
|
|
306
|
+
return scored.slice(0, limit).map(s => s.memory);
|
|
307
|
+
}
|
|
308
|
+
catch {
|
|
309
|
+
return [];
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Process embedding queue asynchronously
|
|
314
|
+
*/
|
|
315
|
+
async processEmbeddingQueue() {
|
|
316
|
+
if (this.isProcessingEmbeddings || this.embeddingQueue.length === 0)
|
|
317
|
+
return;
|
|
318
|
+
this.isProcessingEmbeddings = true;
|
|
319
|
+
const embeddingService = getEmbeddingService();
|
|
320
|
+
try {
|
|
321
|
+
// Process in batches of 10
|
|
322
|
+
while (this.embeddingQueue.length > 0) {
|
|
323
|
+
const batch = this.embeddingQueue.splice(0, 10);
|
|
324
|
+
const memories = batch.map(id => this.memories.get(id)).filter(Boolean);
|
|
325
|
+
const texts = memories.map(m => m.content);
|
|
326
|
+
if (texts.length > 0) {
|
|
327
|
+
const embeddings = await embeddingService.embedBatch(texts);
|
|
328
|
+
for (let i = 0; i < memories.length; i++) {
|
|
329
|
+
memories[i].embedding = embeddings[i];
|
|
330
|
+
memories[i].embeddingPending = false;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
catch (error) {
|
|
336
|
+
console.error('[MultiViewMemory] Embedding generation error:', error);
|
|
337
|
+
}
|
|
338
|
+
finally {
|
|
339
|
+
this.isProcessingEmbeddings = false;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Extract entities from content
|
|
344
|
+
*/
|
|
345
|
+
extractEntities(content) {
|
|
346
|
+
const entities = [];
|
|
347
|
+
// File paths
|
|
348
|
+
const paths = content.match(/[\w./\\-]+\.(ts|js|py|json|yaml|yml|md|sh|sql)/gi);
|
|
349
|
+
if (paths)
|
|
350
|
+
entities.push(...paths);
|
|
351
|
+
// Function/class names
|
|
352
|
+
const names = content.match(/\b[a-z][a-zA-Z0-9]*(?:[A-Z][a-zA-Z0-9]*)+\b/g);
|
|
353
|
+
if (names)
|
|
354
|
+
entities.push(...names);
|
|
355
|
+
// Commands
|
|
356
|
+
const commands = content.match(/\b(npm|git|uam|docker|curl|pip|python|node)\s+\w+/gi);
|
|
357
|
+
if (commands)
|
|
358
|
+
entities.push(...commands.map(c => c.trim()));
|
|
359
|
+
// Quoted strings
|
|
360
|
+
const quoted = content.match(/`([^`]+)`/g);
|
|
361
|
+
if (quoted)
|
|
362
|
+
entities.push(...quoted.map(q => q.replace(/`/g, '')));
|
|
363
|
+
return [...new Set(entities)];
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Record memory access
|
|
367
|
+
*/
|
|
368
|
+
recordAccess(memoryId) {
|
|
369
|
+
const memory = this.memories.get(memoryId);
|
|
370
|
+
if (memory) {
|
|
371
|
+
memory.accessCount++;
|
|
372
|
+
memory.lastAccessed = new Date();
|
|
373
|
+
memory.qualityScore = Math.min(10, memory.qualityScore + 0.1);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Get statistics
|
|
378
|
+
*/
|
|
379
|
+
getStats() {
|
|
380
|
+
const byENGRAMType = {
|
|
381
|
+
episodic: this.index.byENGRAMType.get('episodic')?.size || 0,
|
|
382
|
+
semantic: this.index.byENGRAMType.get('semantic')?.size || 0,
|
|
383
|
+
procedural: this.index.byENGRAMType.get('procedural')?.size || 0,
|
|
384
|
+
};
|
|
385
|
+
return {
|
|
386
|
+
totalMemories: this.memories.size,
|
|
387
|
+
byENGRAMType,
|
|
388
|
+
pendingEmbeddings: this.embeddingQueue.length,
|
|
389
|
+
entitiesIndexed: this.index.byEntity.size,
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* Export all memories
|
|
394
|
+
*/
|
|
395
|
+
export() {
|
|
396
|
+
return Array.from(this.memories.values());
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* Import memories
|
|
400
|
+
*/
|
|
401
|
+
async import(memories) {
|
|
402
|
+
for (const memory of memories) {
|
|
403
|
+
this.memories.set(memory.id, memory);
|
|
404
|
+
this.indexMemory(memory);
|
|
405
|
+
if (!memory.embedding) {
|
|
406
|
+
this.embeddingQueue.push(memory.id);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
this.processEmbeddingQueue();
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
// Singleton instance
|
|
413
|
+
let globalMultiViewManager = null;
|
|
414
|
+
export function getMultiViewMemoryManager() {
|
|
415
|
+
if (!globalMultiViewManager) {
|
|
416
|
+
globalMultiViewManager = new MultiViewMemoryManager();
|
|
417
|
+
}
|
|
418
|
+
return globalMultiViewManager;
|
|
419
|
+
}
|
|
420
|
+
//# sourceMappingURL=multi-view-memory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multi-view-memory.js","sourceRoot":"","sources":["../../src/memory/multi-view-memory.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,YAAY,EAA2B,MAAM,sBAAsB,CAAC;AA8C7E;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,OAAe,EAAE,OAA2B;IAC7E,sCAAsC;IACtC,IAAI,yDAAyD,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QAC5E,OAAO,YAAY,CAAC;IACtB,CAAC;IAED,4BAA4B;IAC5B,IAAI,OAAO,EAAE,IAAI,KAAK,QAAQ,IAAI,OAAO,EAAE,IAAI,KAAK,MAAM,EAAE,CAAC;QAC3D,OAAO,YAAY,CAAC;IACtB,CAAC;IAED,0DAA0D;IAC1D,IAAI,0EAA0E,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QAC7F,OAAO,UAAU,CAAC;IACpB,CAAC;IAED,IAAI,OAAO,EAAE,IAAI,KAAK,aAAa,EAAE,CAAC;QACpC,OAAO,UAAU,CAAC;IACpB,CAA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AAC;QAED,IAAI,CAAC,qBAAqB,EAAE,CAAC;IAC/B,CAAC;CACF;AAED,qBAAqB;AACrB,IAAI,sBAAsB,GAAkC,IAAI,CAAC;AAEjE,MAAM,UAAU,yBAAyB;IACvC,IAAI,CAAC,sBAAsB,EAAE,CAAC;QAC5B,sBAAsB,GAAG,IAAI,sBAAsB,EAAE,CAAC;IACxD,CAAC;IACD,OAAO,sBAAsB,CAAC;AAChC,CAAC"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Semantic Compression Module for UAM
|
|
3
|
+
*
|
|
4
|
+
* Implements SimpleMem-style semantic structured compression:
|
|
5
|
+
* 1. Entropy-aware filtering to distill raw content into atomic facts
|
|
6
|
+
* 2. Coreference normalization (entity resolution)
|
|
7
|
+
* 3. Multi-view indexing for efficient retrieval
|
|
8
|
+
*
|
|
9
|
+
* Based on SimpleMem research (2026): 30x token reduction while maintaining F1 scores
|
|
10
|
+
*/
|
|
11
|
+
export interface AtomicFact {
|
|
12
|
+
content: string;
|
|
13
|
+
entities: string[];
|
|
14
|
+
actionability: number;
|
|
15
|
+
temporality: 'past' | 'present' | 'future' | 'timeless';
|
|
16
|
+
type: 'fact' | 'decision' | 'lesson' | 'pattern' | 'gotcha';
|
|
17
|
+
}
|
|
18
|
+
export interface SemanticUnit {
|
|
19
|
+
id: string;
|
|
20
|
+
atomicFacts: AtomicFact[];
|
|
21
|
+
entities: string[];
|
|
22
|
+
temporalMarkers: string[];
|
|
23
|
+
sourceTokens: number;
|
|
24
|
+
compressedTokens: number;
|
|
25
|
+
compressionRatio: number;
|
|
26
|
+
}
|
|
27
|
+
export interface SemanticCompressionConfig {
|
|
28
|
+
maxFactsPerUnit: number;
|
|
29
|
+
minActionability: number;
|
|
30
|
+
minEntropy: number;
|
|
31
|
+
deduplicationThreshold: number;
|
|
32
|
+
preserveHighImportance: boolean;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Calculate Shannon entropy of text (normalized 0-1)
|
|
36
|
+
* Higher entropy = more information content, less repetition
|
|
37
|
+
* Based on SimpleMem's entropy-aware filtering
|
|
38
|
+
*/
|
|
39
|
+
export declare function calculateEntropy(text: string): number;
|
|
40
|
+
/**
|
|
41
|
+
* Calculate information density (entropy per token)
|
|
42
|
+
* Helps identify high-value content worth preserving
|
|
43
|
+
*/
|
|
44
|
+
export declare function calculateInformationDensity(text: string): number;
|
|
45
|
+
/**
|
|
46
|
+
* Extract atomic facts from raw content
|
|
47
|
+
* Distills verbose content into minimal, self-contained units
|
|
48
|
+
*/
|
|
49
|
+
export declare function extractAtomicFacts(content: string, minEntropy?: number): AtomicFact[];
|
|
50
|
+
/**
|
|
51
|
+
* Create a semantic unit from multiple memories
|
|
52
|
+
*/
|
|
53
|
+
export declare function createSemanticUnit(memories: Array<{
|
|
54
|
+
content: string;
|
|
55
|
+
importance?: number;
|
|
56
|
+
}>, config?: Partial<SemanticCompressionConfig>): SemanticUnit;
|
|
57
|
+
/**
|
|
58
|
+
* Serialize semantic unit for storage/display
|
|
59
|
+
*/
|
|
60
|
+
export declare function serializeSemanticUnit(unit: SemanticUnit): string;
|
|
61
|
+
/**
|
|
62
|
+
* Compress batch of memories into semantic units
|
|
63
|
+
* Main entry point for semantic compression
|
|
64
|
+
*/
|
|
65
|
+
export declare function compressToSemanticUnits(memories: Array<{
|
|
66
|
+
content: string;
|
|
67
|
+
type: string;
|
|
68
|
+
importance?: number;
|
|
69
|
+
timestamp?: string;
|
|
70
|
+
}>, config?: Partial<SemanticCompressionConfig>): {
|
|
71
|
+
units: SemanticUnit[];
|
|
72
|
+
totalSourceTokens: number;
|
|
73
|
+
totalCompressedTokens: number;
|
|
74
|
+
overallRatio: number;
|
|
75
|
+
serialized: string;
|
|
76
|
+
};
|
|
77
|
+
//# sourceMappingURL=semantic-compression.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"semantic-compression.d.ts","sourceRoot":"","sources":["../../src/memory/semantic-compression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