@memstack/core 0.2.0 → 0.4.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 +144 -56
- package/dist/index.cjs +2212 -262
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +496 -27
- package/dist/index.d.ts +496 -27
- package/dist/index.js +2203 -260
- package/dist/index.js.map +1 -1
- package/package.json +32 -32
- 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.cts
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: {
|
|
@@ -170,6 +201,16 @@ interface MemoryStoreConfig {
|
|
|
170
201
|
llm?: LLMProvider;
|
|
171
202
|
embedOnStore?: boolean;
|
|
172
203
|
summarizationPrompt?: string;
|
|
204
|
+
tokenCounter?: TokenCounter;
|
|
205
|
+
contextImportantRatio?: number;
|
|
206
|
+
limits?: {
|
|
207
|
+
dedupScan?: number;
|
|
208
|
+
contextScan?: number;
|
|
209
|
+
summarizeScan?: number;
|
|
210
|
+
pruneScan?: number;
|
|
211
|
+
exportScan?: number;
|
|
212
|
+
purgeScan?: number;
|
|
213
|
+
};
|
|
173
214
|
}
|
|
174
215
|
declare class MemoryStore {
|
|
175
216
|
private storage;
|
|
@@ -178,6 +219,10 @@ declare class MemoryStore {
|
|
|
178
219
|
private pruner;
|
|
179
220
|
private compiler;
|
|
180
221
|
private embedOnStore;
|
|
222
|
+
private limits;
|
|
223
|
+
private contentHashIndex;
|
|
224
|
+
private initialized;
|
|
225
|
+
private _ensureInit;
|
|
181
226
|
constructor(config: MemoryStoreConfig);
|
|
182
227
|
store(input: MemoryStoreInput): Promise<Memory>;
|
|
183
228
|
storeBatch(inputs: MemoryStoreInput[]): Promise<Memory[]>;
|
|
@@ -192,6 +237,10 @@ declare class MemoryStore {
|
|
|
192
237
|
summary: Memory;
|
|
193
238
|
deletedCount: number;
|
|
194
239
|
}>;
|
|
240
|
+
summarizeStream(options: SummarizeOptions): AsyncIterable<{
|
|
241
|
+
chunk: string;
|
|
242
|
+
text: string;
|
|
243
|
+
}>;
|
|
195
244
|
prune(strategy: PruneStrategy): Promise<{
|
|
196
245
|
pruned: string[];
|
|
197
246
|
count: number;
|
|
@@ -200,7 +249,11 @@ declare class MemoryStore {
|
|
|
200
249
|
wouldPrune: string[];
|
|
201
250
|
count: number;
|
|
202
251
|
}>;
|
|
203
|
-
export(): Promise<Memory[]>;
|
|
252
|
+
export(actorId?: string): Promise<Memory[]>;
|
|
253
|
+
stats(actorId?: string): Promise<MemoryStats>;
|
|
254
|
+
purgeActor(actorId: string): Promise<number>;
|
|
255
|
+
merge(ids: string[]): Promise<Memory>;
|
|
256
|
+
private _ensureHashIndex;
|
|
204
257
|
private _hashContent;
|
|
205
258
|
}
|
|
206
259
|
|
|
@@ -208,10 +261,11 @@ declare class MemStack {
|
|
|
208
261
|
readonly memory: MemoryStore;
|
|
209
262
|
private config;
|
|
210
263
|
private storage;
|
|
211
|
-
private
|
|
264
|
+
private processCounts;
|
|
265
|
+
private pruneCheckCount;
|
|
212
266
|
constructor(config: MemStackConfig);
|
|
213
267
|
process(input: ProcessInput): Promise<ProcessResult>;
|
|
214
|
-
export(): Promise<MemStackSnapshot>;
|
|
268
|
+
export(actorId?: string): Promise<MemStackSnapshot>;
|
|
215
269
|
import(snapshot: MemStackSnapshot): Promise<void>;
|
|
216
270
|
health(): Promise<HealthStatus>;
|
|
217
271
|
close(): Promise<void>;
|
|
@@ -236,7 +290,7 @@ declare function validationError(message: string, details?: Record<string, unkno
|
|
|
236
290
|
declare function storageError(message: string, cause?: unknown): MemStackError;
|
|
237
291
|
declare function configError(message: string): MemStackError;
|
|
238
292
|
|
|
239
|
-
declare class
|
|
293
|
+
declare class InMemoryStorageAdapter implements StorageProvider {
|
|
240
294
|
private memories;
|
|
241
295
|
initialize(): Promise<void>;
|
|
242
296
|
generateId(): string;
|
|
@@ -256,9 +310,10 @@ interface DiskStorageConfig {
|
|
|
256
310
|
/** Directory to store memory files. Default: "./memstack-data" */
|
|
257
311
|
storageDir?: string;
|
|
258
312
|
}
|
|
259
|
-
declare class
|
|
313
|
+
declare class DiskStorageAdapter implements StorageProvider {
|
|
260
314
|
private dir;
|
|
261
315
|
private _writeLocks;
|
|
316
|
+
private _idIndex;
|
|
262
317
|
constructor(config?: DiskStorageConfig);
|
|
263
318
|
initialize(): Promise<void>;
|
|
264
319
|
generateId(): string;
|
|
@@ -276,25 +331,126 @@ declare class DiskStorage implements StorageProvider {
|
|
|
276
331
|
private _writeFile;
|
|
277
332
|
private _withWriteLock;
|
|
278
333
|
private _listActors;
|
|
334
|
+
private _buildIndex;
|
|
279
335
|
private _toExternal;
|
|
280
336
|
}
|
|
281
337
|
|
|
338
|
+
interface MarkdownStorageConfig {
|
|
339
|
+
dir: string;
|
|
340
|
+
oneFilePerActor?: boolean;
|
|
341
|
+
}
|
|
342
|
+
declare class MarkdownStorageAdapter implements StorageProvider {
|
|
343
|
+
private dir;
|
|
344
|
+
private oneFilePerActor;
|
|
345
|
+
private _cache;
|
|
346
|
+
private _deletedIds;
|
|
347
|
+
private _cacheDirty;
|
|
348
|
+
constructor(config: MarkdownStorageConfig);
|
|
349
|
+
initialize(): Promise<void>;
|
|
350
|
+
generateId(): string;
|
|
351
|
+
store(input: MemoryStoreInput): Promise<Memory>;
|
|
352
|
+
storeBatch(inputs: MemoryStoreInput[]): Promise<Memory[]>;
|
|
353
|
+
get(id: string): Promise<Memory | null>;
|
|
354
|
+
delete(id: string): Promise<void>;
|
|
355
|
+
deleteMany(ids: string[]): Promise<number>;
|
|
356
|
+
retrieve(query: MemoryRetrieveQuery, _embedding?: number[]): Promise<Memory[]>;
|
|
357
|
+
count(filter?: MemoryCountFilter): Promise<number>;
|
|
358
|
+
close(): Promise<void>;
|
|
359
|
+
vacuum(): Promise<void>;
|
|
360
|
+
private _filePath;
|
|
361
|
+
private _formatBlock;
|
|
362
|
+
private _formatTombstone;
|
|
363
|
+
private _ensureCache;
|
|
364
|
+
private _parseFile;
|
|
365
|
+
private _vacuumFile;
|
|
366
|
+
private _listActors;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
interface HybridStorageConfig {
|
|
370
|
+
cache: StorageProvider;
|
|
371
|
+
durable: StorageProvider;
|
|
372
|
+
writeBoth?: boolean;
|
|
373
|
+
readFromCache?: boolean;
|
|
374
|
+
syncOnInit?: boolean;
|
|
375
|
+
}
|
|
376
|
+
declare class HybridStorageAdapter implements StorageProvider {
|
|
377
|
+
private cache;
|
|
378
|
+
private durable;
|
|
379
|
+
private writeBoth;
|
|
380
|
+
private readFromCache;
|
|
381
|
+
private syncOnInit;
|
|
382
|
+
constructor(config: HybridStorageConfig);
|
|
383
|
+
initialize(): Promise<void>;
|
|
384
|
+
store(input: MemoryStoreInput): Promise<Memory>;
|
|
385
|
+
storeBatch(inputs: MemoryStoreInput[]): Promise<Memory[]>;
|
|
386
|
+
get(id: string): Promise<Memory | null>;
|
|
387
|
+
retrieve(query: MemoryRetrieveQuery, embedding?: number[]): Promise<Memory[]>;
|
|
388
|
+
delete(id: string): Promise<void>;
|
|
389
|
+
deleteMany(ids: string[]): Promise<number>;
|
|
390
|
+
count(filter?: MemoryCountFilter): Promise<number>;
|
|
391
|
+
touch(id: string): Promise<void>;
|
|
392
|
+
close(): Promise<void>;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
type PgPool = {
|
|
396
|
+
query(text: string, params?: unknown[]): Promise<{
|
|
397
|
+
rows: unknown[];
|
|
398
|
+
}>;
|
|
399
|
+
end?: () => Promise<void>;
|
|
400
|
+
};
|
|
401
|
+
interface PostgresStorageConfig {
|
|
402
|
+
pool?: PgPool;
|
|
403
|
+
connectionString?: string;
|
|
404
|
+
host?: string;
|
|
405
|
+
port?: number;
|
|
406
|
+
database?: string;
|
|
407
|
+
user?: string;
|
|
408
|
+
password?: string;
|
|
409
|
+
tableName?: string;
|
|
410
|
+
vectorDimensions?: number;
|
|
411
|
+
ssl?: boolean | object;
|
|
412
|
+
}
|
|
413
|
+
declare class PostgresStorageAdapter implements StorageProvider {
|
|
414
|
+
private pool;
|
|
415
|
+
private table;
|
|
416
|
+
private vectorDimensions;
|
|
417
|
+
private _ownsPool;
|
|
418
|
+
constructor(config: PostgresStorageConfig);
|
|
419
|
+
private _connectionString?;
|
|
420
|
+
private _connParts?;
|
|
421
|
+
private _ssl?;
|
|
422
|
+
initialize(): Promise<void>;
|
|
423
|
+
private _createPool;
|
|
424
|
+
private _buildConnString;
|
|
425
|
+
private _runMigration;
|
|
426
|
+
generateId(): string;
|
|
427
|
+
store(input: MemoryStoreInput): Promise<Memory>;
|
|
428
|
+
storeBatch(inputs: MemoryStoreInput[]): Promise<Memory[]>;
|
|
429
|
+
get(id: string): Promise<Memory | null>;
|
|
430
|
+
delete(id: string): Promise<void>;
|
|
431
|
+
deleteMany(ids: string[]): Promise<number>;
|
|
432
|
+
touch(id: string): Promise<void>;
|
|
433
|
+
retrieve(query: MemoryRetrieveQuery, embedding?: number[]): Promise<Memory[]>;
|
|
434
|
+
count(filter?: MemoryCountFilter): Promise<number>;
|
|
435
|
+
close(): Promise<void>;
|
|
436
|
+
private _semanticRetrieve;
|
|
437
|
+
private _rowToMemory;
|
|
438
|
+
}
|
|
439
|
+
|
|
282
440
|
type RedisClient = {
|
|
283
441
|
set(key: string, value: string): Promise<unknown>;
|
|
284
442
|
get(key: string): Promise<string | null>;
|
|
285
|
-
mget(...keys: string[]): Promise<(string | null)[]>;
|
|
286
443
|
del(key: string | string[]): Promise<number>;
|
|
287
444
|
sadd(key: string, ...members: string[]): Promise<number>;
|
|
288
445
|
srem(key: string, ...members: string[]): Promise<number>;
|
|
289
446
|
smembers(key: string): Promise<string[]>;
|
|
447
|
+
mget(...keys: string[]): Promise<(string | null)[]>;
|
|
290
448
|
};
|
|
291
449
|
interface RedisStorageConfig {
|
|
292
|
-
/** An active ioredis client instance (or compatible) */
|
|
293
450
|
redis: RedisClient;
|
|
294
|
-
/** Key prefix. Default: "memstack" */
|
|
295
451
|
keyPrefix?: string;
|
|
296
452
|
}
|
|
297
|
-
declare class
|
|
453
|
+
declare class RedisStorageAdapter implements StorageProvider {
|
|
298
454
|
private redis;
|
|
299
455
|
private prefix;
|
|
300
456
|
constructor(config: RedisStorageConfig);
|
|
@@ -305,6 +461,7 @@ declare class RedisStorage implements StorageProvider {
|
|
|
305
461
|
get(id: string): Promise<Memory | null>;
|
|
306
462
|
delete(id: string): Promise<void>;
|
|
307
463
|
deleteMany(ids: string[]): Promise<number>;
|
|
464
|
+
touch(id: string): Promise<void>;
|
|
308
465
|
retrieve(query: MemoryRetrieveQuery, _embedding?: number[]): Promise<Memory[]>;
|
|
309
466
|
count(filter?: MemoryCountFilter): Promise<number>;
|
|
310
467
|
close(): Promise<void>;
|
|
@@ -316,24 +473,285 @@ declare class RedisStorage implements StorageProvider {
|
|
|
316
473
|
private _toExternal;
|
|
317
474
|
}
|
|
318
475
|
|
|
319
|
-
type
|
|
320
|
-
|
|
321
|
-
|
|
476
|
+
type QdrantClient = {
|
|
477
|
+
createCollection(name: string, config: {
|
|
478
|
+
vectors: {
|
|
479
|
+
size: number;
|
|
480
|
+
distance: string;
|
|
481
|
+
};
|
|
482
|
+
}): Promise<unknown>;
|
|
483
|
+
getCollection(name: string): Promise<unknown>;
|
|
484
|
+
upsert(name: string, opts: {
|
|
485
|
+
points: {
|
|
486
|
+
id: string;
|
|
487
|
+
vector: number[];
|
|
488
|
+
payload: Record<string, unknown>;
|
|
489
|
+
}[];
|
|
490
|
+
}): Promise<unknown>;
|
|
491
|
+
retrieve(name: string, opts: {
|
|
492
|
+
ids: string[];
|
|
493
|
+
}): Promise<unknown[]>;
|
|
494
|
+
search(name: string, opts: {
|
|
495
|
+
vector: number[];
|
|
496
|
+
limit: number;
|
|
497
|
+
filter?: {
|
|
498
|
+
must: unknown[];
|
|
499
|
+
};
|
|
500
|
+
}): Promise<unknown[]>;
|
|
501
|
+
delete(name: string, opts: {
|
|
502
|
+
points: string[];
|
|
503
|
+
}): Promise<unknown>;
|
|
504
|
+
count(name: string, opts?: {
|
|
505
|
+
filter?: {
|
|
506
|
+
must: unknown[];
|
|
507
|
+
};
|
|
508
|
+
}): Promise<{
|
|
509
|
+
count: number;
|
|
510
|
+
}>;
|
|
511
|
+
scroll(name: string, opts?: {
|
|
512
|
+
filter?: {
|
|
513
|
+
must: unknown[];
|
|
514
|
+
};
|
|
515
|
+
limit?: number;
|
|
516
|
+
}): Promise<{
|
|
517
|
+
points: unknown[];
|
|
322
518
|
}>;
|
|
323
519
|
};
|
|
324
|
-
interface
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
520
|
+
interface QdrantStorageConfig {
|
|
521
|
+
client: QdrantClient;
|
|
522
|
+
collectionName?: string;
|
|
523
|
+
vectorSize?: number;
|
|
524
|
+
}
|
|
525
|
+
declare class QdrantStorageAdapter implements StorageProvider {
|
|
526
|
+
private client;
|
|
527
|
+
private collectionName;
|
|
528
|
+
private vectorSize;
|
|
529
|
+
private _idToQdrant;
|
|
530
|
+
constructor(config: QdrantStorageConfig);
|
|
531
|
+
initialize(): Promise<void>;
|
|
532
|
+
generateId(): string;
|
|
533
|
+
store(input: MemoryStoreInput): Promise<Memory>;
|
|
534
|
+
storeBatch(inputs: MemoryStoreInput[]): Promise<Memory[]>;
|
|
535
|
+
get(id: string): Promise<Memory | null>;
|
|
536
|
+
delete(id: string): Promise<void>;
|
|
537
|
+
deleteMany(ids: string[]): Promise<number>;
|
|
538
|
+
retrieve(query: MemoryRetrieveQuery, embedding?: number[]): Promise<Memory[]>;
|
|
539
|
+
count(filter?: MemoryCountFilter): Promise<number>;
|
|
540
|
+
close(): Promise<void>;
|
|
541
|
+
private _toPayload;
|
|
542
|
+
private _fromPoint;
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
type Neo4jDriver = {
|
|
546
|
+
session(opts?: {
|
|
547
|
+
database?: string;
|
|
548
|
+
}): Neo4jSession;
|
|
549
|
+
close(): Promise<void>;
|
|
550
|
+
};
|
|
551
|
+
type Neo4jSession = {
|
|
552
|
+
run(query: string, params?: Record<string, unknown>): Promise<{
|
|
553
|
+
records: {
|
|
554
|
+
get(key: string): unknown;
|
|
555
|
+
toObject(): Record<string, unknown>;
|
|
556
|
+
}[];
|
|
557
|
+
}>;
|
|
558
|
+
close(): Promise<void>;
|
|
559
|
+
};
|
|
560
|
+
interface Neo4jStorageConfig {
|
|
561
|
+
driver: Neo4jDriver;
|
|
562
|
+
database?: string;
|
|
563
|
+
}
|
|
564
|
+
declare class Neo4jStorageAdapter implements StorageProvider {
|
|
565
|
+
private driver;
|
|
566
|
+
private database;
|
|
567
|
+
constructor(config: Neo4jStorageConfig);
|
|
568
|
+
initialize(): Promise<void>;
|
|
569
|
+
generateId(): string;
|
|
570
|
+
store(input: MemoryStoreInput): Promise<Memory>;
|
|
571
|
+
storeBatch(inputs: MemoryStoreInput[]): Promise<Memory[]>;
|
|
572
|
+
get(id: string): Promise<Memory | null>;
|
|
573
|
+
delete(id: string): Promise<void>;
|
|
574
|
+
deleteMany(ids: string[]): Promise<number>;
|
|
575
|
+
retrieve(query: MemoryRetrieveQuery, embedding?: number[]): Promise<Memory[]>;
|
|
576
|
+
count(filter?: MemoryCountFilter): Promise<number>;
|
|
577
|
+
graphQuery(cypher: string, params?: Record<string, unknown>): Promise<Memory[]>;
|
|
578
|
+
close(): Promise<void>;
|
|
579
|
+
private _semanticRetrieve;
|
|
580
|
+
private _postFilter;
|
|
581
|
+
private _nodeToMemory;
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
type WeaviateClient = {
|
|
585
|
+
collections: {
|
|
586
|
+
create(opts: {
|
|
587
|
+
name: string;
|
|
588
|
+
properties: {
|
|
589
|
+
name: string;
|
|
590
|
+
dataType: string;
|
|
591
|
+
}[];
|
|
592
|
+
vectorizers?: unknown;
|
|
593
|
+
}): Promise<unknown>;
|
|
594
|
+
get(name: string): WeaviateCollection;
|
|
595
|
+
delete(name: string): Promise<void>;
|
|
596
|
+
exists(name: string): Promise<boolean>;
|
|
597
|
+
listAll(): Promise<string[]>;
|
|
598
|
+
};
|
|
599
|
+
};
|
|
600
|
+
type WeaviateCollection = {
|
|
601
|
+
data: {
|
|
602
|
+
insert(opts: {
|
|
603
|
+
properties: Record<string, unknown>;
|
|
604
|
+
vectors: number[];
|
|
605
|
+
id?: string;
|
|
606
|
+
}): Promise<string>;
|
|
607
|
+
deleteById(id: string): Promise<void>;
|
|
608
|
+
};
|
|
609
|
+
query: {
|
|
610
|
+
fetchObjectById(id: string, opts?: {
|
|
611
|
+
includeVector?: boolean;
|
|
612
|
+
}): Promise<{
|
|
613
|
+
properties: Record<string, unknown>;
|
|
614
|
+
vectors?: {
|
|
615
|
+
default?: number[];
|
|
616
|
+
};
|
|
617
|
+
} | null>;
|
|
618
|
+
fetchObjects(opts: {
|
|
619
|
+
limit: number;
|
|
620
|
+
filters?: unknown;
|
|
621
|
+
includeVector?: boolean;
|
|
622
|
+
}): Promise<{
|
|
623
|
+
objects: {
|
|
624
|
+
uuid: string;
|
|
625
|
+
properties: Record<string, unknown>;
|
|
626
|
+
vectors?: {
|
|
627
|
+
default?: number[];
|
|
628
|
+
};
|
|
629
|
+
metadata?: {
|
|
630
|
+
creationTimeUnix: number;
|
|
631
|
+
};
|
|
632
|
+
}[];
|
|
633
|
+
}>;
|
|
634
|
+
nearVector(vector: number[], opts: {
|
|
635
|
+
limit: number;
|
|
636
|
+
returnProperties?: string[];
|
|
637
|
+
returnMetadata?: string[];
|
|
638
|
+
filters?: unknown;
|
|
639
|
+
includeVector?: boolean;
|
|
640
|
+
}): Promise<{
|
|
641
|
+
objects: {
|
|
642
|
+
uuid: string;
|
|
643
|
+
properties: Record<string, unknown>;
|
|
644
|
+
vectors?: {
|
|
645
|
+
default?: number[];
|
|
646
|
+
};
|
|
647
|
+
metadata?: {
|
|
648
|
+
creationTimeUnix: number;
|
|
649
|
+
};
|
|
650
|
+
}[];
|
|
651
|
+
}>;
|
|
652
|
+
};
|
|
653
|
+
config: {
|
|
654
|
+
get(): Promise<{
|
|
655
|
+
name: string;
|
|
656
|
+
}>;
|
|
657
|
+
update(opts: {
|
|
658
|
+
vectorIndexConfig: Record<string, unknown>;
|
|
659
|
+
}): Promise<void>;
|
|
660
|
+
};
|
|
661
|
+
};
|
|
662
|
+
interface WeaviateStorageConfig {
|
|
663
|
+
client: WeaviateClient;
|
|
664
|
+
className?: string;
|
|
665
|
+
}
|
|
666
|
+
declare class WeaviateStorageAdapter implements StorageProvider {
|
|
667
|
+
private client;
|
|
668
|
+
private className;
|
|
669
|
+
private _collection;
|
|
670
|
+
private _idToWv;
|
|
671
|
+
constructor(config: WeaviateStorageConfig);
|
|
672
|
+
initialize(): Promise<void>;
|
|
673
|
+
private collection;
|
|
674
|
+
generateId(): string;
|
|
675
|
+
store(input: MemoryStoreInput): Promise<Memory>;
|
|
676
|
+
storeBatch(inputs: MemoryStoreInput[]): Promise<Memory[]>;
|
|
677
|
+
get(id: string): Promise<Memory | null>;
|
|
678
|
+
delete(id: string): Promise<void>;
|
|
679
|
+
deleteMany(ids: string[]): Promise<number>;
|
|
680
|
+
retrieve(query: MemoryRetrieveQuery, embedding?: number[]): Promise<Memory[]>;
|
|
681
|
+
count(filter?: MemoryCountFilter): Promise<number>;
|
|
682
|
+
close(): Promise<void>;
|
|
683
|
+
private _buildFilter;
|
|
684
|
+
private _toProperties;
|
|
685
|
+
private _fromProperties;
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
type LanceDBConnection = {
|
|
689
|
+
createTable(name: string, data: {
|
|
690
|
+
id: string;
|
|
691
|
+
vector: number[];
|
|
692
|
+
actor_id: string;
|
|
693
|
+
memory_type: string;
|
|
694
|
+
content: string;
|
|
695
|
+
importance: number;
|
|
696
|
+
emotional_valence: number;
|
|
697
|
+
tags: string;
|
|
698
|
+
source_id: string;
|
|
699
|
+
metadata: string;
|
|
700
|
+
expires_at: string;
|
|
701
|
+
created_at: string;
|
|
702
|
+
}[]): Promise<LanceDBTable>;
|
|
703
|
+
openTable(name: string): Promise<LanceDBTable>;
|
|
704
|
+
tableNames(): Promise<string[]>;
|
|
705
|
+
};
|
|
706
|
+
type LanceDBTable = {
|
|
707
|
+
add(data: {
|
|
708
|
+
id: string;
|
|
709
|
+
vector: number[];
|
|
710
|
+
actor_id: string;
|
|
711
|
+
memory_type: string;
|
|
712
|
+
content: string;
|
|
713
|
+
importance: number;
|
|
714
|
+
emotional_valence: number;
|
|
715
|
+
tags: string;
|
|
716
|
+
source_id: string;
|
|
717
|
+
metadata: string;
|
|
718
|
+
expires_at: string;
|
|
719
|
+
created_at: string;
|
|
720
|
+
}[]): Promise<void>;
|
|
721
|
+
search(vector: number[]): {
|
|
722
|
+
limit(n: number): {
|
|
723
|
+
where(predicate: string): {
|
|
724
|
+
execute(): Promise<{
|
|
725
|
+
id: string;
|
|
726
|
+
_distance: number;
|
|
727
|
+
vector: number[];
|
|
728
|
+
actor_id: string;
|
|
729
|
+
memory_type: string;
|
|
730
|
+
content: string;
|
|
731
|
+
importance: number;
|
|
732
|
+
emotional_valence: number;
|
|
733
|
+
tags: string;
|
|
734
|
+
source_id: string;
|
|
735
|
+
metadata: string;
|
|
736
|
+
expires_at: string;
|
|
737
|
+
created_at: string;
|
|
738
|
+
}[]>;
|
|
739
|
+
};
|
|
740
|
+
};
|
|
741
|
+
};
|
|
742
|
+
delete(predicate: string): Promise<void>;
|
|
743
|
+
countRows(predicate?: string): Promise<number>;
|
|
744
|
+
};
|
|
745
|
+
interface LanceDBStorageConfig {
|
|
746
|
+
connection: LanceDBConnection;
|
|
328
747
|
tableName?: string;
|
|
329
|
-
/** Automatically run CREATE TABLE IF NOT EXISTS on init. Default: true */
|
|
330
|
-
autoMigrate?: boolean;
|
|
331
748
|
}
|
|
332
|
-
declare class
|
|
333
|
-
private
|
|
749
|
+
declare class LanceDBStorageAdapter implements StorageProvider {
|
|
750
|
+
private connection;
|
|
334
751
|
private table;
|
|
335
|
-
private
|
|
336
|
-
|
|
752
|
+
private tableName;
|
|
753
|
+
private _zeroVector;
|
|
754
|
+
constructor(config: LanceDBStorageConfig);
|
|
337
755
|
initialize(): Promise<void>;
|
|
338
756
|
generateId(): string;
|
|
339
757
|
store(input: MemoryStoreInput): Promise<Memory>;
|
|
@@ -344,10 +762,61 @@ declare class PostgresStorage implements StorageProvider {
|
|
|
344
762
|
retrieve(query: MemoryRetrieveQuery, embedding?: number[]): Promise<Memory[]>;
|
|
345
763
|
count(filter?: MemoryCountFilter): Promise<number>;
|
|
346
764
|
close(): Promise<void>;
|
|
347
|
-
private _semanticRetrieve;
|
|
348
765
|
private _rowToMemory;
|
|
349
766
|
}
|
|
350
767
|
|
|
768
|
+
type MongoCollection = {
|
|
769
|
+
insertOne(doc: Record<string, unknown>): Promise<{
|
|
770
|
+
insertedId: string;
|
|
771
|
+
}>;
|
|
772
|
+
findOne(filter: Record<string, unknown>): Promise<Record<string, unknown> | null>;
|
|
773
|
+
updateOne(filter: Record<string, unknown>, update: Record<string, unknown>, opts?: {
|
|
774
|
+
upsert?: boolean;
|
|
775
|
+
}): Promise<{
|
|
776
|
+
upsertedId?: string;
|
|
777
|
+
}>;
|
|
778
|
+
deleteOne(filter: Record<string, unknown>): Promise<{
|
|
779
|
+
deletedCount: number;
|
|
780
|
+
}>;
|
|
781
|
+
deleteMany(filter: Record<string, unknown>): Promise<{
|
|
782
|
+
deletedCount: number;
|
|
783
|
+
}>;
|
|
784
|
+
find(filter: Record<string, unknown>): {
|
|
785
|
+
sort(sort: Record<string, number>): {
|
|
786
|
+
limit(n: number): {
|
|
787
|
+
toArray(): Promise<Record<string, unknown>[]>;
|
|
788
|
+
};
|
|
789
|
+
};
|
|
790
|
+
};
|
|
791
|
+
countDocuments(filter?: Record<string, unknown>): Promise<number>;
|
|
792
|
+
aggregate(pipeline: Record<string, unknown>[]): {
|
|
793
|
+
toArray(): Promise<Record<string, unknown>[]>;
|
|
794
|
+
};
|
|
795
|
+
};
|
|
796
|
+
interface MongoDBStorageConfig {
|
|
797
|
+
collection: MongoCollection;
|
|
798
|
+
vectorDimensions?: number;
|
|
799
|
+
}
|
|
800
|
+
declare class MongoDBStorageAdapter implements StorageProvider {
|
|
801
|
+
private collection;
|
|
802
|
+
private vectorDimensions;
|
|
803
|
+
constructor(config: MongoDBStorageConfig);
|
|
804
|
+
initialize(): Promise<void>;
|
|
805
|
+
generateId(): string;
|
|
806
|
+
store(input: MemoryStoreInput): Promise<Memory>;
|
|
807
|
+
storeBatch(inputs: MemoryStoreInput[]): Promise<Memory[]>;
|
|
808
|
+
get(id: string): Promise<Memory | null>;
|
|
809
|
+
delete(id: string): Promise<void>;
|
|
810
|
+
deleteMany(ids: string[]): Promise<number>;
|
|
811
|
+
retrieve(query: MemoryRetrieveQuery, embedding?: number[]): Promise<Memory[]>;
|
|
812
|
+
count(filter?: MemoryCountFilter): Promise<number>;
|
|
813
|
+
close(): Promise<void>;
|
|
814
|
+
private retrieveStandard;
|
|
815
|
+
private retrieveSemantic;
|
|
816
|
+
private toMemory;
|
|
817
|
+
private toDoc;
|
|
818
|
+
}
|
|
819
|
+
|
|
351
820
|
interface OpenAILLMConfig {
|
|
352
821
|
apiKey: string;
|
|
353
822
|
baseURL?: string;
|
|
@@ -403,7 +872,7 @@ declare class AnthropicLLMAdapter implements LLMProvider {
|
|
|
403
872
|
private baseURL;
|
|
404
873
|
private defaultModel;
|
|
405
874
|
private defaultMaxTokens;
|
|
406
|
-
private sdk
|
|
875
|
+
private sdk?;
|
|
407
876
|
constructor(config: AnthropicLLMConfig);
|
|
408
877
|
complete(request: {
|
|
409
878
|
system: string;
|
|
@@ -533,4 +1002,4 @@ declare class GroqLLMAdapter implements LLMProvider {
|
|
|
533
1002
|
}>;
|
|
534
1003
|
}
|
|
535
1004
|
|
|
536
|
-
export { AnthropicLLMAdapter, type AnthropicLLMConfig, CohereEmbeddingAdapter, type CohereEmbeddingConfig, type CompiledContext, type ContextOptions,
|
|
1005
|
+
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, type StorageProvider, type SummarizeOptions, WeaviateStorageAdapter, type WeaviateStorageConfig, configError, notFound, storageError, validationError };
|