@memstack/core 0.2.0 → 0.5.0
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/README.md +321 -69
- package/dist/index.cjs +2480 -269
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +537 -27
- package/dist/index.d.ts +537 -27
- package/dist/index.js +2470 -267
- package/dist/index.js.map +1 -1
- package/package.json +27 -24
- package/src/adapters/embedding/cohere.ts +0 -77
- package/src/adapters/embedding/openai.ts +0 -65
- package/src/adapters/llm/anthropic.ts +0 -69
- package/src/adapters/llm/groq.ts +0 -185
- package/src/adapters/llm/ollama.ts +0 -85
- package/src/adapters/llm/openai.ts +0 -178
- package/src/adapters/storage/disk.ts +0 -334
- package/src/adapters/storage/memory.ts +0 -147
- package/src/adapters/storage/postgres.ts +0 -310
- package/src/adapters/storage/redis.ts +0 -274
- package/src/client.ts +0 -236
- package/src/errors.ts +0 -47
- package/src/index.ts +0 -52
- package/src/interfaces.ts +0 -154
- package/src/memory/ContextCompiler.ts +0 -158
- package/src/memory/MemoryStore.ts +0 -266
- package/src/memory/Pruner.ts +0 -66
- package/src/memory/Summarizer.ts +0 -46
- package/src/types.ts +0 -50
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
type MemoryType = "interaction" | "summary" | "observation" | "
|
|
1
|
+
type MemoryType = "interaction" | "summary" | "observation" | "fact" | "reflection";
|
|
2
2
|
interface Memory {
|
|
3
3
|
id: string;
|
|
4
4
|
actorId: string;
|
|
@@ -18,6 +18,10 @@ interface CompiledContext {
|
|
|
18
18
|
recentMemories: Memory[];
|
|
19
19
|
importantMemories: Memory[];
|
|
20
20
|
tokenEstimate: number;
|
|
21
|
+
messages?: {
|
|
22
|
+
role: string;
|
|
23
|
+
content: string;
|
|
24
|
+
}[];
|
|
21
25
|
}
|
|
22
26
|
interface ProcessResult {
|
|
23
27
|
memory: Memory;
|
|
@@ -33,7 +37,22 @@ interface HealthStatus {
|
|
|
33
37
|
llm: boolean;
|
|
34
38
|
embedding: boolean;
|
|
35
39
|
}
|
|
40
|
+
interface MemoryStats {
|
|
41
|
+
total: number;
|
|
42
|
+
expired: number;
|
|
43
|
+
oldest: Date | null;
|
|
44
|
+
newest: Date | null;
|
|
45
|
+
avgImportance: number;
|
|
46
|
+
byType: Record<MemoryType, number>;
|
|
47
|
+
byActor: Record<string, {
|
|
48
|
+
count: number;
|
|
49
|
+
oldest: Date;
|
|
50
|
+
newest: Date;
|
|
51
|
+
avgImportance: number;
|
|
52
|
+
}>;
|
|
53
|
+
}
|
|
36
54
|
|
|
55
|
+
type TokenCounter = (text: string) => number;
|
|
37
56
|
interface MemoryStoreInput {
|
|
38
57
|
actorId: string;
|
|
39
58
|
content: string;
|
|
@@ -53,6 +72,8 @@ interface MemoryCountFilter {
|
|
|
53
72
|
actorId?: string;
|
|
54
73
|
memoryType?: MemoryType;
|
|
55
74
|
minImportance?: number;
|
|
75
|
+
createdAfter?: Date;
|
|
76
|
+
createdBefore?: Date;
|
|
56
77
|
}
|
|
57
78
|
interface MemoryRetrieveQuery {
|
|
58
79
|
actorId?: string;
|
|
@@ -61,11 +82,15 @@ interface MemoryRetrieveQuery {
|
|
|
61
82
|
tags?: string[];
|
|
62
83
|
limit?: number;
|
|
63
84
|
strategy?: "semantic" | "hybrid" | "recent" | "important";
|
|
85
|
+
createdAfter?: Date;
|
|
86
|
+
createdBefore?: Date;
|
|
64
87
|
}
|
|
65
88
|
interface ContextOptions {
|
|
66
89
|
actorId: string;
|
|
67
90
|
maxTokens?: number;
|
|
68
91
|
memoryTypes?: MemoryType[];
|
|
92
|
+
retrieveStrategy?: "recent" | "important" | "hybrid";
|
|
93
|
+
format?: "markdown" | "messages";
|
|
69
94
|
}
|
|
70
95
|
interface SummarizeOptions {
|
|
71
96
|
actorId?: string;
|
|
@@ -74,15 +99,21 @@ interface SummarizeOptions {
|
|
|
74
99
|
targetCount?: number;
|
|
75
100
|
memoryTypes?: MemoryType[];
|
|
76
101
|
keepOriginals?: boolean;
|
|
102
|
+
/** Maximum memories per LLM call. When exceeded, memories are split into chunks, summarized independently, then recursively merged. Default 50. */
|
|
103
|
+
chunkSize?: number;
|
|
104
|
+
/** Per-call override for the summarization system prompt. Falls back to constructor prompt. */
|
|
105
|
+
prompt?: string;
|
|
77
106
|
}
|
|
78
107
|
interface PruneStrategy {
|
|
79
|
-
type: "byAge" | "byImportance" | "byCount" | "byType" | "custom";
|
|
108
|
+
type: "byAge" | "byImportance" | "byCount" | "byType" | "custom" | "compose";
|
|
80
109
|
maxAge?: number;
|
|
81
110
|
minImportance?: number;
|
|
82
111
|
maxPerActor?: number;
|
|
83
112
|
memoryTypes?: MemoryType[];
|
|
84
113
|
/** Custom predicate: return true for memories that should be REMOVED. */
|
|
85
114
|
shouldRemove?: (memory: Memory) => boolean;
|
|
115
|
+
/** For "compose" type: sub-strategies applied cumulatively (kept memories must pass ALL). */
|
|
116
|
+
strategies?: PruneStrategy[];
|
|
86
117
|
}
|
|
87
118
|
interface LLMProvider {
|
|
88
119
|
complete(request: {
|
|
@@ -117,7 +148,10 @@ interface LLMProvider {
|
|
|
117
148
|
}
|
|
118
149
|
interface EmbeddingProvider {
|
|
119
150
|
embed(texts: string[]): Promise<number[][]>;
|
|
151
|
+
/** Vector dimension length (e.g., 1536 for text-embedding-3-small). */
|
|
120
152
|
dimensions: number;
|
|
153
|
+
/** Maximum number of texts per embed() call. Default: 2048. */
|
|
154
|
+
maxBatchSize?: number;
|
|
121
155
|
}
|
|
122
156
|
interface StorageProvider {
|
|
123
157
|
initialize(): Promise<void>;
|
|
@@ -170,6 +204,16 @@ interface MemoryStoreConfig {
|
|
|
170
204
|
llm?: LLMProvider;
|
|
171
205
|
embedOnStore?: boolean;
|
|
172
206
|
summarizationPrompt?: string;
|
|
207
|
+
tokenCounter?: TokenCounter;
|
|
208
|
+
contextImportantRatio?: number;
|
|
209
|
+
limits?: {
|
|
210
|
+
dedupScan?: number;
|
|
211
|
+
contextScan?: number;
|
|
212
|
+
summarizeScan?: number;
|
|
213
|
+
pruneScan?: number;
|
|
214
|
+
exportScan?: number;
|
|
215
|
+
purgeScan?: number;
|
|
216
|
+
};
|
|
173
217
|
}
|
|
174
218
|
declare class MemoryStore {
|
|
175
219
|
private storage;
|
|
@@ -178,6 +222,10 @@ declare class MemoryStore {
|
|
|
178
222
|
private pruner;
|
|
179
223
|
private compiler;
|
|
180
224
|
private embedOnStore;
|
|
225
|
+
private limits;
|
|
226
|
+
private contentHashIndex;
|
|
227
|
+
private initialized;
|
|
228
|
+
private _ensureInit;
|
|
181
229
|
constructor(config: MemoryStoreConfig);
|
|
182
230
|
store(input: MemoryStoreInput): Promise<Memory>;
|
|
183
231
|
storeBatch(inputs: MemoryStoreInput[]): Promise<Memory[]>;
|
|
@@ -192,6 +240,10 @@ declare class MemoryStore {
|
|
|
192
240
|
summary: Memory;
|
|
193
241
|
deletedCount: number;
|
|
194
242
|
}>;
|
|
243
|
+
summarizeStream(options: SummarizeOptions): AsyncIterable<{
|
|
244
|
+
chunk: string;
|
|
245
|
+
text: string;
|
|
246
|
+
}>;
|
|
195
247
|
prune(strategy: PruneStrategy): Promise<{
|
|
196
248
|
pruned: string[];
|
|
197
249
|
count: number;
|
|
@@ -200,7 +252,11 @@ declare class MemoryStore {
|
|
|
200
252
|
wouldPrune: string[];
|
|
201
253
|
count: number;
|
|
202
254
|
}>;
|
|
203
|
-
export(): Promise<Memory[]>;
|
|
255
|
+
export(actorId?: string): Promise<Memory[]>;
|
|
256
|
+
stats(actorId?: string): Promise<MemoryStats>;
|
|
257
|
+
purgeActor(actorId: string): Promise<number>;
|
|
258
|
+
merge(ids: string[]): Promise<Memory>;
|
|
259
|
+
private _ensureHashIndex;
|
|
204
260
|
private _hashContent;
|
|
205
261
|
}
|
|
206
262
|
|
|
@@ -208,10 +264,11 @@ declare class MemStack {
|
|
|
208
264
|
readonly memory: MemoryStore;
|
|
209
265
|
private config;
|
|
210
266
|
private storage;
|
|
211
|
-
private
|
|
267
|
+
private processCounts;
|
|
268
|
+
private pruneCheckCount;
|
|
212
269
|
constructor(config: MemStackConfig);
|
|
213
270
|
process(input: ProcessInput): Promise<ProcessResult>;
|
|
214
|
-
export(): Promise<MemStackSnapshot>;
|
|
271
|
+
export(actorId?: string): Promise<MemStackSnapshot>;
|
|
215
272
|
import(snapshot: MemStackSnapshot): Promise<void>;
|
|
216
273
|
health(): Promise<HealthStatus>;
|
|
217
274
|
close(): Promise<void>;
|
|
@@ -236,7 +293,7 @@ declare function validationError(message: string, details?: Record<string, unkno
|
|
|
236
293
|
declare function storageError(message: string, cause?: unknown): MemStackError;
|
|
237
294
|
declare function configError(message: string): MemStackError;
|
|
238
295
|
|
|
239
|
-
declare class
|
|
296
|
+
declare class InMemoryStorageAdapter implements StorageProvider {
|
|
240
297
|
private memories;
|
|
241
298
|
initialize(): Promise<void>;
|
|
242
299
|
generateId(): string;
|
|
@@ -256,9 +313,10 @@ interface DiskStorageConfig {
|
|
|
256
313
|
/** Directory to store memory files. Default: "./memstack-data" */
|
|
257
314
|
storageDir?: string;
|
|
258
315
|
}
|
|
259
|
-
declare class
|
|
316
|
+
declare class DiskStorageAdapter implements StorageProvider {
|
|
260
317
|
private dir;
|
|
261
318
|
private _writeLocks;
|
|
319
|
+
private _idIndex;
|
|
262
320
|
constructor(config?: DiskStorageConfig);
|
|
263
321
|
initialize(): Promise<void>;
|
|
264
322
|
generateId(): string;
|
|
@@ -276,25 +334,126 @@ declare class DiskStorage implements StorageProvider {
|
|
|
276
334
|
private _writeFile;
|
|
277
335
|
private _withWriteLock;
|
|
278
336
|
private _listActors;
|
|
337
|
+
private _buildIndex;
|
|
279
338
|
private _toExternal;
|
|
280
339
|
}
|
|
281
340
|
|
|
341
|
+
interface MarkdownStorageConfig {
|
|
342
|
+
dir: string;
|
|
343
|
+
oneFilePerActor?: boolean;
|
|
344
|
+
}
|
|
345
|
+
declare class MarkdownStorageAdapter implements StorageProvider {
|
|
346
|
+
private dir;
|
|
347
|
+
private oneFilePerActor;
|
|
348
|
+
private _cache;
|
|
349
|
+
private _deletedIds;
|
|
350
|
+
private _cacheDirty;
|
|
351
|
+
constructor(config: MarkdownStorageConfig);
|
|
352
|
+
initialize(): Promise<void>;
|
|
353
|
+
generateId(): string;
|
|
354
|
+
store(input: MemoryStoreInput): Promise<Memory>;
|
|
355
|
+
storeBatch(inputs: MemoryStoreInput[]): Promise<Memory[]>;
|
|
356
|
+
get(id: string): Promise<Memory | null>;
|
|
357
|
+
delete(id: string): Promise<void>;
|
|
358
|
+
deleteMany(ids: string[]): Promise<number>;
|
|
359
|
+
retrieve(query: MemoryRetrieveQuery, _embedding?: number[]): Promise<Memory[]>;
|
|
360
|
+
count(filter?: MemoryCountFilter): Promise<number>;
|
|
361
|
+
close(): Promise<void>;
|
|
362
|
+
vacuum(): Promise<void>;
|
|
363
|
+
private _filePath;
|
|
364
|
+
private _formatBlock;
|
|
365
|
+
private _formatTombstone;
|
|
366
|
+
private _ensureCache;
|
|
367
|
+
private _parseFile;
|
|
368
|
+
private _vacuumFile;
|
|
369
|
+
private _listActors;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
interface HybridStorageConfig {
|
|
373
|
+
cache: StorageProvider;
|
|
374
|
+
durable: StorageProvider;
|
|
375
|
+
writeBoth?: boolean;
|
|
376
|
+
readFromCache?: boolean;
|
|
377
|
+
syncOnInit?: boolean;
|
|
378
|
+
}
|
|
379
|
+
declare class HybridStorageAdapter implements StorageProvider {
|
|
380
|
+
private cache;
|
|
381
|
+
private durable;
|
|
382
|
+
private writeBoth;
|
|
383
|
+
private readFromCache;
|
|
384
|
+
private syncOnInit;
|
|
385
|
+
constructor(config: HybridStorageConfig);
|
|
386
|
+
initialize(): Promise<void>;
|
|
387
|
+
store(input: MemoryStoreInput): Promise<Memory>;
|
|
388
|
+
storeBatch(inputs: MemoryStoreInput[]): Promise<Memory[]>;
|
|
389
|
+
get(id: string): Promise<Memory | null>;
|
|
390
|
+
retrieve(query: MemoryRetrieveQuery, embedding?: number[]): Promise<Memory[]>;
|
|
391
|
+
delete(id: string): Promise<void>;
|
|
392
|
+
deleteMany(ids: string[]): Promise<number>;
|
|
393
|
+
count(filter?: MemoryCountFilter): Promise<number>;
|
|
394
|
+
touch(id: string): Promise<void>;
|
|
395
|
+
close(): Promise<void>;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
type PgPool = {
|
|
399
|
+
query(text: string, params?: unknown[]): Promise<{
|
|
400
|
+
rows: unknown[];
|
|
401
|
+
}>;
|
|
402
|
+
end?: () => Promise<void>;
|
|
403
|
+
};
|
|
404
|
+
interface PostgresStorageConfig {
|
|
405
|
+
pool?: PgPool;
|
|
406
|
+
connectionString?: string;
|
|
407
|
+
host?: string;
|
|
408
|
+
port?: number;
|
|
409
|
+
database?: string;
|
|
410
|
+
user?: string;
|
|
411
|
+
password?: string;
|
|
412
|
+
tableName?: string;
|
|
413
|
+
vectorDimensions?: number;
|
|
414
|
+
ssl?: boolean | object;
|
|
415
|
+
}
|
|
416
|
+
declare class PostgresStorageAdapter implements StorageProvider {
|
|
417
|
+
private pool;
|
|
418
|
+
private table;
|
|
419
|
+
private vectorDimensions;
|
|
420
|
+
private _ownsPool;
|
|
421
|
+
constructor(config: PostgresStorageConfig);
|
|
422
|
+
private _connectionString?;
|
|
423
|
+
private _connParts?;
|
|
424
|
+
private _ssl?;
|
|
425
|
+
initialize(): Promise<void>;
|
|
426
|
+
private _createPool;
|
|
427
|
+
private _buildConnString;
|
|
428
|
+
private _runMigration;
|
|
429
|
+
generateId(): string;
|
|
430
|
+
store(input: MemoryStoreInput): Promise<Memory>;
|
|
431
|
+
storeBatch(inputs: MemoryStoreInput[]): Promise<Memory[]>;
|
|
432
|
+
get(id: string): Promise<Memory | null>;
|
|
433
|
+
delete(id: string): Promise<void>;
|
|
434
|
+
deleteMany(ids: string[]): Promise<number>;
|
|
435
|
+
touch(id: string): Promise<void>;
|
|
436
|
+
retrieve(query: MemoryRetrieveQuery, embedding?: number[]): Promise<Memory[]>;
|
|
437
|
+
count(filter?: MemoryCountFilter): Promise<number>;
|
|
438
|
+
close(): Promise<void>;
|
|
439
|
+
private _semanticRetrieve;
|
|
440
|
+
private _rowToMemory;
|
|
441
|
+
}
|
|
442
|
+
|
|
282
443
|
type RedisClient = {
|
|
283
444
|
set(key: string, value: string): Promise<unknown>;
|
|
284
445
|
get(key: string): Promise<string | null>;
|
|
285
|
-
mget(...keys: string[]): Promise<(string | null)[]>;
|
|
286
446
|
del(key: string | string[]): Promise<number>;
|
|
287
447
|
sadd(key: string, ...members: string[]): Promise<number>;
|
|
288
448
|
srem(key: string, ...members: string[]): Promise<number>;
|
|
289
449
|
smembers(key: string): Promise<string[]>;
|
|
450
|
+
mget(...keys: string[]): Promise<(string | null)[]>;
|
|
290
451
|
};
|
|
291
452
|
interface RedisStorageConfig {
|
|
292
|
-
/** An active ioredis client instance (or compatible) */
|
|
293
453
|
redis: RedisClient;
|
|
294
|
-
/** Key prefix. Default: "memstack" */
|
|
295
454
|
keyPrefix?: string;
|
|
296
455
|
}
|
|
297
|
-
declare class
|
|
456
|
+
declare class RedisStorageAdapter implements StorageProvider {
|
|
298
457
|
private redis;
|
|
299
458
|
private prefix;
|
|
300
459
|
constructor(config: RedisStorageConfig);
|
|
@@ -305,6 +464,7 @@ declare class RedisStorage implements StorageProvider {
|
|
|
305
464
|
get(id: string): Promise<Memory | null>;
|
|
306
465
|
delete(id: string): Promise<void>;
|
|
307
466
|
deleteMany(ids: string[]): Promise<number>;
|
|
467
|
+
touch(id: string): Promise<void>;
|
|
308
468
|
retrieve(query: MemoryRetrieveQuery, _embedding?: number[]): Promise<Memory[]>;
|
|
309
469
|
count(filter?: MemoryCountFilter): Promise<number>;
|
|
310
470
|
close(): Promise<void>;
|
|
@@ -316,24 +476,285 @@ declare class RedisStorage implements StorageProvider {
|
|
|
316
476
|
private _toExternal;
|
|
317
477
|
}
|
|
318
478
|
|
|
319
|
-
type
|
|
320
|
-
|
|
321
|
-
|
|
479
|
+
type QdrantClient = {
|
|
480
|
+
createCollection(name: string, config: {
|
|
481
|
+
vectors: {
|
|
482
|
+
size: number;
|
|
483
|
+
distance: string;
|
|
484
|
+
};
|
|
485
|
+
}): Promise<unknown>;
|
|
486
|
+
getCollection(name: string): Promise<unknown>;
|
|
487
|
+
upsert(name: string, opts: {
|
|
488
|
+
points: {
|
|
489
|
+
id: string;
|
|
490
|
+
vector: number[];
|
|
491
|
+
payload: Record<string, unknown>;
|
|
492
|
+
}[];
|
|
493
|
+
}): Promise<unknown>;
|
|
494
|
+
retrieve(name: string, opts: {
|
|
495
|
+
ids: string[];
|
|
496
|
+
}): Promise<unknown[]>;
|
|
497
|
+
search(name: string, opts: {
|
|
498
|
+
vector: number[];
|
|
499
|
+
limit: number;
|
|
500
|
+
filter?: {
|
|
501
|
+
must: unknown[];
|
|
502
|
+
};
|
|
503
|
+
}): Promise<unknown[]>;
|
|
504
|
+
delete(name: string, opts: {
|
|
505
|
+
points: string[];
|
|
506
|
+
}): Promise<unknown>;
|
|
507
|
+
count(name: string, opts?: {
|
|
508
|
+
filter?: {
|
|
509
|
+
must: unknown[];
|
|
510
|
+
};
|
|
511
|
+
}): Promise<{
|
|
512
|
+
count: number;
|
|
513
|
+
}>;
|
|
514
|
+
scroll(name: string, opts?: {
|
|
515
|
+
filter?: {
|
|
516
|
+
must: unknown[];
|
|
517
|
+
};
|
|
518
|
+
limit?: number;
|
|
519
|
+
}): Promise<{
|
|
520
|
+
points: unknown[];
|
|
322
521
|
}>;
|
|
323
522
|
};
|
|
324
|
-
interface
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
523
|
+
interface QdrantStorageConfig {
|
|
524
|
+
client: QdrantClient;
|
|
525
|
+
collectionName?: string;
|
|
526
|
+
vectorSize?: number;
|
|
527
|
+
}
|
|
528
|
+
declare class QdrantStorageAdapter implements StorageProvider {
|
|
529
|
+
private client;
|
|
530
|
+
private collectionName;
|
|
531
|
+
private vectorSize;
|
|
532
|
+
private _idToQdrant;
|
|
533
|
+
constructor(config: QdrantStorageConfig);
|
|
534
|
+
initialize(): Promise<void>;
|
|
535
|
+
generateId(): string;
|
|
536
|
+
store(input: MemoryStoreInput): Promise<Memory>;
|
|
537
|
+
storeBatch(inputs: MemoryStoreInput[]): Promise<Memory[]>;
|
|
538
|
+
get(id: string): Promise<Memory | null>;
|
|
539
|
+
delete(id: string): Promise<void>;
|
|
540
|
+
deleteMany(ids: string[]): Promise<number>;
|
|
541
|
+
retrieve(query: MemoryRetrieveQuery, embedding?: number[]): Promise<Memory[]>;
|
|
542
|
+
count(filter?: MemoryCountFilter): Promise<number>;
|
|
543
|
+
close(): Promise<void>;
|
|
544
|
+
private _toPayload;
|
|
545
|
+
private _fromPoint;
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
type Neo4jDriver = {
|
|
549
|
+
session(opts?: {
|
|
550
|
+
database?: string;
|
|
551
|
+
}): Neo4jSession;
|
|
552
|
+
close(): Promise<void>;
|
|
553
|
+
};
|
|
554
|
+
type Neo4jSession = {
|
|
555
|
+
run(query: string, params?: Record<string, unknown>): Promise<{
|
|
556
|
+
records: {
|
|
557
|
+
get(key: string): unknown;
|
|
558
|
+
toObject(): Record<string, unknown>;
|
|
559
|
+
}[];
|
|
560
|
+
}>;
|
|
561
|
+
close(): Promise<void>;
|
|
562
|
+
};
|
|
563
|
+
interface Neo4jStorageConfig {
|
|
564
|
+
driver: Neo4jDriver;
|
|
565
|
+
database?: string;
|
|
566
|
+
}
|
|
567
|
+
declare class Neo4jStorageAdapter implements StorageProvider {
|
|
568
|
+
private driver;
|
|
569
|
+
private database;
|
|
570
|
+
constructor(config: Neo4jStorageConfig);
|
|
571
|
+
initialize(): Promise<void>;
|
|
572
|
+
generateId(): string;
|
|
573
|
+
store(input: MemoryStoreInput): Promise<Memory>;
|
|
574
|
+
storeBatch(inputs: MemoryStoreInput[]): Promise<Memory[]>;
|
|
575
|
+
get(id: string): Promise<Memory | null>;
|
|
576
|
+
delete(id: string): Promise<void>;
|
|
577
|
+
deleteMany(ids: string[]): Promise<number>;
|
|
578
|
+
retrieve(query: MemoryRetrieveQuery, embedding?: number[]): Promise<Memory[]>;
|
|
579
|
+
count(filter?: MemoryCountFilter): Promise<number>;
|
|
580
|
+
graphQuery(cypher: string, params?: Record<string, unknown>): Promise<Memory[]>;
|
|
581
|
+
close(): Promise<void>;
|
|
582
|
+
private _semanticRetrieve;
|
|
583
|
+
private _postFilter;
|
|
584
|
+
private _nodeToMemory;
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
type WeaviateClient = {
|
|
588
|
+
collections: {
|
|
589
|
+
create(opts: {
|
|
590
|
+
name: string;
|
|
591
|
+
properties: {
|
|
592
|
+
name: string;
|
|
593
|
+
dataType: string;
|
|
594
|
+
}[];
|
|
595
|
+
vectorizers?: unknown;
|
|
596
|
+
}): Promise<unknown>;
|
|
597
|
+
get(name: string): WeaviateCollection;
|
|
598
|
+
delete(name: string): Promise<void>;
|
|
599
|
+
exists(name: string): Promise<boolean>;
|
|
600
|
+
listAll(): Promise<string[]>;
|
|
601
|
+
};
|
|
602
|
+
};
|
|
603
|
+
type WeaviateCollection = {
|
|
604
|
+
data: {
|
|
605
|
+
insert(opts: {
|
|
606
|
+
properties: Record<string, unknown>;
|
|
607
|
+
vectors: number[];
|
|
608
|
+
id?: string;
|
|
609
|
+
}): Promise<string>;
|
|
610
|
+
deleteById(id: string): Promise<void>;
|
|
611
|
+
};
|
|
612
|
+
query: {
|
|
613
|
+
fetchObjectById(id: string, opts?: {
|
|
614
|
+
includeVector?: boolean;
|
|
615
|
+
}): Promise<{
|
|
616
|
+
properties: Record<string, unknown>;
|
|
617
|
+
vectors?: {
|
|
618
|
+
default?: number[];
|
|
619
|
+
};
|
|
620
|
+
} | null>;
|
|
621
|
+
fetchObjects(opts: {
|
|
622
|
+
limit: number;
|
|
623
|
+
filters?: unknown;
|
|
624
|
+
includeVector?: boolean;
|
|
625
|
+
}): Promise<{
|
|
626
|
+
objects: {
|
|
627
|
+
uuid: string;
|
|
628
|
+
properties: Record<string, unknown>;
|
|
629
|
+
vectors?: {
|
|
630
|
+
default?: number[];
|
|
631
|
+
};
|
|
632
|
+
metadata?: {
|
|
633
|
+
creationTimeUnix: number;
|
|
634
|
+
};
|
|
635
|
+
}[];
|
|
636
|
+
}>;
|
|
637
|
+
nearVector(vector: number[], opts: {
|
|
638
|
+
limit: number;
|
|
639
|
+
returnProperties?: string[];
|
|
640
|
+
returnMetadata?: string[];
|
|
641
|
+
filters?: unknown;
|
|
642
|
+
includeVector?: boolean;
|
|
643
|
+
}): Promise<{
|
|
644
|
+
objects: {
|
|
645
|
+
uuid: string;
|
|
646
|
+
properties: Record<string, unknown>;
|
|
647
|
+
vectors?: {
|
|
648
|
+
default?: number[];
|
|
649
|
+
};
|
|
650
|
+
metadata?: {
|
|
651
|
+
creationTimeUnix: number;
|
|
652
|
+
};
|
|
653
|
+
}[];
|
|
654
|
+
}>;
|
|
655
|
+
};
|
|
656
|
+
config: {
|
|
657
|
+
get(): Promise<{
|
|
658
|
+
name: string;
|
|
659
|
+
}>;
|
|
660
|
+
update(opts: {
|
|
661
|
+
vectorIndexConfig: Record<string, unknown>;
|
|
662
|
+
}): Promise<void>;
|
|
663
|
+
};
|
|
664
|
+
};
|
|
665
|
+
interface WeaviateStorageConfig {
|
|
666
|
+
client: WeaviateClient;
|
|
667
|
+
className?: string;
|
|
668
|
+
}
|
|
669
|
+
declare class WeaviateStorageAdapter implements StorageProvider {
|
|
670
|
+
private client;
|
|
671
|
+
private className;
|
|
672
|
+
private _collection;
|
|
673
|
+
private _idToWv;
|
|
674
|
+
constructor(config: WeaviateStorageConfig);
|
|
675
|
+
initialize(): Promise<void>;
|
|
676
|
+
private collection;
|
|
677
|
+
generateId(): string;
|
|
678
|
+
store(input: MemoryStoreInput): Promise<Memory>;
|
|
679
|
+
storeBatch(inputs: MemoryStoreInput[]): Promise<Memory[]>;
|
|
680
|
+
get(id: string): Promise<Memory | null>;
|
|
681
|
+
delete(id: string): Promise<void>;
|
|
682
|
+
deleteMany(ids: string[]): Promise<number>;
|
|
683
|
+
retrieve(query: MemoryRetrieveQuery, embedding?: number[]): Promise<Memory[]>;
|
|
684
|
+
count(filter?: MemoryCountFilter): Promise<number>;
|
|
685
|
+
close(): Promise<void>;
|
|
686
|
+
private _buildFilter;
|
|
687
|
+
private _toProperties;
|
|
688
|
+
private _fromProperties;
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
type LanceDBConnection = {
|
|
692
|
+
createTable(name: string, data: {
|
|
693
|
+
id: string;
|
|
694
|
+
vector: number[];
|
|
695
|
+
actor_id: string;
|
|
696
|
+
memory_type: string;
|
|
697
|
+
content: string;
|
|
698
|
+
importance: number;
|
|
699
|
+
emotional_valence: number;
|
|
700
|
+
tags: string;
|
|
701
|
+
source_id: string;
|
|
702
|
+
metadata: string;
|
|
703
|
+
expires_at: string;
|
|
704
|
+
created_at: string;
|
|
705
|
+
}[]): Promise<LanceDBTable>;
|
|
706
|
+
openTable(name: string): Promise<LanceDBTable>;
|
|
707
|
+
tableNames(): Promise<string[]>;
|
|
708
|
+
};
|
|
709
|
+
type LanceDBTable = {
|
|
710
|
+
add(data: {
|
|
711
|
+
id: string;
|
|
712
|
+
vector: number[];
|
|
713
|
+
actor_id: string;
|
|
714
|
+
memory_type: string;
|
|
715
|
+
content: string;
|
|
716
|
+
importance: number;
|
|
717
|
+
emotional_valence: number;
|
|
718
|
+
tags: string;
|
|
719
|
+
source_id: string;
|
|
720
|
+
metadata: string;
|
|
721
|
+
expires_at: string;
|
|
722
|
+
created_at: string;
|
|
723
|
+
}[]): Promise<void>;
|
|
724
|
+
search(vector: number[]): {
|
|
725
|
+
limit(n: number): {
|
|
726
|
+
where(predicate: string): {
|
|
727
|
+
execute(): Promise<{
|
|
728
|
+
id: string;
|
|
729
|
+
_distance: number;
|
|
730
|
+
vector: number[];
|
|
731
|
+
actor_id: string;
|
|
732
|
+
memory_type: string;
|
|
733
|
+
content: string;
|
|
734
|
+
importance: number;
|
|
735
|
+
emotional_valence: number;
|
|
736
|
+
tags: string;
|
|
737
|
+
source_id: string;
|
|
738
|
+
metadata: string;
|
|
739
|
+
expires_at: string;
|
|
740
|
+
created_at: string;
|
|
741
|
+
}[]>;
|
|
742
|
+
};
|
|
743
|
+
};
|
|
744
|
+
};
|
|
745
|
+
delete(predicate: string): Promise<void>;
|
|
746
|
+
countRows(predicate?: string): Promise<number>;
|
|
747
|
+
};
|
|
748
|
+
interface LanceDBStorageConfig {
|
|
749
|
+
connection: LanceDBConnection;
|
|
328
750
|
tableName?: string;
|
|
329
|
-
/** Automatically run CREATE TABLE IF NOT EXISTS on init. Default: true */
|
|
330
|
-
autoMigrate?: boolean;
|
|
331
751
|
}
|
|
332
|
-
declare class
|
|
333
|
-
private
|
|
752
|
+
declare class LanceDBStorageAdapter implements StorageProvider {
|
|
753
|
+
private connection;
|
|
334
754
|
private table;
|
|
335
|
-
private
|
|
336
|
-
|
|
755
|
+
private tableName;
|
|
756
|
+
private _zeroVector;
|
|
757
|
+
constructor(config: LanceDBStorageConfig);
|
|
337
758
|
initialize(): Promise<void>;
|
|
338
759
|
generateId(): string;
|
|
339
760
|
store(input: MemoryStoreInput): Promise<Memory>;
|
|
@@ -344,7 +765,94 @@ declare class PostgresStorage implements StorageProvider {
|
|
|
344
765
|
retrieve(query: MemoryRetrieveQuery, embedding?: number[]): Promise<Memory[]>;
|
|
345
766
|
count(filter?: MemoryCountFilter): Promise<number>;
|
|
346
767
|
close(): Promise<void>;
|
|
347
|
-
private
|
|
768
|
+
private _rowToMemory;
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
type MongoCollection = {
|
|
772
|
+
insertOne(doc: Record<string, unknown>): Promise<{
|
|
773
|
+
insertedId: string;
|
|
774
|
+
}>;
|
|
775
|
+
findOne(filter: Record<string, unknown>): Promise<Record<string, unknown> | null>;
|
|
776
|
+
updateOne(filter: Record<string, unknown>, update: Record<string, unknown>, opts?: {
|
|
777
|
+
upsert?: boolean;
|
|
778
|
+
}): Promise<{
|
|
779
|
+
upsertedId?: string;
|
|
780
|
+
}>;
|
|
781
|
+
deleteOne(filter: Record<string, unknown>): Promise<{
|
|
782
|
+
deletedCount: number;
|
|
783
|
+
}>;
|
|
784
|
+
deleteMany(filter: Record<string, unknown>): Promise<{
|
|
785
|
+
deletedCount: number;
|
|
786
|
+
}>;
|
|
787
|
+
find(filter: Record<string, unknown>): {
|
|
788
|
+
sort(sort: Record<string, number>): {
|
|
789
|
+
limit(n: number): {
|
|
790
|
+
toArray(): Promise<Record<string, unknown>[]>;
|
|
791
|
+
};
|
|
792
|
+
};
|
|
793
|
+
};
|
|
794
|
+
countDocuments(filter?: Record<string, unknown>): Promise<number>;
|
|
795
|
+
aggregate(pipeline: Record<string, unknown>[]): {
|
|
796
|
+
toArray(): Promise<Record<string, unknown>[]>;
|
|
797
|
+
};
|
|
798
|
+
};
|
|
799
|
+
interface MongoDBStorageConfig {
|
|
800
|
+
collection: MongoCollection;
|
|
801
|
+
vectorDimensions?: number;
|
|
802
|
+
}
|
|
803
|
+
declare class MongoDBStorageAdapter implements StorageProvider {
|
|
804
|
+
private collection;
|
|
805
|
+
private vectorDimensions;
|
|
806
|
+
constructor(config: MongoDBStorageConfig);
|
|
807
|
+
initialize(): Promise<void>;
|
|
808
|
+
generateId(): string;
|
|
809
|
+
store(input: MemoryStoreInput): Promise<Memory>;
|
|
810
|
+
storeBatch(inputs: MemoryStoreInput[]): Promise<Memory[]>;
|
|
811
|
+
get(id: string): Promise<Memory | null>;
|
|
812
|
+
delete(id: string): Promise<void>;
|
|
813
|
+
deleteMany(ids: string[]): Promise<number>;
|
|
814
|
+
retrieve(query: MemoryRetrieveQuery, embedding?: number[]): Promise<Memory[]>;
|
|
815
|
+
count(filter?: MemoryCountFilter): Promise<number>;
|
|
816
|
+
close(): Promise<void>;
|
|
817
|
+
private retrieveStandard;
|
|
818
|
+
private retrieveSemantic;
|
|
819
|
+
private toMemory;
|
|
820
|
+
private toDoc;
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
type BetterSqlite3Db = {
|
|
824
|
+
exec(sql: string): void;
|
|
825
|
+
prepare(sql: string): {
|
|
826
|
+
run(...params: unknown[]): {
|
|
827
|
+
changes: number;
|
|
828
|
+
lastInsertRowid: number | bigint;
|
|
829
|
+
};
|
|
830
|
+
get(...params: unknown[]): unknown | undefined;
|
|
831
|
+
all(...params: unknown[]): unknown[];
|
|
832
|
+
};
|
|
833
|
+
close(): void;
|
|
834
|
+
};
|
|
835
|
+
interface SQLiteStorageConfig {
|
|
836
|
+
db: BetterSqlite3Db;
|
|
837
|
+
tableName?: string;
|
|
838
|
+
vectorDimensions?: number;
|
|
839
|
+
}
|
|
840
|
+
declare class SQLiteStorageAdapter implements StorageProvider {
|
|
841
|
+
private db;
|
|
842
|
+
private table;
|
|
843
|
+
private vectorDimensions;
|
|
844
|
+
constructor(config: SQLiteStorageConfig);
|
|
845
|
+
initialize(): Promise<void>;
|
|
846
|
+
generateId(): string;
|
|
847
|
+
store(input: MemoryStoreInput): Promise<Memory>;
|
|
848
|
+
storeBatch(inputs: MemoryStoreInput[]): Promise<Memory[]>;
|
|
849
|
+
get(id: string): Promise<Memory | null>;
|
|
850
|
+
delete(id: string): Promise<void>;
|
|
851
|
+
deleteMany(ids: string[]): Promise<number>;
|
|
852
|
+
touch(id: string): Promise<void>;
|
|
853
|
+
retrieve(query: MemoryRetrieveQuery, embedding?: number[]): Promise<Memory[]>;
|
|
854
|
+
count(filter?: MemoryCountFilter): Promise<number>;
|
|
855
|
+
close(): Promise<void>;
|
|
348
856
|
private _rowToMemory;
|
|
349
857
|
}
|
|
350
858
|
|
|
@@ -403,7 +911,7 @@ declare class AnthropicLLMAdapter implements LLMProvider {
|
|
|
403
911
|
private baseURL;
|
|
404
912
|
private defaultModel;
|
|
405
913
|
private defaultMaxTokens;
|
|
406
|
-
private sdk
|
|
914
|
+
private sdk?;
|
|
407
915
|
constructor(config: AnthropicLLMConfig);
|
|
408
916
|
complete(request: {
|
|
409
917
|
system: string;
|
|
@@ -431,6 +939,7 @@ declare class OpenAIEmbeddingAdapter implements EmbeddingProvider {
|
|
|
431
939
|
private baseURL;
|
|
432
940
|
private model;
|
|
433
941
|
readonly dimensions: number;
|
|
942
|
+
readonly maxBatchSize = 2048;
|
|
434
943
|
constructor(config: OpenAIEmbeddingConfig);
|
|
435
944
|
embed(texts: string[]): Promise<number[][]>;
|
|
436
945
|
}
|
|
@@ -448,6 +957,7 @@ declare class CohereEmbeddingAdapter implements EmbeddingProvider {
|
|
|
448
957
|
private baseURL;
|
|
449
958
|
private model;
|
|
450
959
|
readonly dimensions: number;
|
|
960
|
+
readonly maxBatchSize = 96;
|
|
451
961
|
constructor(config: CohereEmbeddingConfig);
|
|
452
962
|
embed(texts: string[]): Promise<number[][]>;
|
|
453
963
|
}
|
|
@@ -533,4 +1043,4 @@ declare class GroqLLMAdapter implements LLMProvider {
|
|
|
533
1043
|
}>;
|
|
534
1044
|
}
|
|
535
1045
|
|
|
536
|
-
export { AnthropicLLMAdapter, type AnthropicLLMConfig, CohereEmbeddingAdapter, type CohereEmbeddingConfig, type CompiledContext, type ContextOptions,
|
|
1046
|
+
export { AnthropicLLMAdapter, type AnthropicLLMConfig, CohereEmbeddingAdapter, type CohereEmbeddingConfig, type CompiledContext, type ContextOptions, DiskStorageAdapter, type DiskStorageConfig, type EmbeddingProvider, GroqLLMAdapter, type GroqLLMConfig, type HealthStatus, HybridStorageAdapter, type HybridStorageConfig, InMemoryStorageAdapter, type LLMProvider, LanceDBStorageAdapter, type LanceDBStorageConfig, MarkdownStorageAdapter, type MarkdownStorageConfig, MemStack, type MemStackConfig, MemStackError, type MemStackErrorCode, type MemStackSnapshot, type Memory, type MemoryCountFilter, type MemoryRetrieveQuery, type MemoryStats, type MemoryStoreInput, type MemoryType, MongoDBStorageAdapter, type MongoDBStorageConfig, Neo4jStorageAdapter, type Neo4jStorageConfig, OllamaLLMAdapter, type OllamaLLMConfig, OpenAIEmbeddingAdapter, type OpenAIEmbeddingConfig, OpenAILLMAdapter, type OpenAILLMConfig, PostgresStorageAdapter, type PostgresStorageConfig, type ProcessInput, type ProcessResult, type PruneStrategy, QdrantStorageAdapter, type QdrantStorageConfig, RedisStorageAdapter, type RedisStorageConfig, SQLiteStorageAdapter, type SQLiteStorageConfig, type StorageProvider, type SummarizeOptions, WeaviateStorageAdapter, type WeaviateStorageConfig, configError, notFound, storageError, validationError };
|