mnemocyte 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 +292 -27
- package/dist/embedders/openai.d.mts +1 -1
- package/dist/embedders/openai.d.mts.map +1 -1
- package/dist/embedders/openai.mjs +24 -9
- package/dist/embedders/openai.mjs.map +1 -1
- package/dist/{errors-BG3-mNur.mjs → errors-B_7ZdjEO.mjs} +4 -3
- package/dist/errors-B_7ZdjEO.mjs.map +1 -0
- package/dist/index.d.mts +11 -7
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1724 -1092
- package/dist/index.mjs.map +1 -1
- package/dist/{types-DXEGcc47.d.mts → types-DH0inEay.d.mts} +166 -52
- package/dist/types-DH0inEay.d.mts.map +1 -0
- package/migrations/0000_initial.sql.template +2 -1
- package/migrations/0002_add_embedding_model.sql +15 -0
- package/migrations/meta/0002_snapshot.json +315 -0
- package/migrations/meta/_journal.json +7 -0
- package/package.json +4 -3
- package/dist/errors-BG3-mNur.mjs.map +0 -1
- package/dist/types-DXEGcc47.d.mts.map +0 -1
|
@@ -29,6 +29,17 @@ type ImportanceLevel = "low" | "normal" | "high" | "critical";
|
|
|
29
29
|
* @defaultValue `"markdown"`
|
|
30
30
|
*/
|
|
31
31
|
type ContextFormat = "markdown" | "plain" | "xml";
|
|
32
|
+
/**
|
|
33
|
+
* A value that can be persisted losslessly as JSON.
|
|
34
|
+
*
|
|
35
|
+
* Metadata rejects unsupported runtime values such as `undefined`, functions,
|
|
36
|
+
* symbols, bigints, non-finite numbers, class instances, and cyclic objects.
|
|
37
|
+
*/
|
|
38
|
+
type JsonValue = string | number | boolean | null | JsonObject | JsonValue[];
|
|
39
|
+
/** A JSON-compatible object used for persisted memory and audit metadata. */
|
|
40
|
+
interface JsonObject {
|
|
41
|
+
[key: string]: JsonValue;
|
|
42
|
+
}
|
|
32
43
|
/**
|
|
33
44
|
* Identifies which backend a {@link MnemocyteClient} is using.
|
|
34
45
|
*
|
|
@@ -100,17 +111,25 @@ interface ProviderResilienceConfig {
|
|
|
100
111
|
/**
|
|
101
112
|
* Maximum time, in milliseconds, that a single provider attempt may
|
|
102
113
|
* run before a {@link MnemocyteError} with code `"TIMEOUT"` is thrown.
|
|
103
|
-
* Defaults to `0` which disables the
|
|
114
|
+
* Must be a non-negative finite number. Defaults to `0` which disables the
|
|
115
|
+
* timeout.
|
|
104
116
|
*/
|
|
105
117
|
timeoutMs?: number;
|
|
106
118
|
/**
|
|
107
|
-
* Maximum number of retry attempts after the initial call.
|
|
108
|
-
* disables retries (default).
|
|
119
|
+
* Maximum number of retry attempts after the initial call. Must be a
|
|
120
|
+
* non-negative integer. `0` disables retries (default).
|
|
109
121
|
*/
|
|
110
122
|
retries?: number;
|
|
111
|
-
/**
|
|
123
|
+
/**
|
|
124
|
+
* Base backoff delay (ms) used before the first retry. Must be a
|
|
125
|
+
* non-negative finite number. Defaults to `100`.
|
|
126
|
+
*/
|
|
112
127
|
baseDelayMs?: number;
|
|
113
|
-
/**
|
|
128
|
+
/**
|
|
129
|
+
* Maximum backoff delay (ms) used between retries. Must be a non-negative
|
|
130
|
+
* finite number. Values below `baseDelayMs` are normalized up to the base
|
|
131
|
+
* delay. Defaults to `2000`.
|
|
132
|
+
*/
|
|
114
133
|
maxDelayMs?: number;
|
|
115
134
|
/**
|
|
116
135
|
* Optional predicate deciding whether `error` should trigger a retry.
|
|
@@ -129,7 +148,9 @@ interface MnemocyteConfig {
|
|
|
129
148
|
/**
|
|
130
149
|
* Postgres connection string. When set, the client uses the Postgres
|
|
131
150
|
* backend (requires the `pgvector` extension and a rendered migration
|
|
132
|
-
* with `mnemocyte_meta.embedding_dimensions` matching the embedder
|
|
151
|
+
* with `mnemocyte_meta.embedding_dimensions` matching the embedder and
|
|
152
|
+
* `embedding_model` metadata available). Must use the `postgres:` or
|
|
153
|
+
* `postgresql:` protocol.
|
|
133
154
|
* When omitted, an in-memory backend is used.
|
|
134
155
|
*/
|
|
135
156
|
databaseUrl?: string;
|
|
@@ -180,8 +201,9 @@ interface AuditConfig {
|
|
|
180
201
|
* (e.g. OpenAI, Cohere, a local model) in a small interface.
|
|
181
202
|
*
|
|
182
203
|
* Mnemocyte records {@link Embedder.model} and {@link Embedder.dimensions}
|
|
183
|
-
* on every stored memory
|
|
184
|
-
*
|
|
204
|
+
* on every stored memory. The Postgres backend also records both values as
|
|
205
|
+
* installation metadata and rejects embedding-dependent operations when the
|
|
206
|
+
* configured embedder is incompatible.
|
|
185
207
|
*/
|
|
186
208
|
interface Embedder {
|
|
187
209
|
/** Stable identifier for the underlying model (e.g. `"text-embedding-3-small"`). */
|
|
@@ -190,13 +212,15 @@ interface Embedder {
|
|
|
190
212
|
readonly dimensions: number;
|
|
191
213
|
/**
|
|
192
214
|
* Embed one or more texts. Implementations MUST return one vector per
|
|
193
|
-
* input, in the same order, each of length {@link Embedder.dimensions}
|
|
215
|
+
* input, in the same order, each of length {@link Embedder.dimensions} and
|
|
216
|
+
* containing only finite numeric values.
|
|
194
217
|
*
|
|
195
218
|
* The optional `options.signal` is forwarded by Mnemocyte when the
|
|
196
|
-
* caller passes a `signal` on a {@link RememberInput} /
|
|
197
|
-
*
|
|
198
|
-
*
|
|
199
|
-
*
|
|
219
|
+
* caller passes a `signal` on a {@link RememberInput} /
|
|
220
|
+
* {@link RememberManyInput} / {@link RecallInput} /
|
|
221
|
+
* {@link BuildContextInput}, or when Mnemocyte's own provider timeout fires.
|
|
222
|
+
* Implementations that integrate with `fetch` should forward the signal to
|
|
223
|
+
* it so requests can be cancelled promptly.
|
|
200
224
|
*/
|
|
201
225
|
embed(texts: readonly string[], options?: {
|
|
202
226
|
signal?: AbortSignal;
|
|
@@ -223,8 +247,8 @@ interface Memory {
|
|
|
223
247
|
tags: string[];
|
|
224
248
|
/** Optional human-readable source attribution (e.g. `"chat:2024-04-12"`). */
|
|
225
249
|
source: string | null;
|
|
226
|
-
/**
|
|
227
|
-
metadata:
|
|
250
|
+
/** JSON-compatible metadata persisted by value alongside the memory. */
|
|
251
|
+
metadata: JsonObject;
|
|
228
252
|
/** Confidence in `[0, 1]`. Used in retrieval ranking. */
|
|
229
253
|
confidence: number;
|
|
230
254
|
/** {@link Embedder.model} value at write time. */
|
|
@@ -272,21 +296,22 @@ interface RetrievalScores {
|
|
|
272
296
|
}
|
|
273
297
|
/**
|
|
274
298
|
* Optional overrides for the per-component retrieval weights. Missing keys
|
|
275
|
-
* fall back to library defaults. Weights
|
|
276
|
-
*
|
|
299
|
+
* fall back to library defaults. Weights must be finite and non-negative, and
|
|
300
|
+
* their effective total must be greater than zero. They need not sum to 1;
|
|
301
|
+
* the final score is computed as a weighted sum of {@link RetrievalScores}.
|
|
277
302
|
*/
|
|
278
303
|
interface RetrievalScoreWeights {
|
|
279
|
-
/**
|
|
304
|
+
/** Non-negative finite weight applied to {@link RetrievalScores.vector}. */
|
|
280
305
|
vector?: number;
|
|
281
|
-
/**
|
|
306
|
+
/** Non-negative finite weight applied to {@link RetrievalScores.lexical}. */
|
|
282
307
|
lexical?: number;
|
|
283
|
-
/**
|
|
308
|
+
/** Non-negative finite weight applied to {@link RetrievalScores.recency}. */
|
|
284
309
|
recency?: number;
|
|
285
|
-
/**
|
|
310
|
+
/** Non-negative finite weight applied to {@link RetrievalScores.confidence}. */
|
|
286
311
|
confidence?: number;
|
|
287
|
-
/**
|
|
312
|
+
/** Non-negative finite weight applied to {@link RetrievalScores.access}. */
|
|
288
313
|
access?: number;
|
|
289
|
-
/**
|
|
314
|
+
/** Non-negative finite weight applied to {@link RetrievalScores.importance}. */
|
|
290
315
|
importance?: number;
|
|
291
316
|
}
|
|
292
317
|
/**
|
|
@@ -296,13 +321,14 @@ interface RetrievalScoreWeights {
|
|
|
296
321
|
interface RetrievalConfig {
|
|
297
322
|
/** Per-component score weights. See {@link RetrievalScoreWeights}. */
|
|
298
323
|
weights?: RetrievalScoreWeights;
|
|
299
|
-
/**
|
|
324
|
+
/** Positive finite half-life (days) for the time-decay recency component. */
|
|
300
325
|
recencyHalfLifeDays?: number;
|
|
301
|
-
/**
|
|
326
|
+
/** Positive finite access count at which the access score is saturated. */
|
|
302
327
|
accessSaturation?: number;
|
|
303
328
|
/**
|
|
304
329
|
* Multiplier applied to {@link RecallInput.limit} to determine how many
|
|
305
330
|
* candidates are fetched from the underlying store before re-ranking.
|
|
331
|
+
* Must be an integer greater than or equal to 1.
|
|
306
332
|
*/
|
|
307
333
|
candidateMultiplier?: number;
|
|
308
334
|
}
|
|
@@ -363,8 +389,8 @@ interface RememberInput {
|
|
|
363
389
|
tags?: string[];
|
|
364
390
|
/** Optional human-readable source attribution. */
|
|
365
391
|
source?: string;
|
|
366
|
-
/**
|
|
367
|
-
metadata?:
|
|
392
|
+
/** JSON-compatible metadata persisted by value alongside the memory. */
|
|
393
|
+
metadata?: JsonObject;
|
|
368
394
|
/** Confidence in `[0, 1]`. @defaultValue `1` */
|
|
369
395
|
confidence?: number;
|
|
370
396
|
/** Optional expiry; expired memories are filtered out by default. */
|
|
@@ -376,6 +402,18 @@ interface RememberInput {
|
|
|
376
402
|
*/
|
|
377
403
|
signal?: AbortSignal;
|
|
378
404
|
}
|
|
405
|
+
/**
|
|
406
|
+
* Batch-level input for {@link MnemocyteClient.rememberMany}.
|
|
407
|
+
*
|
|
408
|
+
* Cancellation belongs to the whole batch. Individual items accept every
|
|
409
|
+
* {@link RememberInput} field except `signal`.
|
|
410
|
+
*/
|
|
411
|
+
interface RememberManyInput {
|
|
412
|
+
/** Memories to persist in order. */
|
|
413
|
+
inputs: readonly Omit<RememberInput, "signal">[];
|
|
414
|
+
/** Optional cancellation signal for the entire batch. */
|
|
415
|
+
signal?: AbortSignal;
|
|
416
|
+
}
|
|
379
417
|
/**
|
|
380
418
|
* Input for {@link MnemocyteClient.recall}.
|
|
381
419
|
*/
|
|
@@ -412,8 +450,8 @@ interface RecallInput {
|
|
|
412
450
|
/**
|
|
413
451
|
* Pluggable token counter used by {@link MnemocyteClient.buildContext} to
|
|
414
452
|
* enforce {@link BuildContextInput.maxTokens}. Plug in your model's real
|
|
415
|
-
* tokenizer (e.g. `tiktoken`) for accurate budgeting; a simple
|
|
416
|
-
* heuristic is used when omitted.
|
|
453
|
+
* tokenizer (e.g. `tiktoken`) for accurate budgeting; a simple character-count
|
|
454
|
+
* heuristic (approximately one token per four characters) is used when omitted.
|
|
417
455
|
*/
|
|
418
456
|
interface TokenCounter {
|
|
419
457
|
/** Return the number of tokens in `text`. */
|
|
@@ -430,7 +468,7 @@ interface BuildContextInput {
|
|
|
430
468
|
query: string;
|
|
431
469
|
/** Output format. @defaultValue `"markdown"` */
|
|
432
470
|
format?: ContextFormat;
|
|
433
|
-
/** Optional token budget;
|
|
471
|
+
/** Optional positive-integer token budget; omission uses the default path. */
|
|
434
472
|
maxTokens?: number;
|
|
435
473
|
/** Maximum number of memories to consider. */
|
|
436
474
|
limit?: number;
|
|
@@ -457,7 +495,10 @@ interface BuildContextInput {
|
|
|
457
495
|
* Input for {@link MnemocyteClient.prune}. All fields are optional, but
|
|
458
496
|
* at least one selector must be set; calling `prune({})` is rejected with
|
|
459
497
|
* a `"VALIDATION"` {@link MnemocyteError} so memories cannot be deleted
|
|
460
|
-
* accidentally.
|
|
498
|
+
* accidentally. Runtime values are validated before storage access; malformed
|
|
499
|
+
* dates, enums, arrays, booleans, and signals are rejected. `false` selector
|
|
500
|
+
* flags and empty selector arrays do not count as effective selectors after
|
|
501
|
+
* normalization. Specified filters are combined with AND semantics.
|
|
461
502
|
*/
|
|
462
503
|
interface PruneInput {
|
|
463
504
|
/** Restrict pruning to a single entity. */
|
|
@@ -491,7 +532,11 @@ interface PruneInput {
|
|
|
491
532
|
* @defaultValue `false`
|
|
492
533
|
*/
|
|
493
534
|
dryRun?: boolean;
|
|
494
|
-
/**
|
|
535
|
+
/**
|
|
536
|
+
* Optional cancellation signal. A pre-aborted signal prevents storage work.
|
|
537
|
+
* In-flight Postgres pruning requests server-query cancellation, but a
|
|
538
|
+
* deletion that has already committed cannot be undone.
|
|
539
|
+
*/
|
|
495
540
|
signal?: AbortSignal;
|
|
496
541
|
}
|
|
497
542
|
/**
|
|
@@ -539,7 +584,10 @@ interface FindDuplicatesInput {
|
|
|
539
584
|
includeSuperseded?: boolean;
|
|
540
585
|
/** Include expired memories in the scan. @defaultValue `false` */
|
|
541
586
|
includeExpired?: boolean;
|
|
542
|
-
/**
|
|
587
|
+
/**
|
|
588
|
+
* Optional cancellation signal. In-memory scans check it cooperatively;
|
|
589
|
+
* Postgres requests cancellation of the active duplicate-search query.
|
|
590
|
+
*/
|
|
543
591
|
signal?: AbortSignal;
|
|
544
592
|
}
|
|
545
593
|
/**
|
|
@@ -574,11 +622,22 @@ interface AuditEvent {
|
|
|
574
622
|
* `"entity.cleared"`.
|
|
575
623
|
*/
|
|
576
624
|
description: string;
|
|
577
|
-
/**
|
|
578
|
-
metadata:
|
|
625
|
+
/** JSON-compatible structured details persisted by value with the change. */
|
|
626
|
+
metadata: JsonObject;
|
|
579
627
|
/** When the change was recorded. */
|
|
580
628
|
timestamp: Date;
|
|
581
629
|
}
|
|
630
|
+
/**
|
|
631
|
+
* Stable composite position for deterministic audit-log pagination.
|
|
632
|
+
*
|
|
633
|
+
* @experimental Part of Phase 6 (consolidation tooling). Shape may change.
|
|
634
|
+
*/
|
|
635
|
+
interface AuditLogCursor {
|
|
636
|
+
/** Event timestamp at the page boundary. */
|
|
637
|
+
timestamp: Date;
|
|
638
|
+
/** Event ID used to break timestamp ties. */
|
|
639
|
+
id: string;
|
|
640
|
+
}
|
|
582
641
|
/**
|
|
583
642
|
* Input for {@link MnemocyteClient.listAuditLog}.
|
|
584
643
|
*
|
|
@@ -592,11 +651,32 @@ interface ListAuditLogInput {
|
|
|
592
651
|
* @defaultValue `50`
|
|
593
652
|
*/
|
|
594
653
|
limit?: number;
|
|
595
|
-
/**
|
|
654
|
+
/**
|
|
655
|
+
* Only return entries strictly before this timestamp. This is a filter, not
|
|
656
|
+
* a complete pagination cursor: events sharing the timestamp are excluded.
|
|
657
|
+
*/
|
|
596
658
|
before?: Date;
|
|
597
|
-
/**
|
|
659
|
+
/**
|
|
660
|
+
* Only return entries strictly after this timestamp. This is a filter, not
|
|
661
|
+
* a complete pagination cursor: events sharing the timestamp are excluded.
|
|
662
|
+
*/
|
|
598
663
|
after?: Date;
|
|
599
|
-
/**
|
|
664
|
+
/**
|
|
665
|
+
* Return entries strictly older than this stable `(timestamp, id)` position.
|
|
666
|
+
*
|
|
667
|
+
* @experimental Prefer this over `before` for complete pagination.
|
|
668
|
+
*/
|
|
669
|
+
beforeCursor?: AuditLogCursor;
|
|
670
|
+
/**
|
|
671
|
+
* Return entries strictly newer than this stable `(timestamp, id)` position.
|
|
672
|
+
*
|
|
673
|
+
* @experimental Prefer this over `after` for complete pagination.
|
|
674
|
+
*/
|
|
675
|
+
afterCursor?: AuditLogCursor;
|
|
676
|
+
/**
|
|
677
|
+
* Optional cancellation signal. In-memory scans check it cooperatively;
|
|
678
|
+
* Postgres requests cancellation of the active audit-log query.
|
|
679
|
+
*/
|
|
600
680
|
signal?: AbortSignal;
|
|
601
681
|
}
|
|
602
682
|
/**
|
|
@@ -614,9 +694,10 @@ interface ConsolidateInput {
|
|
|
614
694
|
/** Memory that should win the merge. Must not itself be superseded. */
|
|
615
695
|
survivorId: string;
|
|
616
696
|
/**
|
|
617
|
-
* Memories to mark as superseded by the survivor.
|
|
618
|
-
*
|
|
619
|
-
*
|
|
697
|
+
* Memories to mark as superseded by the survivor. Entries already
|
|
698
|
+
* superseded by this same survivor are skipped for idempotency. If any
|
|
699
|
+
* entry points to a different survivor, the entire call rejects with
|
|
700
|
+
* `"CONFLICT"`. Must not contain {@link ConsolidateInput.survivorId}.
|
|
620
701
|
*/
|
|
621
702
|
supersededIds: readonly string[];
|
|
622
703
|
/**
|
|
@@ -625,7 +706,13 @@ interface ConsolidateInput {
|
|
|
625
706
|
* @defaultValue `true`
|
|
626
707
|
*/
|
|
627
708
|
mergeTags?: boolean;
|
|
628
|
-
/**
|
|
709
|
+
/**
|
|
710
|
+
* Optional cancellation signal. Postgres checks it between transaction
|
|
711
|
+
* steps and immediately before the transaction callback returns. A
|
|
712
|
+
* statement already in flight may finish before the next check rolls the
|
|
713
|
+
* transaction back. An abort after the final check, including while commit
|
|
714
|
+
* is in flight, may still leave the consolidation committed.
|
|
715
|
+
*/
|
|
629
716
|
signal?: AbortSignal;
|
|
630
717
|
}
|
|
631
718
|
/**
|
|
@@ -638,7 +725,7 @@ interface ConsolidateResult {
|
|
|
638
725
|
survivorId: string;
|
|
639
726
|
/**
|
|
640
727
|
* Number of memories actually marked as superseded. Excludes entries
|
|
641
|
-
* that
|
|
728
|
+
* that already pointed to this survivor (idempotent skip).
|
|
642
729
|
*/
|
|
643
730
|
supersededCount: number;
|
|
644
731
|
/** The IDs that were newly superseded during this call. */
|
|
@@ -692,7 +779,14 @@ interface MnemocyteClient {
|
|
|
692
779
|
remember(input: RememberInput): Promise<Memory>;
|
|
693
780
|
/**
|
|
694
781
|
* Persist multiple memories in one round-trip. Returns the stored records
|
|
695
|
-
* in the same order as `inputs
|
|
782
|
+
* in the same order as `input.inputs`; `input.signal` cancels the batch.
|
|
783
|
+
*/
|
|
784
|
+
rememberMany(input: RememberManyInput): Promise<Memory[]>;
|
|
785
|
+
/**
|
|
786
|
+
* Positional compatibility overload retained during pre-v1. The first
|
|
787
|
+
* item's `signal`, when present, acts as the batch signal.
|
|
788
|
+
*
|
|
789
|
+
* @deprecated Use `rememberMany({ inputs, signal })`.
|
|
696
790
|
*/
|
|
697
791
|
rememberMany(inputs: readonly RememberInput[]): Promise<Memory[]>;
|
|
698
792
|
/**
|
|
@@ -710,12 +804,20 @@ interface MnemocyteClient {
|
|
|
710
804
|
*
|
|
711
805
|
* @throws {MnemocyteError} `"NOT_FOUND"` if the memory does not exist
|
|
712
806
|
* or does not belong to `entityId`.
|
|
807
|
+
* @throws {MnemocyteError} `"CONFLICT"` if another memory still
|
|
808
|
+
* references this memory as its consolidation survivor.
|
|
713
809
|
*/
|
|
714
810
|
forget(input: {
|
|
715
811
|
entityId: string;
|
|
716
812
|
memoryId: string;
|
|
717
813
|
}): Promise<void>;
|
|
718
|
-
/**
|
|
814
|
+
/**
|
|
815
|
+
* Delete every memory belonging to `entityId`.
|
|
816
|
+
*
|
|
817
|
+
* @throws {MnemocyteError} `"CONFLICT"` if any selected memory is still
|
|
818
|
+
* referenced as a consolidation survivor, including by another selected
|
|
819
|
+
* memory.
|
|
820
|
+
*/
|
|
719
821
|
forgetAll(input: {
|
|
720
822
|
entityId: string;
|
|
721
823
|
}): Promise<void>;
|
|
@@ -726,6 +828,10 @@ interface MnemocyteClient {
|
|
|
726
828
|
* `"VALIDATION"` {@link MnemocyteError} to avoid accidental full
|
|
727
829
|
* deletion. Pass `dryRun: true` to count without deleting.
|
|
728
830
|
*
|
|
831
|
+
* @throws {MnemocyteError} `"CONFLICT"` when a non-dry-run prune selects
|
|
832
|
+
* a memory that still has consolidation dependents. The prune deletes
|
|
833
|
+
* nothing in that case.
|
|
834
|
+
*
|
|
729
835
|
* @example Evict expired or stale memories for an entity
|
|
730
836
|
* ```ts
|
|
731
837
|
* await client.prune({
|
|
@@ -798,7 +904,10 @@ interface MnemocyteClient {
|
|
|
798
904
|
}): Promise<EntityStats | GlobalStats>;
|
|
799
905
|
/**
|
|
800
906
|
* Release any underlying resources (e.g. the Postgres connection pool).
|
|
801
|
-
*
|
|
907
|
+
* New operations are rejected once closing starts. The returned promise
|
|
908
|
+
* waits for operations that already started, then closes the store. Safe to
|
|
909
|
+
* call multiple times; concurrent calls share the same close operation.
|
|
910
|
+
* If closing the store fails, the client reopens so callers may retry.
|
|
802
911
|
*/
|
|
803
912
|
close(): Promise<void>;
|
|
804
913
|
}
|
|
@@ -812,11 +921,13 @@ interface ExperimentalMnemocyteClient {
|
|
|
812
921
|
/**
|
|
813
922
|
* Consolidate likely-duplicate memories into a single survivor by
|
|
814
923
|
* marking the others as superseded. Optionally unions their tags
|
|
815
|
-
* onto the survivor. Idempotent
|
|
816
|
-
*
|
|
924
|
+
* onto the survivor. Idempotent when every already-superseded loser
|
|
925
|
+
* points to the requested survivor.
|
|
817
926
|
*
|
|
818
927
|
* Emits one `"memory.superseded"` audit event per newly superseded
|
|
819
928
|
* memory when {@link MnemocyteConfig.audit}.`enabled` is `true`.
|
|
929
|
+
* A survivor cannot later be deleted while any superseded memory still
|
|
930
|
+
* references it; deletion attempts fail with `"CONFLICT"`.
|
|
820
931
|
*
|
|
821
932
|
* @experimental Part of Phase 6 (consolidation tooling). API may change.
|
|
822
933
|
*
|
|
@@ -824,8 +935,11 @@ interface ExperimentalMnemocyteClient {
|
|
|
824
935
|
* a `survivorId` that also appears in `supersededIds`, or a survivor
|
|
825
936
|
* that is itself already superseded.
|
|
826
937
|
* @throws {MnemocyteError} `"NOT_FOUND"` if the survivor or any
|
|
827
|
-
*
|
|
828
|
-
*
|
|
938
|
+
* memory in `supersededIds` does not belong to `entityId`.
|
|
939
|
+
* @throws {MnemocyteError} `"CONFLICT"` if any memory in
|
|
940
|
+
* `supersededIds` already points to a different survivor. The whole
|
|
941
|
+
* call is rejected before any loser, survivor tags, or audit events
|
|
942
|
+
* are changed.
|
|
829
943
|
*
|
|
830
944
|
* @example
|
|
831
945
|
* ```ts
|
|
@@ -842,5 +956,5 @@ interface ExperimentalMnemocyteClient {
|
|
|
842
956
|
consolidate(input: ConsolidateInput): Promise<ConsolidateResult>;
|
|
843
957
|
}
|
|
844
958
|
//#endregion
|
|
845
|
-
export {
|
|
846
|
-
//# sourceMappingURL=types-
|
|
959
|
+
export { PruneResult as A, MnemocyteConfig as C, ObservabilityConfig as D, MnemocyteOperation as E, RetrievalExplanation as F, RetrievalScoreWeights as I, RetrievalScores as L, RememberInput as M, RememberManyInput as N, ProviderResilienceConfig as O, RetrievalConfig as P, TokenCounter as R, MnemocyteClient as S, MnemocyteObservationPhase as T, ListAuditLogInput as _, ConsolidateInput as a, MemoryWithScore as b, DuplicatePair as c, ExperimentalMnemocyteClient as d, FindDuplicatesInput as f, JsonValue as g, JsonObject as h, BuildContextInput as i, RecallInput as j, PruneInput as k, Embedder as l, ImportanceLevel as m, AuditEvent as n, ConsolidateResult as o, GlobalStats as p, AuditLogCursor as r, ContextFormat as s, AuditConfig as t, EntityStats as u, Memory as v, MnemocyteObservation as w, MnemocyteBackend as x, MemoryType as y };
|
|
960
|
+
//# sourceMappingURL=types-DH0inEay.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-DH0inEay.d.mts","names":[],"sources":["../src/types.ts"],"mappings":";;AAYA;;;;AAAsB;AActB;;;;AAA2B;AAW3B;KAzBY,UAAA;;;AAyBa;AAQzB;;;KAnBY,eAAA;AAyBA;AAGZ;;;;AACyB;AASzB;;;AAbY,KAdA,aAAA;AA2BgB;AAM5B;;;;AAA8B;AANF,KAnBhB,SAAA,sCAKT,UAAA,GACA,SAAS;;UAGK,UAAA;EAAA,CACf,GAAA,WAAc,SAAS;AAAA;AA2CzB;;;;;;AAAA,KAlCY,gBAAA;;;;;KAMA,kBAAA;;;;;;;KAoBA,yBAAA;;;;;AA0BN;AASN;UA3BiB,oBAAA;;EAEhB,SAAA,EAAW,kBAAA;EA+BX;EA7BA,KAAA,EAAO,yBAAA;EA6BI;EA3BX,OAAA,EAAS,gBAAA;EA2BgD;EAzBzD,SAAA,EAAW,IAAA;EAoCK;EAlChB,UAAA;;EAEA,QAAA;EAuCA;EArCA,QAAA;EA+CA;EA7CA,KAAA;EA4DA;EA1DA,KAAA;AAAA;;AA0D8C;AAM/C;;;;UAvDiB,mBAAA;EA6EA;;;;;EAvEhB,OAAA,IAAW,KAAA,EAAO,oBAAA,YAAgC,OAAO;AAAA;;;;;;;;;UAWzC,wBAAA;EAkEL;;;;AASQ;AAQpB;EA5EC,SAAA;;;AAoFO;AAYR;EA3FC,OAAA;;;;;EAKA,WAAA;EAwGC;;;;;EAlGD,UAAA;EAoGU;AASX;;;;;;;EApGC,WAAA,IAAe,KAAA,WAA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pC,YAAA,CAAa,KAAA,EAAO,iBAAA,GAAoB,OAAA;;;;;;;;;EASxC,MAAA,CAAO,KAAA;IAAS,QAAA;IAAkB,QAAA;EAAA,IAAqB,OAAA;;;;;;;;EAQvD,SAAA,CAAU,KAAA;IAAS,QAAA;EAAA,IAAqB,OAAA;;;;;;;;;;;;;;;;;;;;;;;;;EAyBxC,KAAA,CAAM,KAAA,EAAO,UAAA,GAAa,OAAA,CAAQ,WAAA;;;;;;;;;;;;;;;;;;;;EAoBlC,cAAA,CAAe,KAAA,EAAO,mBAAA,GAAsB,OAAA,CAAQ,aAAA;;;;;;;;;;;;;;;;;;;;;EAqBpD,YAAA,CAAa,KAAA,EAAO,iBAAA,GAAoB,OAAA,CAAQ,UAAA;;;;;;;;EAQhD,YAAA,EAAc,2BAAA;;;;;EAKd,KAAA,CAAM,KAAA;IAAU,QAAA;EAAA,IAAsB,OAAA,CAAQ,WAAA,GAAc,WAAA;;;;;;;;EAQ5D,KAAA,IAAS,OAAA;AAAA;;;;;;;UASO,2BAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAoChB,WAAA,CAAY,KAAA,EAAO,gBAAA,GAAmB,OAAA,CAAQ,iBAAA;AAAA"}
|
|
@@ -8,7 +8,8 @@ CREATE TABLE "mnemocyte_events" (
|
|
|
8
8
|
--> statement-breakpoint
|
|
9
9
|
CREATE TABLE "mnemocyte_meta" (
|
|
10
10
|
"key" text PRIMARY KEY NOT NULL,
|
|
11
|
-
"embedding_dimensions" integer NOT NULL
|
|
11
|
+
"embedding_dimensions" integer NOT NULL,
|
|
12
|
+
"embedding_model" text
|
|
12
13
|
);
|
|
13
14
|
--> statement-breakpoint
|
|
14
15
|
INSERT INTO "mnemocyte_meta" ("key", "embedding_dimensions") VALUES ('installation', {{EMBEDDING_DIMENSIONS}});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
ALTER TABLE "mnemocyte_meta" ADD COLUMN "embedding_model" text;
|
|
2
|
+
--> statement-breakpoint
|
|
3
|
+
UPDATE "mnemocyte_meta"
|
|
4
|
+
SET "embedding_model" = (
|
|
5
|
+
SELECT min("embedding_model")
|
|
6
|
+
FROM "mnemocyte_memories"
|
|
7
|
+
HAVING count(DISTINCT "embedding_model") = 1
|
|
8
|
+
)
|
|
9
|
+
WHERE
|
|
10
|
+
"key" = 'installation'
|
|
11
|
+
AND "embedding_model" IS NULL
|
|
12
|
+
AND (
|
|
13
|
+
SELECT count(DISTINCT "embedding_model")
|
|
14
|
+
FROM "mnemocyte_memories"
|
|
15
|
+
) = 1;
|