wolbarg 0.3.2 → 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/CHANGELOG.md +42 -0
- package/README.md +35 -1
- package/dist/index.cjs +4202 -627
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +541 -23
- package/dist/index.d.ts +541 -23
- package/dist/index.js +4194 -626
- package/dist/index.js.map +1 -1
- package/package.json +11 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { DatabaseSync } from 'node:sqlite';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Metadata filter AST for advanced recall filtering.
|
|
3
5
|
*/
|
|
@@ -47,7 +49,7 @@ declare const meta: {
|
|
|
47
49
|
* Schema is intentionally extensible for future providers (Postgres, cloud).
|
|
48
50
|
*/
|
|
49
51
|
/** Public operation names recorded as telemetry events. */
|
|
50
|
-
type TelemetryOperation = "remember" | "recall" | "forget" | "compress" | "rememberBatch" | "recallBatch" | "export" | "import" | "checkpoint" | "rollback" | "error" | "startup" | "shutdown" | "ingest" | "history" | "stats" | "clear" | "deleteCheckpoint" | "listCheckpoints" | "getCheckpoint";
|
|
52
|
+
type TelemetryOperation = "remember" | "recall" | "forget" | "compress" | "rememberBatch" | "recallBatch" | "export" | "import" | "checkpoint" | "rollback" | "error" | "startup" | "shutdown" | "ingest" | "history" | "stats" | "clear" | "deleteCheckpoint" | "listCheckpoints" | "getCheckpoint" | "linkMemories" | "getRelated" | "graphQuery";
|
|
51
53
|
type TelemetryStatus = "ok" | "error" | "cancelled";
|
|
52
54
|
type TelemetryLogLevel = "off" | "error" | "warn" | "info" | "debug" | "trace";
|
|
53
55
|
/** Stage-level latency breakdown recorded on each event. */
|
|
@@ -224,8 +226,10 @@ interface PostgresDatabaseConfig {
|
|
|
224
226
|
connectionString?: string;
|
|
225
227
|
/** v0.3 preferred alias for the Postgres connection string. */
|
|
226
228
|
url?: string;
|
|
227
|
-
/** Optional max pool size. Defaults to
|
|
229
|
+
/** Optional max pool size. Defaults to 64. */
|
|
228
230
|
maxPoolSize?: number;
|
|
231
|
+
/** When false, uses asynchronous commit for higher write throughput. */
|
|
232
|
+
durableWrites?: boolean;
|
|
229
233
|
}
|
|
230
234
|
/** Discriminated union of database configs. */
|
|
231
235
|
type DatabaseConfig = SqliteDatabaseConfig | PostgresDatabaseConfig;
|
|
@@ -302,6 +306,30 @@ interface InitOptions {
|
|
|
302
306
|
*/
|
|
303
307
|
llm?: LlmConfig;
|
|
304
308
|
}
|
|
309
|
+
/** Write-time memory dedupe strategy. */
|
|
310
|
+
type MemoryDedupeStrategy = "exact" | "near" | "exact-or-near";
|
|
311
|
+
/** Constructor / per-call memory dedupe configuration. */
|
|
312
|
+
interface MemoryDedupeConfig {
|
|
313
|
+
enabled?: boolean;
|
|
314
|
+
strategy?: MemoryDedupeStrategy;
|
|
315
|
+
/** Cosine similarity threshold for near-dup matching. Default 0.92 */
|
|
316
|
+
nearThreshold?: number;
|
|
317
|
+
/** Max vector candidates considered for near-dup. Default 8 */
|
|
318
|
+
nearCandidateLimit?: number;
|
|
319
|
+
}
|
|
320
|
+
/** SQLite multi-writer concurrency tuning. */
|
|
321
|
+
interface ConcurrencyConfig$1 {
|
|
322
|
+
maxRetries?: number;
|
|
323
|
+
baseBackoffMs?: number;
|
|
324
|
+
maxBackoffMs?: number;
|
|
325
|
+
lockTimeoutMs?: number;
|
|
326
|
+
}
|
|
327
|
+
/** Transparent embedding cache configuration. */
|
|
328
|
+
interface EmbeddingCacheConfig {
|
|
329
|
+
enabled?: boolean;
|
|
330
|
+
ttlMs?: number;
|
|
331
|
+
maxEntries?: number;
|
|
332
|
+
}
|
|
305
333
|
/** Input for {@link Wolbarg.remember}. */
|
|
306
334
|
interface RememberOptions {
|
|
307
335
|
/** Agent identifier that owns this memory. */
|
|
@@ -310,6 +338,14 @@ interface RememberOptions {
|
|
|
310
338
|
content: MemoryContent;
|
|
311
339
|
/** Optional opaque metadata. Stored and returned as-is. */
|
|
312
340
|
metadata?: MemoryMetadata;
|
|
341
|
+
/** Per-call dedupe override; undefined uses constructor `memory.dedupe`. */
|
|
342
|
+
dedupe?: boolean | MemoryDedupeConfig;
|
|
343
|
+
}
|
|
344
|
+
/** Whether remember created a new row or updated an existing one. */
|
|
345
|
+
type RememberAction = "created" | "updated";
|
|
346
|
+
/** Result of {@link Wolbarg.remember} — MemoryRecord plus upsert action. */
|
|
347
|
+
interface RememberResult extends MemoryRecord {
|
|
348
|
+
action: RememberAction;
|
|
313
349
|
}
|
|
314
350
|
/** Optional filter applied to recall / forget / compress operations. */
|
|
315
351
|
interface MemoryFilter {
|
|
@@ -352,6 +388,12 @@ interface RecallOptions {
|
|
|
352
388
|
* When `true`, return enriched explain results instead of plain RecallResult[].
|
|
353
389
|
*/
|
|
354
390
|
explain?: boolean;
|
|
391
|
+
/**
|
|
392
|
+
* When `true` and a graph provider is configured, each hit includes
|
|
393
|
+
* `related` memories from {@link GraphProvider.getRelated}.
|
|
394
|
+
* Omitted / false → no behavior change (related is absent).
|
|
395
|
+
*/
|
|
396
|
+
includeGraph?: boolean;
|
|
355
397
|
}
|
|
356
398
|
/** A single recalled memory with similarity score. */
|
|
357
399
|
interface RecallResult {
|
|
@@ -364,6 +406,11 @@ interface RecallResult {
|
|
|
364
406
|
similarity: number;
|
|
365
407
|
createdAt: Date;
|
|
366
408
|
updatedAt: Date;
|
|
409
|
+
/**
|
|
410
|
+
* Present only when `recall({ includeGraph: true })` and a graph provider
|
|
411
|
+
* is configured. Related memories via graph traversal (depth 1, both dirs).
|
|
412
|
+
*/
|
|
413
|
+
related?: MemoryRecord[];
|
|
367
414
|
}
|
|
368
415
|
/** Enriched recall hit when `explain: true`. */
|
|
369
416
|
interface RecallExplanationHit {
|
|
@@ -465,7 +512,7 @@ interface HistoryOptions {
|
|
|
465
512
|
interface HistoryEvent {
|
|
466
513
|
id: string;
|
|
467
514
|
memoryId: string;
|
|
468
|
-
eventType: "created" | "archived" | "compressed";
|
|
515
|
+
eventType: "created" | "archived" | "compressed" | "updated";
|
|
469
516
|
relatedMemoryId: string | null;
|
|
470
517
|
createdAt: Date;
|
|
471
518
|
}
|
|
@@ -543,6 +590,107 @@ interface IngestResult {
|
|
|
543
590
|
usedVision: boolean;
|
|
544
591
|
}
|
|
545
592
|
|
|
593
|
+
/**
|
|
594
|
+
* Graph memory provider contract.
|
|
595
|
+
*
|
|
596
|
+
* Mirrors {@link StorageProvider} lifecycle naming (`open` / `close` / `health`
|
|
597
|
+
* pattern via `health()`). Fully optional — omitting a graph provider does not
|
|
598
|
+
* change existing memory behavior.
|
|
599
|
+
*
|
|
600
|
+
* ## Portability contract
|
|
601
|
+
*
|
|
602
|
+
* - The five typed methods (`linkMemories`, `unlinkMemories`, `getRelated`,
|
|
603
|
+
* `upsertEntity`, `linkEntityToMemory`) are **guaranteed** identical behavior
|
|
604
|
+
* across SQLite and Neo4j. This is the tested, supported contract (see
|
|
605
|
+
* `graph-parity.test.ts`).
|
|
606
|
+
* - `query(cypher, params)` is supported on Neo4j only. The SQLite graph
|
|
607
|
+
* provider **hard-errors** immediately — SQLite has no Cypher. Use typed
|
|
608
|
+
* methods for portable code, or query the graph SQLite tables directly if you
|
|
609
|
+
* need raw SQL locally.
|
|
610
|
+
* - `health()` guarantees only `ok` and `backend`. The `details` payload
|
|
611
|
+
* differs (embedded file path vs networked cluster/connection info).
|
|
612
|
+
* - `deleteMemory` supports hard-delete cascade from `forget` / `clear` and is
|
|
613
|
+
* part of the portable typed surface.
|
|
614
|
+
*/
|
|
615
|
+
|
|
616
|
+
/** Direction for {@link GraphProvider.getRelated}. */
|
|
617
|
+
type GraphDirection = "in" | "out" | "both";
|
|
618
|
+
interface GetRelatedOptions {
|
|
619
|
+
relation?: string;
|
|
620
|
+
/** Traversal depth (default 1). */
|
|
621
|
+
depth?: number;
|
|
622
|
+
direction?: GraphDirection;
|
|
623
|
+
}
|
|
624
|
+
interface GraphEntityInput {
|
|
625
|
+
name: string;
|
|
626
|
+
type: string;
|
|
627
|
+
metadata?: Record<string, unknown>;
|
|
628
|
+
}
|
|
629
|
+
interface GraphHealthResult {
|
|
630
|
+
ok: boolean;
|
|
631
|
+
backend: string;
|
|
632
|
+
details?: unknown;
|
|
633
|
+
}
|
|
634
|
+
/**
|
|
635
|
+
* Pluggable graph store for memory–memory and entity–memory relations.
|
|
636
|
+
*
|
|
637
|
+
* Typed CRUD methods MUST be implemented with each backend’s native driver API
|
|
638
|
+
* (not by routing through {@link GraphProvider.query}). `query()` is the
|
|
639
|
+
* user-facing raw escape hatch only (Neo4j); SQLite throws.
|
|
640
|
+
*/
|
|
641
|
+
interface GraphProvider {
|
|
642
|
+
readonly name: string;
|
|
643
|
+
/** Open connection / embedded database and ensure schema. */
|
|
644
|
+
open(): Promise<void>;
|
|
645
|
+
/** Close the underlying connection. */
|
|
646
|
+
close(): Promise<void>;
|
|
647
|
+
/**
|
|
648
|
+
* Create (or ensure) a directed relation between two memory nodes.
|
|
649
|
+
* Implementations create stub Memory nodes when missing.
|
|
650
|
+
*/
|
|
651
|
+
linkMemories(fromId: string, toId: string, relation: string, metadata?: Record<string, unknown>): Promise<void>;
|
|
652
|
+
/** Remove relation(s) between two memory nodes. */
|
|
653
|
+
unlinkMemories(fromId: string, toId: string, relation?: string): Promise<void>;
|
|
654
|
+
/**
|
|
655
|
+
* Traverse from a memory node and return related Memory records as stored
|
|
656
|
+
* in the graph (facade may re-hydrate from SQL storage).
|
|
657
|
+
*/
|
|
658
|
+
getRelated(memoryId: string, options?: GetRelatedOptions): Promise<MemoryRecord[]>;
|
|
659
|
+
/** Upsert an entity node; returns stable entity id. */
|
|
660
|
+
upsertEntity(entity: GraphEntityInput): Promise<string>;
|
|
661
|
+
/** Link an entity to a memory with an optional role. */
|
|
662
|
+
linkEntityToMemory(entityId: string, memoryId: string, role?: string): Promise<void>;
|
|
663
|
+
/**
|
|
664
|
+
* Hard-delete a memory node and all incident edges (cascade for forget/clear).
|
|
665
|
+
*/
|
|
666
|
+
deleteMemory(memoryId: string): Promise<void>;
|
|
667
|
+
/**
|
|
668
|
+
* Raw Cypher escape hatch. Supported on Neo4j only — the SQLite provider
|
|
669
|
+
* throws a typed error. See module portability contract above.
|
|
670
|
+
*/
|
|
671
|
+
query(cypher: string, params?: Record<string, unknown>): Promise<unknown>;
|
|
672
|
+
health(): Promise<GraphHealthResult>;
|
|
673
|
+
/**
|
|
674
|
+
* When true, checkpoint/export may snapshot {@link getDataPath}.
|
|
675
|
+
* Network-backed providers (Neo4j) return false.
|
|
676
|
+
*/
|
|
677
|
+
supportsFileSnapshot(): boolean;
|
|
678
|
+
/** Absolute path to the embedded graph data directory/file, if any. */
|
|
679
|
+
getDataPath(): string | null;
|
|
680
|
+
}
|
|
681
|
+
/** Config shape accepted by `wolbarg({ graph: … })` when not passing an instance. */
|
|
682
|
+
type GraphConfig = {
|
|
683
|
+
provider: "sqlite";
|
|
684
|
+
path: string;
|
|
685
|
+
} | {
|
|
686
|
+
provider: "neo4j";
|
|
687
|
+
url: string;
|
|
688
|
+
username: string;
|
|
689
|
+
password: string;
|
|
690
|
+
database?: string;
|
|
691
|
+
};
|
|
692
|
+
type GraphInput$1 = GraphProvider | GraphConfig;
|
|
693
|
+
|
|
546
694
|
/**
|
|
547
695
|
* Chunking strategies for document ingestion.
|
|
548
696
|
*/
|
|
@@ -768,6 +916,7 @@ interface MemoryRow {
|
|
|
768
916
|
metadata_json: string;
|
|
769
917
|
archived: number;
|
|
770
918
|
compressed_into: string | null;
|
|
919
|
+
content_hash?: string | null;
|
|
771
920
|
created_at: string;
|
|
772
921
|
updated_at: string;
|
|
773
922
|
rowid?: number;
|
|
@@ -776,7 +925,7 @@ interface MemoryRow {
|
|
|
776
925
|
interface HistoryRow {
|
|
777
926
|
id: string;
|
|
778
927
|
memory_id: string;
|
|
779
|
-
event_type: "created" | "archived" | "compressed";
|
|
928
|
+
event_type: "created" | "archived" | "compressed" | "updated";
|
|
780
929
|
related_memory_id: string | null;
|
|
781
930
|
created_at: string;
|
|
782
931
|
}
|
|
@@ -790,6 +939,7 @@ interface InsertMemoryInput {
|
|
|
790
939
|
embedding: Float32Array;
|
|
791
940
|
createdAt: string;
|
|
792
941
|
updatedAt: string;
|
|
942
|
+
contentHash?: string | null;
|
|
793
943
|
}
|
|
794
944
|
/** Payload for updating memory content / metadata. */
|
|
795
945
|
interface UpdateMemoryInput {
|
|
@@ -799,6 +949,7 @@ interface UpdateMemoryInput {
|
|
|
799
949
|
metadata?: MemoryMetadata;
|
|
800
950
|
embedding?: Float32Array;
|
|
801
951
|
updatedAt: string;
|
|
952
|
+
contentHash?: string | null;
|
|
802
953
|
}
|
|
803
954
|
/** Filters used by repository queries. */
|
|
804
955
|
interface RepositoryFilter {
|
|
@@ -834,6 +985,11 @@ interface StorageProvider {
|
|
|
834
985
|
insertMemoriesBatch(inputs: InsertMemoryInput[]): Promise<MemoryRow[]>;
|
|
835
986
|
/** Update memory fields and optionally replace embedding. */
|
|
836
987
|
updateMemory(input: UpdateMemoryInput): Promise<MemoryRow | null>;
|
|
988
|
+
/**
|
|
989
|
+
* Find an active (non-archived) memory by content hash within org+agent.
|
|
990
|
+
* Used by write-time exact dedupe.
|
|
991
|
+
*/
|
|
992
|
+
findActiveByContentHash?(organization: string, agent: string, contentHash: string): Promise<MemoryRow | null>;
|
|
837
993
|
/** Fetch a memory by UUID. */
|
|
838
994
|
getMemoryById(id: string, organization: string): Promise<MemoryRow | null>;
|
|
839
995
|
/** Fetch a memory by its integer rowid. */
|
|
@@ -990,6 +1146,7 @@ declare function openaiVision(options: {
|
|
|
990
1146
|
type EmbeddingInput = EmbeddingProvider | EmbeddingConfig;
|
|
991
1147
|
type LlmInput = LlmProvider | LlmConfig;
|
|
992
1148
|
type StorageInput = StorageProvider | StorageConfig | DatabaseConfig;
|
|
1149
|
+
type GraphInput = GraphProvider | GraphConfig;
|
|
993
1150
|
interface WolbargOptionsBase {
|
|
994
1151
|
/** Organization namespace isolating memories within a shared database. */
|
|
995
1152
|
organization: string;
|
|
@@ -1018,12 +1175,26 @@ interface WolbargOptionsBase {
|
|
|
1018
1175
|
ocr?: OCRProvider;
|
|
1019
1176
|
/** Optional vision model for image captions. */
|
|
1020
1177
|
vision?: VisionProvider;
|
|
1178
|
+
/**
|
|
1179
|
+
* Optional graph memory layer (SQLite embedded or Neo4j networked).
|
|
1180
|
+
* Fully optional — omitting it does not change existing memory behavior.
|
|
1181
|
+
* Accepts a {@link GraphProvider} instance or a recognized config shape.
|
|
1182
|
+
*/
|
|
1183
|
+
graph?: GraphInput;
|
|
1021
1184
|
/** Optional compression provider (overrides llm-backed default). */
|
|
1022
1185
|
compression?: CompressionProvider;
|
|
1023
1186
|
/** Optional default chunking strategy for ingest. */
|
|
1024
1187
|
chunking?: ChunkingStrategy;
|
|
1025
1188
|
/** Optional retrieval defaults. */
|
|
1026
1189
|
retrieval?: RetrievalConfig;
|
|
1190
|
+
/** SQLite multi-writer concurrency tuning (ignored for Postgres). */
|
|
1191
|
+
concurrency?: ConcurrencyConfig$1;
|
|
1192
|
+
/** Transparent embedding cache (default enabled). */
|
|
1193
|
+
embeddingCache?: EmbeddingCacheConfig;
|
|
1194
|
+
/** Memory write-path options (dedupe / upsert). */
|
|
1195
|
+
memory?: {
|
|
1196
|
+
dedupe?: MemoryDedupeConfig;
|
|
1197
|
+
};
|
|
1027
1198
|
}
|
|
1028
1199
|
interface WolbargOptionsWithoutLlm extends WolbargOptionsBase {
|
|
1029
1200
|
llm?: undefined;
|
|
@@ -1034,6 +1205,29 @@ interface WolbargOptionsWithLlm extends WolbargOptionsBase {
|
|
|
1034
1205
|
}
|
|
1035
1206
|
type WolbargOptions = WolbargOptionsWithoutLlm | WolbargOptionsWithLlm;
|
|
1036
1207
|
|
|
1208
|
+
/**
|
|
1209
|
+
* Public subscribe() types for real-time memory change events.
|
|
1210
|
+
*/
|
|
1211
|
+
type SubscribableEvent = "remember" | "update" | "forget" | "compress" | "ingest" | "*";
|
|
1212
|
+
interface SubscribeFilter {
|
|
1213
|
+
organization: string;
|
|
1214
|
+
agent?: string;
|
|
1215
|
+
event?: SubscribableEvent | SubscribableEvent[];
|
|
1216
|
+
}
|
|
1217
|
+
interface MemoryChangeEvent {
|
|
1218
|
+
event: Exclude<SubscribableEvent, "*">;
|
|
1219
|
+
organization: string;
|
|
1220
|
+
agent: string;
|
|
1221
|
+
memoryId: string | string[];
|
|
1222
|
+
timestamp: string;
|
|
1223
|
+
traceId?: string;
|
|
1224
|
+
sessionId?: string;
|
|
1225
|
+
/** Present when upsert path ran during remember/ingest. */
|
|
1226
|
+
upsertAction?: "created" | "updated" | "skipped";
|
|
1227
|
+
}
|
|
1228
|
+
type MemoryChangeCallback = (event: MemoryChangeEvent) => void;
|
|
1229
|
+
type Unsubscribe = () => void;
|
|
1230
|
+
|
|
1037
1231
|
/**
|
|
1038
1232
|
* Wolbarg — modular semantic memory SDK for AI agents (v0.3).
|
|
1039
1233
|
*
|
|
@@ -1074,6 +1268,7 @@ declare class Wolbarg<HasLlm extends boolean = false> {
|
|
|
1074
1268
|
private keywordSearch;
|
|
1075
1269
|
private ocr;
|
|
1076
1270
|
private vision;
|
|
1271
|
+
private graph;
|
|
1077
1272
|
private chunking;
|
|
1078
1273
|
private retrievalConfig;
|
|
1079
1274
|
private embeddingDimensions;
|
|
@@ -1082,6 +1277,11 @@ declare class Wolbarg<HasLlm extends boolean = false> {
|
|
|
1082
1277
|
private checkpointProvider;
|
|
1083
1278
|
private memoryDbPath;
|
|
1084
1279
|
private readonly transfer;
|
|
1280
|
+
private subscribeBackend;
|
|
1281
|
+
private pgListenBackend;
|
|
1282
|
+
private memoryDedupe;
|
|
1283
|
+
private embeddingCacheConfig;
|
|
1284
|
+
private rawEmbedding;
|
|
1085
1285
|
constructor(options: WolbargOptionsWithLlm);
|
|
1086
1286
|
constructor(options: WolbargOptionsWithoutLlm);
|
|
1087
1287
|
constructor();
|
|
@@ -1092,10 +1292,31 @@ declare class Wolbarg<HasLlm extends boolean = false> {
|
|
|
1092
1292
|
/** Ensure storage (and optional telemetry) are open. */
|
|
1093
1293
|
ready(): Promise<void>;
|
|
1094
1294
|
private boot;
|
|
1095
|
-
/** Store a semantic memory for an agent. */
|
|
1096
|
-
remember(options: RememberOptions): Promise<
|
|
1097
|
-
/** Batch remember —
|
|
1098
|
-
rememberBatch(items: RememberOptions[]): Promise<
|
|
1295
|
+
/** Store a semantic memory for an agent (may upsert when dedupe is enabled). */
|
|
1296
|
+
remember(options: RememberOptions): Promise<RememberResult>;
|
|
1297
|
+
/** Batch remember — sequential when dedupe enabled; otherwise one TX batch. */
|
|
1298
|
+
rememberBatch(items: RememberOptions[]): Promise<RememberResult[]>;
|
|
1299
|
+
/**
|
|
1300
|
+
* Update an existing memory by id (re-embeds when content changes).
|
|
1301
|
+
*/
|
|
1302
|
+
update(options: {
|
|
1303
|
+
id: string;
|
|
1304
|
+
content?: {
|
|
1305
|
+
text: string;
|
|
1306
|
+
};
|
|
1307
|
+
metadata?: MemoryMetadata;
|
|
1308
|
+
}): Promise<RememberResult>;
|
|
1309
|
+
/**
|
|
1310
|
+
* Subscribe to memory change events.
|
|
1311
|
+
*
|
|
1312
|
+
* **SQLite:** delivers events only within this Node.js process.
|
|
1313
|
+
* A second process writing the same `memory.db` will not notify subscribers here.
|
|
1314
|
+
*/
|
|
1315
|
+
subscribe(filter: SubscribeFilter, callback: (event: MemoryChangeEvent) => void): Unsubscribe;
|
|
1316
|
+
private emitChange;
|
|
1317
|
+
/** Internal remember with optional upsert/dedupe. */
|
|
1318
|
+
private rememberOne;
|
|
1319
|
+
private findNearDuplicate;
|
|
1099
1320
|
/**
|
|
1100
1321
|
* Semantic / hybrid search over stored memories.
|
|
1101
1322
|
* Pass `{ explain: true }` for enriched ranking diagnostics.
|
|
@@ -1113,6 +1334,17 @@ declare class Wolbarg<HasLlm extends boolean = false> {
|
|
|
1113
1334
|
/** @internal */
|
|
1114
1335
|
private runCompress;
|
|
1115
1336
|
ingest(options: IngestOptions): Promise<IngestResult>;
|
|
1337
|
+
/**
|
|
1338
|
+
* Link two memories in the optional graph layer.
|
|
1339
|
+
* Throws {@link ProviderNotConfiguredError} when no graph provider is set.
|
|
1340
|
+
*/
|
|
1341
|
+
linkMemories(fromId: string, toId: string, relation: string, metadata?: Record<string, unknown>): Promise<void>;
|
|
1342
|
+
/**
|
|
1343
|
+
* Traverse related memories via the optional graph layer.
|
|
1344
|
+
* Throws {@link ProviderNotConfiguredError} when no graph provider is set.
|
|
1345
|
+
* Results are re-hydrated from SQL storage when available.
|
|
1346
|
+
*/
|
|
1347
|
+
getRelated(memoryId: string, options?: GetRelatedOptions): Promise<MemoryRecord[]>;
|
|
1116
1348
|
forget(options: ForgetOptions): Promise<number>;
|
|
1117
1349
|
history(options: HistoryOptions): Promise<HistoryResult>;
|
|
1118
1350
|
stats(): Promise<StatsResult>;
|
|
@@ -1132,17 +1364,32 @@ declare class Wolbarg<HasLlm extends boolean = false> {
|
|
|
1132
1364
|
flushTelemetry(): Promise<void>;
|
|
1133
1365
|
/** Session id for this SDK instance (telemetry traces). */
|
|
1134
1366
|
get sessionId(): string;
|
|
1367
|
+
/**
|
|
1368
|
+
* Optional process-wide lock for SQLite read-modify-write (dedupe upsert).
|
|
1369
|
+
* Plain inserts must NOT take this lock — the provider coalesces concurrent
|
|
1370
|
+
* insertMemory calls under a single BEGIN IMMEDIATE for multi-writer throughput.
|
|
1371
|
+
*/
|
|
1135
1372
|
private withWriteLock;
|
|
1136
1373
|
close(): Promise<void>;
|
|
1137
1374
|
get isInitialized(): boolean;
|
|
1138
1375
|
private requireReady;
|
|
1139
1376
|
private assertEmbeddingDimensions;
|
|
1140
1377
|
private requireCheckpointProvider;
|
|
1378
|
+
private requireGraph;
|
|
1379
|
+
private assertGraphCheckpointSupported;
|
|
1380
|
+
private graphSnapshotDir;
|
|
1381
|
+
private closeGraphForSnapshot;
|
|
1382
|
+
private snapshotGraphAlongside;
|
|
1383
|
+
private restoreGraphAlongside;
|
|
1384
|
+
private hydrateRelated;
|
|
1141
1385
|
private requireMemoryDbPath;
|
|
1142
1386
|
}
|
|
1143
1387
|
/** Preferred v0.3 entry — re-exported from factories as well. */
|
|
1144
1388
|
declare function wolbarg$1(options: WolbargOptions): Wolbarg;
|
|
1145
1389
|
|
|
1390
|
+
/** Published SDK semver — keep in sync with package.json `version`. */
|
|
1391
|
+
declare const SDK_VERSION = "0.5.0";
|
|
1392
|
+
|
|
1146
1393
|
/**
|
|
1147
1394
|
* Operation-scoped errors with reason + suggestion for developer experience.
|
|
1148
1395
|
*/
|
|
@@ -1190,6 +1437,17 @@ declare class DatabaseError extends WolbargError {
|
|
|
1190
1437
|
operation?: string;
|
|
1191
1438
|
});
|
|
1192
1439
|
}
|
|
1440
|
+
/**
|
|
1441
|
+
* Thrown when SQLite write-lock retries are exhausted.
|
|
1442
|
+
* Stable code: WOLBARG_STORAGE_LOCKED
|
|
1443
|
+
*/
|
|
1444
|
+
declare class StorageLockedError extends WolbargError {
|
|
1445
|
+
constructor(message: string, options?: ErrorOptions & {
|
|
1446
|
+
reason?: string;
|
|
1447
|
+
suggestion?: string;
|
|
1448
|
+
operation?: string;
|
|
1449
|
+
});
|
|
1450
|
+
}
|
|
1193
1451
|
/** Thrown when an embedding request fails. */
|
|
1194
1452
|
declare class EmbeddingError extends WolbargError {
|
|
1195
1453
|
constructor(message: string, options?: ErrorOptions & {
|
|
@@ -1221,6 +1479,14 @@ declare class ProviderNotConfiguredError extends ConfigurationError {
|
|
|
1221
1479
|
readonly provider: string;
|
|
1222
1480
|
constructor(provider: string, method: string, hint: string);
|
|
1223
1481
|
}
|
|
1482
|
+
/**
|
|
1483
|
+
* Thrown when graph checkpoint / rollback / export / import is requested for a
|
|
1484
|
+
* network-backed graph provider (e.g. Neo4j). File-backed SQLite graph supports
|
|
1485
|
+
* snapshots; Neo4j does not in v1 — we refuse rather than silently skip.
|
|
1486
|
+
*/
|
|
1487
|
+
declare class GraphCheckpointNotSupportedError extends WolbargError {
|
|
1488
|
+
constructor(backend: string, operation: string);
|
|
1489
|
+
}
|
|
1224
1490
|
/** Map low-level SQLite / driver errors into actionable operation errors. */
|
|
1225
1491
|
declare function wrapOperationError(operation: string, error: unknown): WolbargError;
|
|
1226
1492
|
|
|
@@ -1236,15 +1502,29 @@ declare function sqliteConfig(connectionString: string): SqliteDatabaseConfig;
|
|
|
1236
1502
|
declare function postgres(options: string | {
|
|
1237
1503
|
connectionString: string;
|
|
1238
1504
|
maxPoolSize?: number;
|
|
1505
|
+
/** Default true. Set false for higher write throughput (async commit). */
|
|
1506
|
+
durableWrites?: boolean;
|
|
1239
1507
|
}): StorageProvider;
|
|
1240
1508
|
/** Create a PostgreSQL storage config object. */
|
|
1241
1509
|
declare function postgresConfig(connectionString: string, options?: {
|
|
1242
1510
|
maxPoolSize?: number;
|
|
1511
|
+
durableWrites?: boolean;
|
|
1243
1512
|
}): PostgresDatabaseConfig;
|
|
1244
1513
|
/** Create a SQLite telemetry provider for an independent event database. */
|
|
1245
1514
|
declare function sqliteTelemetry(url: string): TelemetryProvider;
|
|
1246
1515
|
/** Create a SQLite checkpoint provider. */
|
|
1247
1516
|
declare function sqliteCheckpoint(directory?: string): CheckpointProvider;
|
|
1517
|
+
/** Create an embedded SQLite graph provider (file-backed, local/dev). */
|
|
1518
|
+
declare function sqliteGraph(options: {
|
|
1519
|
+
path: string;
|
|
1520
|
+
}): GraphProvider;
|
|
1521
|
+
/** Create a Neo4j graph provider (networked). Requires optional peer `neo4j-driver`. */
|
|
1522
|
+
declare function neo4jGraph(options: {
|
|
1523
|
+
url: string;
|
|
1524
|
+
username: string;
|
|
1525
|
+
password: string;
|
|
1526
|
+
database?: string;
|
|
1527
|
+
}): GraphProvider;
|
|
1248
1528
|
/** Create a telemetry provider from config (SQLite only in v0.3). */
|
|
1249
1529
|
declare function createTelemetryProvider(config: TelemetryConfig): TelemetryProvider;
|
|
1250
1530
|
/**
|
|
@@ -1252,6 +1532,20 @@ declare function createTelemetryProvider(config: TelemetryConfig): TelemetryProv
|
|
|
1252
1532
|
*/
|
|
1253
1533
|
declare function wolbarg(options: WolbargOptions): Wolbarg;
|
|
1254
1534
|
|
|
1535
|
+
/**
|
|
1536
|
+
* SQLite multi-writer concurrency defaults and validation.
|
|
1537
|
+
*/
|
|
1538
|
+
interface ConcurrencyConfig {
|
|
1539
|
+
/** Max retry attempts after SQLITE_BUSY. Default: 5 */
|
|
1540
|
+
maxRetries?: number;
|
|
1541
|
+
/** Base backoff in ms before jitter. Default: 50 */
|
|
1542
|
+
baseBackoffMs?: number;
|
|
1543
|
+
/** Cap on backoff delay in ms. Default: 2000 */
|
|
1544
|
+
maxBackoffMs?: number;
|
|
1545
|
+
/** SQLite busy_timeout pragma in ms. Default: 5000 */
|
|
1546
|
+
lockTimeoutMs?: number;
|
|
1547
|
+
}
|
|
1548
|
+
|
|
1255
1549
|
/**
|
|
1256
1550
|
* SQLite + sqlite-vec database provider (Node.js built-in `node:sqlite`).
|
|
1257
1551
|
*
|
|
@@ -1266,10 +1560,12 @@ declare function wolbarg(options: WolbargOptions): Wolbarg;
|
|
|
1266
1560
|
|
|
1267
1561
|
interface SqliteProviderOptions {
|
|
1268
1562
|
connectionString: string;
|
|
1563
|
+
concurrency?: ConcurrencyConfig;
|
|
1269
1564
|
}
|
|
1270
1565
|
declare class SqliteStorageProvider implements StorageProvider {
|
|
1271
1566
|
readonly name = "sqlite";
|
|
1272
1567
|
private readonly connectionString;
|
|
1568
|
+
private readonly concurrency;
|
|
1273
1569
|
private db;
|
|
1274
1570
|
private statements;
|
|
1275
1571
|
private vectorDimensions;
|
|
@@ -1280,17 +1576,41 @@ declare class SqliteStorageProvider implements StorageProvider {
|
|
|
1280
1576
|
private memoryIndexDirty;
|
|
1281
1577
|
/** Resolved absolute path (or `:memory:`) — avoid re-resolving on size checks. */
|
|
1282
1578
|
private resolvedPath;
|
|
1579
|
+
private retryLog;
|
|
1580
|
+
/** Cached prepared statements for `rowid IN (…)` lookups keyed by list length. */
|
|
1581
|
+
private rowidInStatements;
|
|
1582
|
+
/** Cached list SQL statements keyed by clause shape. */
|
|
1583
|
+
private listStatements;
|
|
1584
|
+
/** Cached multi-row insert statements keyed by row count. */
|
|
1585
|
+
private batchInsertStatements;
|
|
1586
|
+
/** Cached multi-row history inserts keyed by row count. */
|
|
1587
|
+
private batchHistoryStatements;
|
|
1588
|
+
/** Cached multi-row FTS inserts keyed by row count. */
|
|
1589
|
+
private batchFtsStatements;
|
|
1590
|
+
/** Cached multi-row blob embedding inserts keyed by row count. */
|
|
1591
|
+
private batchBlobEmbStatements;
|
|
1592
|
+
/** Coalesce concurrent insertMemory callers into one IMMEDIATE transaction. */
|
|
1593
|
+
private insertQueue;
|
|
1594
|
+
private insertFlushScheduled;
|
|
1283
1595
|
constructor(options: SqliteProviderOptions);
|
|
1284
1596
|
/** Absolute or relative path / `:memory:` used by this provider. */
|
|
1285
1597
|
get path(): string;
|
|
1598
|
+
/** Expose DB for embedding cache store (same connection). */
|
|
1599
|
+
getDatabase(): DatabaseSync | null;
|
|
1600
|
+
setRetryLogger(fn: ((msg: string) => void) | null): void;
|
|
1286
1601
|
open(): Promise<void>;
|
|
1287
1602
|
close(): Promise<void>;
|
|
1288
1603
|
ensureVectorSchema(dimensions: number): Promise<void>;
|
|
1289
1604
|
getEmbeddingDimensions(): Promise<number | null>;
|
|
1290
1605
|
setEmbeddingDimensions(dimensions: number): Promise<void>;
|
|
1291
1606
|
insertMemory(input: InsertMemoryInput): Promise<MemoryRow>;
|
|
1607
|
+
private scheduleInsertFlush;
|
|
1608
|
+
private flushInsertQueue;
|
|
1609
|
+
/** Single-row insert without coalescing (used by flush of size 1). */
|
|
1610
|
+
private insertMemoryImmediate;
|
|
1292
1611
|
insertMemoriesBatch(inputs: InsertMemoryInput[]): Promise<MemoryRow[]>;
|
|
1293
1612
|
updateMemory(input: UpdateMemoryInput): Promise<MemoryRow | null>;
|
|
1613
|
+
findActiveByContentHash(organization: string, agent: string, contentHash: string): Promise<MemoryRow | null>;
|
|
1294
1614
|
searchByMetadata(filter: RepositoryFilter, limit?: number): Promise<MemoryRow[]>;
|
|
1295
1615
|
/** Keyword search via FTS5 BM25. Returns memory IDs ranked by relevance. */
|
|
1296
1616
|
searchKeyword(query: string, organization: string, topK: number): Promise<Array<{
|
|
@@ -1303,8 +1623,8 @@ declare class SqliteStorageProvider implements StorageProvider {
|
|
|
1303
1623
|
listMemories(filter: RepositoryFilter, limit?: number): Promise<MemoryRow[]>;
|
|
1304
1624
|
searchVectors(embedding: Float32Array, topK: number): Promise<VectorSearchHit[]>;
|
|
1305
1625
|
/**
|
|
1306
|
-
* Org-scoped KNN + memory rows.
|
|
1307
|
-
*
|
|
1626
|
+
* Org-scoped KNN + memory rows with adaptive overfetch.
|
|
1627
|
+
* Global ANN is post-filtered by org/agent/archived; underfill triggers larger k.
|
|
1308
1628
|
*/
|
|
1309
1629
|
searchVectorsWithMemories(embedding: Float32Array, topK: number, organization: string, options?: {
|
|
1310
1630
|
agent?: string;
|
|
@@ -1326,9 +1646,21 @@ declare class SqliteStorageProvider implements StorageProvider {
|
|
|
1326
1646
|
totalAgents: number;
|
|
1327
1647
|
}>;
|
|
1328
1648
|
getDatabaseSizeBytes(): Promise<number>;
|
|
1329
|
-
withTransaction<T>(fn: () => T): T
|
|
1649
|
+
withTransaction<T>(fn: () => T | Promise<T>): Promise<T>;
|
|
1330
1650
|
private tryLoadSqliteVec;
|
|
1651
|
+
private static sqliteVecUnsupported;
|
|
1331
1652
|
private runMigrations;
|
|
1653
|
+
/**
|
|
1654
|
+
* Schema v4: drop unused global created_at index, strip archived vectors
|
|
1655
|
+
* from ANN, add agent-active covering index (via CREATE_INDEXES).
|
|
1656
|
+
*/
|
|
1657
|
+
private migrateToV4;
|
|
1658
|
+
/**
|
|
1659
|
+
* Schema v3: content_hash column, history 'updated' event, embedding_cache.
|
|
1660
|
+
* SQLite cannot ALTER CHECK constraints — rebuild memory_history when needed.
|
|
1661
|
+
*/
|
|
1662
|
+
private migrateToV3;
|
|
1663
|
+
private migrateHistoryAllowUpdated;
|
|
1332
1664
|
/**
|
|
1333
1665
|
* Rebuild FTS from active (non-archived) memories when counts diverge.
|
|
1334
1666
|
* Guarantees keyword/hybrid correctness after crashes or interrupted writes.
|
|
@@ -1336,7 +1668,19 @@ declare class SqliteStorageProvider implements StorageProvider {
|
|
|
1336
1668
|
private ensureFtsConsistency;
|
|
1337
1669
|
private backfillFts;
|
|
1338
1670
|
private prepareStatements;
|
|
1339
|
-
private
|
|
1671
|
+
private listMemoriesIndexed;
|
|
1672
|
+
/**
|
|
1673
|
+
* Metadata-filtered list: push filters to json_extract when possible;
|
|
1674
|
+
* otherwise page with a hard scan cap (never load unbounded orgs into RAM).
|
|
1675
|
+
*/
|
|
1676
|
+
private listMemoriesWithMetadata;
|
|
1677
|
+
private getRowidInStatement;
|
|
1678
|
+
private insertMemoryChunk;
|
|
1679
|
+
private insertEmbeddingsBatch;
|
|
1680
|
+
private insertFtsBatch;
|
|
1681
|
+
private insertHistoryBatch;
|
|
1682
|
+
private deleteEmbeddingsForScope;
|
|
1683
|
+
private deleteFtsForScope;
|
|
1340
1684
|
/** Insert-only FTS row (new memory IDs never collide). */
|
|
1341
1685
|
private insertFtsRow;
|
|
1342
1686
|
private upsertFts;
|
|
@@ -1371,30 +1715,63 @@ declare const SqliteDatabaseProvider: typeof SqliteStorageProvider;
|
|
|
1371
1715
|
* - AsyncLocalStorage for nested transactions
|
|
1372
1716
|
* - Single-statement CTE inserts (no BEGIN/COMMIT for one memory)
|
|
1373
1717
|
* - Named prepared statements (parse/plan once per connection)
|
|
1374
|
-
* - Concurrent insert coalescing into unnest batches
|
|
1375
|
-
* -
|
|
1376
|
-
* - Org
|
|
1377
|
-
* -
|
|
1718
|
+
* - Concurrent insert coalescing into unnest batches
|
|
1719
|
+
* - float4[] vector bind (no text "[f,f,…]" parse tax)
|
|
1720
|
+
* - Org/agent/archived denormalized on embeddings for filtered ANN
|
|
1721
|
+
* - Large bulk inserts via sequential fat unnest (COPY-class amortization)
|
|
1722
|
+
* - JSONB metadata filter pushdown
|
|
1378
1723
|
*/
|
|
1379
1724
|
|
|
1725
|
+
type PgQueryResult = {
|
|
1726
|
+
rows: Record<string, unknown>[];
|
|
1727
|
+
rowCount: number | null;
|
|
1728
|
+
};
|
|
1729
|
+
type PgQueryable = {
|
|
1730
|
+
query: (textOrConfig: string | {
|
|
1731
|
+
name?: string;
|
|
1732
|
+
text: string;
|
|
1733
|
+
values?: unknown[];
|
|
1734
|
+
}, params?: unknown[]) => Promise<PgQueryResult>;
|
|
1735
|
+
};
|
|
1736
|
+
type PgPoolClient = PgQueryable & {
|
|
1737
|
+
release: () => void;
|
|
1738
|
+
query: PgQueryable["query"];
|
|
1739
|
+
};
|
|
1740
|
+
type PgPool = PgQueryable & {
|
|
1741
|
+
end: () => Promise<void>;
|
|
1742
|
+
connect: () => Promise<PgPoolClient>;
|
|
1743
|
+
on?: (event: "connect", listener: (client: PgPoolClient) => void) => void;
|
|
1744
|
+
totalCount?: number;
|
|
1745
|
+
idleCount?: number;
|
|
1746
|
+
waitingCount?: number;
|
|
1747
|
+
};
|
|
1380
1748
|
interface PostgresProviderOptions {
|
|
1381
1749
|
connectionString: string;
|
|
1382
1750
|
maxPoolSize?: number;
|
|
1751
|
+
/**
|
|
1752
|
+
* When false, uses `synchronous_commit=off` on every pool connection.
|
|
1753
|
+
* Much higher write throughput; recent commits can be lost on OS crash.
|
|
1754
|
+
* Default true (full durability).
|
|
1755
|
+
*/
|
|
1756
|
+
durableWrites?: boolean;
|
|
1383
1757
|
}
|
|
1384
1758
|
declare class PostgresStorageProvider implements StorageProvider {
|
|
1385
1759
|
readonly name = "postgres";
|
|
1386
1760
|
private readonly connectionString;
|
|
1387
1761
|
private readonly maxPoolSize;
|
|
1762
|
+
private readonly durableWrites;
|
|
1388
1763
|
private pool;
|
|
1389
1764
|
private vectorDimensions;
|
|
1390
1765
|
private hasPgvector;
|
|
1391
1766
|
private hnswIndexEnsured;
|
|
1392
1767
|
private hnswCreateFailures;
|
|
1768
|
+
/** Dedup concurrent CREATE INDEX so mixed read/write storms don't pile up. */
|
|
1769
|
+
private hnswBuildInFlight;
|
|
1393
1770
|
private hasContentTsv;
|
|
1394
|
-
private iterativeScanEnabled;
|
|
1395
1771
|
/** Coalesce concurrent insertMemory callers into one unnest batch. */
|
|
1396
1772
|
private insertQueue;
|
|
1397
1773
|
private insertFlushScheduled;
|
|
1774
|
+
private insertFlushTimer;
|
|
1398
1775
|
private insertFlushInFlight;
|
|
1399
1776
|
constructor(options: PostgresProviderOptions);
|
|
1400
1777
|
getPoolStats(): {
|
|
@@ -1403,10 +1780,26 @@ declare class PostgresStorageProvider implements StorageProvider {
|
|
|
1403
1780
|
idle: number;
|
|
1404
1781
|
waiting: number;
|
|
1405
1782
|
};
|
|
1783
|
+
/** Dedicated pool accessor for LISTEN/NOTIFY subscribe backend. */
|
|
1784
|
+
getPool(): PgPool | null;
|
|
1406
1785
|
open(): Promise<void>;
|
|
1407
1786
|
close(): Promise<void>;
|
|
1787
|
+
/**
|
|
1788
|
+
* Run a search query. HNSW GUCs are baked into pool startup options —
|
|
1789
|
+
* no per-recall connect()+set_config round-trip.
|
|
1790
|
+
*/
|
|
1791
|
+
private withSearchSession;
|
|
1792
|
+
/**
|
|
1793
|
+
* Drop HNSW so bulk / concurrent inserts avoid graph maintenance.
|
|
1794
|
+
* Next recall rebuilds the index (lazy).
|
|
1795
|
+
*/
|
|
1796
|
+
dropVectorIndex(): Promise<void>;
|
|
1797
|
+
/** Force HNSW build now (e.g. before timed recall benches). */
|
|
1798
|
+
ensureVectorIndex(): Promise<void>;
|
|
1408
1799
|
ensureVectorSchema(dimensions: number): Promise<void>;
|
|
1409
1800
|
private ensureVectorTables;
|
|
1801
|
+
/** Cross-process subscribe: NOTIFY after a committed write. */
|
|
1802
|
+
notifyChange(event: MemoryChangeEvent): Promise<void>;
|
|
1410
1803
|
/**
|
|
1411
1804
|
* Soft reset for a single organization. Drops HNSW only when the embeddings
|
|
1412
1805
|
* table is empty so other corpora on a shared bench DB stay intact.
|
|
@@ -1418,18 +1811,23 @@ declare class PostgresStorageProvider implements StorageProvider {
|
|
|
1418
1811
|
wipeAllData(): Promise<void>;
|
|
1419
1812
|
/** Build HNSW once before the first KNN query (bulk-friendly inserts). */
|
|
1420
1813
|
private ensureHnswIndex;
|
|
1814
|
+
private buildHnswIndex;
|
|
1421
1815
|
getEmbeddingDimensions(): Promise<number | null>;
|
|
1422
1816
|
setEmbeddingDimensions(dimensions: number): Promise<void>;
|
|
1423
1817
|
insertMemory(input: InsertMemoryInput): Promise<MemoryRow>;
|
|
1818
|
+
private clearInsertFlushTimer;
|
|
1819
|
+
/** Flush coalesced inserts after a turn so concurrent remember() can join. */
|
|
1820
|
+
private scheduleInsertFlush;
|
|
1424
1821
|
private flushInsertQueue;
|
|
1425
1822
|
/** Single-row insert without coalescing (used by flush + batch of 1). */
|
|
1426
1823
|
private insertMemoryImmediate;
|
|
1427
1824
|
insertMemoriesBatch(inputs: InsertMemoryInput[]): Promise<MemoryRow[]>;
|
|
1428
1825
|
private insertBatchPgvector;
|
|
1429
|
-
/**
|
|
1826
|
+
/** Parallel unnest when HNSW is absent; sequential when index must stay consistent. */
|
|
1430
1827
|
private insertBatchChunked;
|
|
1431
1828
|
private insertOneBlob;
|
|
1432
1829
|
updateMemory(input: UpdateMemoryInput): Promise<MemoryRow | null>;
|
|
1830
|
+
findActiveByContentHash(organization: string, agent: string, contentHash: string): Promise<MemoryRow | null>;
|
|
1433
1831
|
getMemoryById(id: string, organization: string): Promise<MemoryRow | null>;
|
|
1434
1832
|
getMemoryByRowid(rowid: number, organization: string): Promise<MemoryRow | null>;
|
|
1435
1833
|
getMemoriesByRowids(rowids: number[], organization: string): Promise<Map<number, MemoryRow>>;
|
|
@@ -1463,6 +1861,8 @@ declare class PostgresStorageProvider implements StorageProvider {
|
|
|
1463
1861
|
withTransaction<T>(fn: () => T | Promise<T>): Promise<T>;
|
|
1464
1862
|
private runMigrations;
|
|
1465
1863
|
private tryEnablePgvector;
|
|
1864
|
+
private static pgvectorByConn;
|
|
1865
|
+
private static vectorSchemaReady;
|
|
1466
1866
|
private insertEmbedding;
|
|
1467
1867
|
private deleteEmbedding;
|
|
1468
1868
|
private query;
|
|
@@ -1474,13 +1874,115 @@ declare class PostgresStorageProvider implements StorageProvider {
|
|
|
1474
1874
|
private describe;
|
|
1475
1875
|
}
|
|
1476
1876
|
|
|
1877
|
+
declare function createStorageProvider(config: StorageConfig | DatabaseConfig, options?: {
|
|
1878
|
+
concurrency?: ConcurrencyConfig$1;
|
|
1879
|
+
}): StorageProvider;
|
|
1880
|
+
/** @deprecated Prefer {@link createStorageProvider}. */
|
|
1881
|
+
declare function createDatabaseProvider(config: DatabaseConfig): StorageProvider;
|
|
1882
|
+
|
|
1883
|
+
/**
|
|
1884
|
+
* Embedded SQLite graph provider (file-backed, local/dev).
|
|
1885
|
+
*
|
|
1886
|
+
* Implements the five typed {@link GraphProvider} methods with plain SQL and
|
|
1887
|
+
* recursive CTEs — no Cypher. Schema is created on open (plain CREATE TABLE IF
|
|
1888
|
+
* NOT EXISTS; no graph-engine DDL / schema-creation-on-first-write complexity).
|
|
1889
|
+
*
|
|
1890
|
+
* Uses the same `node:sqlite` + {@link withImmediateTransaction} patterns as
|
|
1891
|
+
* {@link SqliteStorageProvider}. Graph data lives in a separate SQLite file from
|
|
1892
|
+
* the memory store by default.
|
|
1893
|
+
*/
|
|
1894
|
+
|
|
1895
|
+
interface SqliteGraphProviderOptions {
|
|
1896
|
+
/** Path to the graph SQLite file (separate from the memory store by default). */
|
|
1897
|
+
path: string;
|
|
1898
|
+
/** Optional write-concurrency tuning (same shape as memory SQLite). */
|
|
1899
|
+
concurrency?: ConcurrencyConfig;
|
|
1900
|
+
}
|
|
1901
|
+
declare class SqliteGraphProvider implements GraphProvider {
|
|
1902
|
+
readonly name = "sqlite";
|
|
1903
|
+
private readonly dbPath;
|
|
1904
|
+
private readonly concurrency;
|
|
1905
|
+
private db;
|
|
1906
|
+
private opened;
|
|
1907
|
+
constructor(options: SqliteGraphProviderOptions);
|
|
1908
|
+
supportsFileSnapshot(): boolean;
|
|
1909
|
+
getDataPath(): string | null;
|
|
1910
|
+
open(): Promise<void>;
|
|
1911
|
+
close(): Promise<void>;
|
|
1912
|
+
linkMemories(fromId: string, toId: string, relation: string, metadata?: Record<string, unknown>): Promise<void>;
|
|
1913
|
+
unlinkMemories(fromId: string, toId: string, relation?: string): Promise<void>;
|
|
1914
|
+
/**
|
|
1915
|
+
* Bounded recursive CTE over `graph_edges`.
|
|
1916
|
+
*
|
|
1917
|
+
* Default depth: {@link DEFAULT_GET_RELATED_DEPTH} (1). Cap: 16.
|
|
1918
|
+
* Only memory↔memory edges are walked (entity MENTIONS edges are excluded).
|
|
1919
|
+
* Cycle-safe via path membership (`instr`) so A→B→C→A terminates.
|
|
1920
|
+
*
|
|
1921
|
+
* Returns stub {@link MemoryRecord}s (id + empty fields). The facade
|
|
1922
|
+
* re-hydrates full rows via `toMemoryRecord` from storage when possible.
|
|
1923
|
+
*/
|
|
1924
|
+
getRelated(memoryId: string, options?: GetRelatedOptions): Promise<MemoryRecord[]>;
|
|
1925
|
+
upsertEntity(entity: GraphEntityInput): Promise<string>;
|
|
1926
|
+
linkEntityToMemory(entityId: string, memoryId: string, role?: string): Promise<void>;
|
|
1927
|
+
deleteMemory(memoryId: string): Promise<void>;
|
|
1928
|
+
/**
|
|
1929
|
+
* Raw Cypher escape hatch — **not supported** on the SQLite graph provider.
|
|
1930
|
+
* Use the typed methods, or open the underlying SQLite file yourself for raw SQL.
|
|
1931
|
+
*/
|
|
1932
|
+
query(_cypher: string, _params?: Record<string, unknown>): Promise<unknown>;
|
|
1933
|
+
health(): Promise<GraphHealthResult>;
|
|
1934
|
+
private withTx;
|
|
1935
|
+
private requireDb;
|
|
1936
|
+
private findMemoryNodeId;
|
|
1937
|
+
private ensureMemoryNodeSync;
|
|
1938
|
+
}
|
|
1939
|
+
|
|
1477
1940
|
/**
|
|
1478
|
-
*
|
|
1941
|
+
* Neo4j graph provider (networked, production).
|
|
1942
|
+
*
|
|
1943
|
+
* Uses neo4j-driver session.run with parameterized Cypher for typed methods —
|
|
1944
|
+
* NOT GraphProvider.query(). Schema-flexible: nodes/relationships are created
|
|
1945
|
+
* freely without DDL.
|
|
1946
|
+
*
|
|
1947
|
+
* Install as optional peer: `npm install neo4j-driver`.
|
|
1479
1948
|
*/
|
|
1480
1949
|
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1950
|
+
interface Neo4jGraphProviderOptions {
|
|
1951
|
+
url: string;
|
|
1952
|
+
username: string;
|
|
1953
|
+
password: string;
|
|
1954
|
+
database?: string;
|
|
1955
|
+
}
|
|
1956
|
+
declare class Neo4jGraphProvider implements GraphProvider {
|
|
1957
|
+
readonly name = "neo4j";
|
|
1958
|
+
private readonly url;
|
|
1959
|
+
private readonly username;
|
|
1960
|
+
private readonly password;
|
|
1961
|
+
private readonly database;
|
|
1962
|
+
private driver;
|
|
1963
|
+
private opened;
|
|
1964
|
+
constructor(options: Neo4jGraphProviderOptions);
|
|
1965
|
+
supportsFileSnapshot(): boolean;
|
|
1966
|
+
getDataPath(): string | null;
|
|
1967
|
+
open(): Promise<void>;
|
|
1968
|
+
close(): Promise<void>;
|
|
1969
|
+
private requireDriver;
|
|
1970
|
+
private withSession;
|
|
1971
|
+
private run;
|
|
1972
|
+
private ensureMemoryNode;
|
|
1973
|
+
linkMemories(fromId: string, toId: string, relation: string, metadata?: Record<string, unknown>): Promise<void>;
|
|
1974
|
+
unlinkMemories(fromId: string, toId: string, relation?: string): Promise<void>;
|
|
1975
|
+
/**
|
|
1976
|
+
* Native Neo4j variable-length path traversal.
|
|
1977
|
+
* Relationship filter uses RELATED.relation property for parity with Kuzu.
|
|
1978
|
+
*/
|
|
1979
|
+
getRelated(memoryId: string, options?: GetRelatedOptions): Promise<MemoryRecord[]>;
|
|
1980
|
+
upsertEntity(entity: GraphEntityInput): Promise<string>;
|
|
1981
|
+
linkEntityToMemory(entityId: string, memoryId: string, role?: string): Promise<void>;
|
|
1982
|
+
deleteMemory(memoryId: string): Promise<void>;
|
|
1983
|
+
query(cypher: string, params?: Record<string, unknown>): Promise<unknown>;
|
|
1984
|
+
health(): Promise<GraphHealthResult>;
|
|
1985
|
+
}
|
|
1484
1986
|
|
|
1485
1987
|
/**
|
|
1486
1988
|
* Database-agnostic memory persistence contract.
|
|
@@ -1592,6 +2094,22 @@ declare class SqliteCheckpointProvider implements CheckpointProvider {
|
|
|
1592
2094
|
deleteCheckpoint(name: string): Promise<boolean>;
|
|
1593
2095
|
listCheckpoints(): Promise<CheckpointMeta[]>;
|
|
1594
2096
|
getCheckpoint(name: string): Promise<CheckpointMeta | null>;
|
|
2097
|
+
/**
|
|
2098
|
+
* Consistent SQLite file backup (WAL checkpoint + backup API / copy).
|
|
2099
|
+
* Used for memory snapshots and for secondary files such as the graph DB.
|
|
2100
|
+
*/
|
|
2101
|
+
backupSqliteFile(sourcePath: string, destPath: string): Promise<void>;
|
|
2102
|
+
/**
|
|
2103
|
+
* Snapshot a secondary SQLite file (typically the graph DB) next to a named
|
|
2104
|
+
* memory checkpoint as `{name}.graph.db`.
|
|
2105
|
+
*/
|
|
2106
|
+
checkpointGraph(name: string, graphSourcePath: string): Promise<string>;
|
|
2107
|
+
/**
|
|
2108
|
+
* Restore a previously snapshotted graph SQLite file into `targetPath`.
|
|
2109
|
+
*/
|
|
2110
|
+
rollbackGraph(name: string, targetPath: string): Promise<void>;
|
|
2111
|
+
/** Absolute path of the graph snapshot for a named checkpoint, if present. */
|
|
2112
|
+
graphSnapshotPath(name: string): string;
|
|
1595
2113
|
private metaPath;
|
|
1596
2114
|
private snapshotPath;
|
|
1597
2115
|
private requireReady;
|
|
@@ -1690,4 +2208,4 @@ interface BenchmarkReport {
|
|
|
1690
2208
|
declare function runBenchmark(name: string, iterations: number, fn: () => Promise<void> | void): Promise<BenchmarkSample[]>;
|
|
1691
2209
|
declare function summarizeBenchmark(samples: BenchmarkSample[], startedAt: string, finishedAt: string): BenchmarkReport;
|
|
1692
2210
|
|
|
1693
|
-
export { type BenchmarkReport, type BenchmarkSample, type ChatMessage, type CheckpointInfo, type CheckpointMeta, type CheckpointOptions, type CheckpointProvider, type Chunk, type ChunkingOptions, type ChunkingStrategy, type ClearOptions, type CompressOptions, type CompressResult, CompressionError, type CompressionProvider, ConfigurationError, type CreateCheckpointOptions, type DatabaseConfig, DatabaseError, type DatabaseProvider, type DatabaseProviderName, type EmbeddingConfig, EmbeddingError, type EmbeddingProvider, type EventDatabase, type ExportResult, FixedChunkingStrategy, type ForgetByFilterOptions, type ForgetByIdOptions, type ForgetOptions, HeadingChunkingStrategy, type HistoryEvent, type HistoryOptions, type HistoryResult, type HybridConfig, type ImportResult, type IngestOptions, type IngestResult, type InitOptions, InitializationError, type KeywordDocument, type KeywordSearchHit, type KeywordSearchProvider, type LatencyBreakdown, LlmCompressionProvider, type LlmConfig, type LlmProvider, MarkdownChunkingStrategy, type MemoryContent, type MemoryFilter, type MemoryMetadata, MemoryNotFoundError, type MemoryProvider, type MemoryRecord, type MetadataFilter as MetaFilter, type MetadataComparison, type MetadataFilter, type MmrConfig, NoopTelemetryProvider, type OCRProvider, type OcrResult, ParagraphChunkingStrategy, type PersistedRecallExplainPayload, type PostgresDatabaseConfig, PostgresStorageProvider, ProviderNotConfiguredError, type RecallExplainResponse, type RecallExplanationHit, type RecallOptions, type RecallResult, type RememberOptions, type RerankDocument, type RerankHit, type RerankerProvider, type RetrievalConfig, SentenceChunkingStrategy, SqliteCheckpointProvider, type SqliteDatabaseConfig, SqliteDatabaseProvider, SqliteEventDatabase, SqliteStorageProvider, SqliteTelemetryProvider, type StageSpan, type StatsResult, type StorageConfig, type StorageProvider, type StorageProviderName, type TelemetryConfig, TelemetryEmitter, type TelemetryEvent, type TelemetryEventInput, type TelemetryLogLevel, type TelemetryOperation, type TelemetryProvider, type TelemetryQuery, type TelemetryQueryResult, type TelemetryStatus, ValidationError, type VisionProvider, type VisionResult, Wolbarg, WolbargError, WolbargLogger, type WolbargOptions, type WolbargOptionsWithLlm, type WolbargOptionsWithoutLlm, bgeReranker, bm25, cohereReranker, createChunkingStrategy, createCompressionProvider, createDatabaseProvider, createEmbeddingProvider, createLlmProvider, createStorageProvider, createTelemetryProvider, wolbarg as createWolbarg, crossEncoder, geminiEmbedding, geminiVision, jinaReranker, lmStudioEmbedding, meta, ollamaEmbedding, ollamaLlm, openRouterEmbedding, openRouterLlm, openaiCompatibleEmbedding, openaiCompatibleLlm, openaiEmbedding, openaiLlm, openaiReranker, openaiVision, postgres, postgresConfig, runBenchmark, sqlite, sqliteCheckpoint, sqliteConfig, sqliteTelemetry, summarizeBenchmark, tesseract, togetherEmbedding, vllmEmbedding, wolbarg$1 as wolbarg, wrapOperationError };
|
|
2211
|
+
export { type BenchmarkReport, type BenchmarkSample, type ChatMessage, type CheckpointInfo, type CheckpointMeta, type CheckpointOptions, type CheckpointProvider, type Chunk, type ChunkingOptions, type ChunkingStrategy, type ClearOptions, type CompressOptions, type CompressResult, CompressionError, type CompressionProvider, type ConcurrencyConfig$1 as ConcurrencyConfig, ConfigurationError, type CreateCheckpointOptions, type DatabaseConfig, DatabaseError, type DatabaseProvider, type DatabaseProviderName, type EmbeddingCacheConfig, type EmbeddingConfig, EmbeddingError, type EmbeddingProvider, type EventDatabase, type ExportResult, FixedChunkingStrategy, type ForgetByFilterOptions, type ForgetByIdOptions, type ForgetOptions, type GetRelatedOptions, GraphCheckpointNotSupportedError, type GraphConfig, type GraphDirection, type GraphEntityInput, type GraphHealthResult, type GraphInput$1 as GraphInput, type GraphProvider, HeadingChunkingStrategy, type HistoryEvent, type HistoryOptions, type HistoryResult, type HybridConfig, type ImportResult, type IngestOptions, type IngestResult, type InitOptions, InitializationError, type KeywordDocument, type KeywordSearchHit, type KeywordSearchProvider, type LatencyBreakdown, LlmCompressionProvider, type LlmConfig, type LlmProvider, MarkdownChunkingStrategy, type MemoryChangeCallback, type MemoryChangeEvent, type MemoryContent, type MemoryDedupeConfig, type MemoryDedupeStrategy, type MemoryFilter, type MemoryMetadata, MemoryNotFoundError, type MemoryProvider, type MemoryRecord, type MetadataFilter as MetaFilter, type MetadataComparison, type MetadataFilter, type MmrConfig, Neo4jGraphProvider, NoopTelemetryProvider, type OCRProvider, type OcrResult, ParagraphChunkingStrategy, type PersistedRecallExplainPayload, type PostgresDatabaseConfig, PostgresStorageProvider, ProviderNotConfiguredError, type RecallExplainResponse, type RecallExplanationHit, type RecallOptions, type RecallResult, type RememberAction, type RememberOptions, type RememberResult, type RerankDocument, type RerankHit, type RerankerProvider, type RetrievalConfig, SDK_VERSION, SentenceChunkingStrategy, SqliteCheckpointProvider, type SqliteDatabaseConfig, SqliteDatabaseProvider, SqliteEventDatabase, SqliteGraphProvider, SqliteStorageProvider, SqliteTelemetryProvider, type StageSpan, type StatsResult, type StorageConfig, StorageLockedError, type StorageProvider, type StorageProviderName, type SubscribableEvent, type SubscribeFilter, type TelemetryConfig, TelemetryEmitter, type TelemetryEvent, type TelemetryEventInput, type TelemetryLogLevel, type TelemetryOperation, type TelemetryProvider, type TelemetryQuery, type TelemetryQueryResult, type TelemetryStatus, type Unsubscribe, ValidationError, type VisionProvider, type VisionResult, Wolbarg, WolbargError, WolbargLogger, type WolbargOptions, type WolbargOptionsWithLlm, type WolbargOptionsWithoutLlm, bgeReranker, bm25, cohereReranker, createChunkingStrategy, createCompressionProvider, createDatabaseProvider, createEmbeddingProvider, createLlmProvider, createStorageProvider, createTelemetryProvider, wolbarg as createWolbarg, crossEncoder, geminiEmbedding, geminiVision, jinaReranker, lmStudioEmbedding, meta, neo4jGraph, ollamaEmbedding, ollamaLlm, openRouterEmbedding, openRouterLlm, openaiCompatibleEmbedding, openaiCompatibleLlm, openaiEmbedding, openaiLlm, openaiReranker, openaiVision, postgres, postgresConfig, runBenchmark, sqlite, sqliteCheckpoint, sqliteConfig, sqliteGraph, sqliteTelemetry, summarizeBenchmark, tesseract, togetherEmbedding, vllmEmbedding, wolbarg$1 as wolbarg, wrapOperationError };
|