mnemocyte 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +97 -7
- package/dist/embedders/openai.d.mts +1 -1
- package/dist/embedders/openai.mjs +1 -1
- package/dist/{errors-B_7ZdjEO.mjs → errors-DIPysVWl.mjs} +1 -1
- package/dist/{errors-B_7ZdjEO.mjs.map → errors-DIPysVWl.mjs.map} +1 -1
- package/dist/index.d.mts +13 -11
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +49 -2106
- package/dist/index.mjs.map +1 -1
- package/dist/postgres-BHQ1pj16.mjs +913 -0
- package/dist/postgres-BHQ1pj16.mjs.map +1 -0
- package/dist/postgres-runtime-DxJxns07.mjs +9 -0
- package/dist/postgres-runtime-DxJxns07.mjs.map +1 -0
- package/dist/store-config-BFFTm1sj.mjs +1255 -0
- package/dist/store-config-BFFTm1sj.mjs.map +1 -0
- package/dist/stores/drizzle.d.mts +18 -0
- package/dist/stores/drizzle.d.mts.map +1 -0
- package/dist/stores/drizzle.mjs +20 -0
- package/dist/stores/drizzle.mjs.map +1 -0
- package/dist/{types-DH0inEay.d.mts → types-XUWYDoXM.d.mts} +35 -13
- package/dist/types-XUWYDoXM.d.mts.map +1 -0
- package/package.json +7 -3
- package/dist/types-DH0inEay.d.mts.map +0 -1
package/README.md
CHANGED
|
@@ -12,6 +12,8 @@ logs, and duplicate-consolidation tools on top of your existing infrastructure.
|
|
|
12
12
|
|
|
13
13
|
- In-memory backend for tests and demos.
|
|
14
14
|
- Postgres + pgvector backend for persistent storage.
|
|
15
|
+
- Caller-owned postgres.js Drizzle instances through
|
|
16
|
+
`mnemocyte/stores/drizzle`.
|
|
15
17
|
- User-supplied `Embedder` interface.
|
|
16
18
|
- Hybrid recall with vector similarity, lexical matching, recency, confidence,
|
|
17
19
|
access count, and importance.
|
|
@@ -65,8 +67,8 @@ const context = await client.buildContext({
|
|
|
65
67
|
await client.close();
|
|
66
68
|
```
|
|
67
69
|
|
|
68
|
-
When `databaseUrl`
|
|
69
|
-
That backend is intended for development, tests, and prototyping. For
|
|
70
|
+
When both `databaseUrl` and `store` are omitted, Mnemocyte uses the in-memory
|
|
71
|
+
backend. That backend is intended for development, tests, and prototyping. For
|
|
70
72
|
persistent or larger workloads, use Postgres.
|
|
71
73
|
|
|
72
74
|
## Embedder
|
|
@@ -123,6 +125,42 @@ const client = createMnemocyte({
|
|
|
123
125
|
});
|
|
124
126
|
```
|
|
125
127
|
|
|
128
|
+
Applications that already own a postgres.js Drizzle instance can pass it
|
|
129
|
+
through the `mnemocyte/stores/drizzle` subpath:
|
|
130
|
+
|
|
131
|
+
```ts
|
|
132
|
+
import { createMnemocyte } from "mnemocyte";
|
|
133
|
+
import { drizzleStore } from "mnemocyte/stores/drizzle";
|
|
134
|
+
import { drizzle } from "drizzle-orm/postgres-js";
|
|
135
|
+
import postgres from "postgres";
|
|
136
|
+
import * as applicationSchema from "./db/schema.js";
|
|
137
|
+
|
|
138
|
+
const sql = postgres(process.env.DATABASE_URL!);
|
|
139
|
+
const db = drizzle(sql, { schema: applicationSchema });
|
|
140
|
+
|
|
141
|
+
const client = createMnemocyte({
|
|
142
|
+
store: drizzleStore(db),
|
|
143
|
+
embedder,
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
try {
|
|
147
|
+
await client.remember({
|
|
148
|
+
entityId: "user_123",
|
|
149
|
+
content: "Uses the application's existing Drizzle connection.",
|
|
150
|
+
});
|
|
151
|
+
} finally {
|
|
152
|
+
await client.close(); // does not close db or sql
|
|
153
|
+
await sql.end(); // the caller retains connection ownership
|
|
154
|
+
}
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
`drizzleStore(db)` v1 accepts only Drizzle instances backed by postgres.js. It
|
|
158
|
+
uses Mnemocyte's fixed tables in the `public` schema; the bundled migrations
|
|
159
|
+
must already have been applied, and the adapter does not create or migrate
|
|
160
|
+
tables. The caller's Drizzle schema map does not need to include Mnemocyte's
|
|
161
|
+
tables. Supplying both `databaseUrl` and `store` is ambiguous and throws
|
|
162
|
+
synchronously with `MnemocyteError` code `"CONFIG"`.
|
|
163
|
+
|
|
126
164
|
`databaseUrl` must use the `postgres:` or `postgresql:` protocol. Other URL
|
|
127
165
|
protocols reject synchronously with `MnemocyteError` code `"CONFIG"`; detailed
|
|
128
166
|
host, database, and credential validation remains the driver's responsibility.
|
|
@@ -429,7 +467,15 @@ requested loser already points to a different survivor, the call rejects with
|
|
|
429
467
|
`"CONFLICT"`. Mixed batches are atomic: no newly eligible loser is changed, no
|
|
430
468
|
tags are merged, and no consolidation audit event is written when any item
|
|
431
469
|
conflicts. Concurrent calls follow the same target-specific rule in both
|
|
432
|
-
backends.
|
|
470
|
+
backends. `supersededIds` must contain distinct IDs; duplicates reject with
|
|
471
|
+
`"VALIDATION"` before either store is accessed.
|
|
472
|
+
|
|
473
|
+
The store re-reads and protects the survivor in the same atomic boundary as
|
|
474
|
+
the loser updates, tag merge, and enabled audit events. If the survivor is
|
|
475
|
+
deleted or becomes superseded after initial validation but before that
|
|
476
|
+
boundary, the call rejects with `"CONFLICT"` without a partial mutation. Tag
|
|
477
|
+
merges start from the survivor's state inside that boundary, so concurrent
|
|
478
|
+
successful consolidations preserve every committed tag.
|
|
433
479
|
|
|
434
480
|
The survivor cannot later be deleted while any such reference remains:
|
|
435
481
|
`forget`, `forgetAll`, and matching non-dry-run `prune` calls reject with
|
|
@@ -521,12 +567,51 @@ must be positive finite numbers, and `candidateMultiplier` must be an integer
|
|
|
521
567
|
of at least 1. Invalid tuning is rejected at client construction with
|
|
522
568
|
`MnemocyteError` code `"CONFIG"`.
|
|
523
569
|
|
|
570
|
+
## Storage Adapter Contract
|
|
571
|
+
|
|
572
|
+
`MemoryStore` is still an internal boundary rather than a public package
|
|
573
|
+
export, but its future-adapter contract is now documented directly in
|
|
574
|
+
[`src/memory/store.ts`](./src/memory/store.ts). The contract is based on
|
|
575
|
+
postconditions, not identical implementation mechanics: every method is
|
|
576
|
+
mandatory, and no capability-flag surface exists or is currently planned.
|
|
577
|
+
|
|
578
|
+
For adapter implementers, the main rules are:
|
|
579
|
+
|
|
580
|
+
- `ensureSchema` is a readiness hook, not permission for hidden schema
|
|
581
|
+
creation. `ensureEmbeddingCompatibility` unconditionally enforces whatever
|
|
582
|
+
compatibility is meaningful to the persistence model; a store without
|
|
583
|
+
persistent installation state may no-op.
|
|
584
|
+
- `insertMemories` takes ownership of prepared rows and returns exactly one
|
|
585
|
+
detached record per prepared ID. Store return order is untrusted; shared
|
|
586
|
+
orchestration rejects missing, duplicate, or unknown IDs and restores input
|
|
587
|
+
order. `getMemoryEmbeddings`, `getMemory`, and `stats` use the exact keyed,
|
|
588
|
+
detached, and count postconditions described in the source comments.
|
|
589
|
+
- `markMemoriesAccessed` requires distinct IDs and returns the committed
|
|
590
|
+
post-update access fields. Duplicate-ID behavior is intentionally not a
|
|
591
|
+
portable contract. Ordinary `addAuditEvents` calls are best-effort, and a
|
|
592
|
+
rejected batch may have partially persisted on some backends.
|
|
593
|
+
- `listAuditLog` uses stable event IDs, comparable timestamps, strict tuple
|
|
594
|
+
filters, and matching newest-first `(timestamp, id)` order. Tuple pagination
|
|
595
|
+
needs no transaction. Cancellation may be cooperative or active depending on
|
|
596
|
+
the implementation.
|
|
597
|
+
- `vectorSearch` may scan or use an approximate, planner-dependent index.
|
|
598
|
+
`lexicalSearch` may legitimately return different candidates and rankings
|
|
599
|
+
across implementations. `findDuplicatePairs` compares qualifying memories
|
|
600
|
+
pairwise and does not imply indexed nearest-neighbor pair generation.
|
|
601
|
+
- `deleteMemory`, `deleteMemoriesForEntity`, and non-dry-run `prune` must
|
|
602
|
+
protect referenced consolidation survivors with one atomic,
|
|
603
|
+
non-interleavable check-and-mutate operation and reject with `"CONFLICT"`
|
|
604
|
+
before any deletion. Other cancellation boundaries remain method- and
|
|
605
|
+
implementation-specific as documented by the public operations.
|
|
606
|
+
- `close` releases or destroys only implementation-owned state and resources.
|
|
607
|
+
A future adapter around a caller-supplied connection must not close that
|
|
608
|
+
connection.
|
|
609
|
+
|
|
524
610
|
## Roadmap
|
|
525
611
|
|
|
526
612
|
Planned larger milestones:
|
|
527
613
|
|
|
528
614
|
- public `MemoryStore` adapter surface
|
|
529
|
-
- `drizzleStore(db)` for caller-owned Drizzle clients
|
|
530
615
|
- `@mnemocyte/mcp`
|
|
531
616
|
|
|
532
617
|
See [ROADMAP.md](./docs/ROADMAP.md).
|
|
@@ -535,11 +620,15 @@ See [ROADMAP.md](./docs/ROADMAP.md).
|
|
|
535
620
|
|
|
536
621
|
Current behavior:
|
|
537
622
|
|
|
538
|
-
- `createMnemocyte()` selects
|
|
539
|
-
Postgres/pgvector backend
|
|
623
|
+
- `createMnemocyte()` selects an explicitly supplied `store`, the URL-owned
|
|
624
|
+
Postgres/pgvector backend, or the in-memory backend; supplying both `store`
|
|
625
|
+
and `databaseUrl` rejects instead of selecting a precedence.
|
|
540
626
|
- Both backends run through an internal `MemoryStore` boundary and shared
|
|
541
627
|
client orchestration; `MemoryStore` is not exported as a public adapter API
|
|
542
628
|
yet.
|
|
629
|
+
- `mnemocyte/stores/drizzle` exposes the first supported public adapter factory
|
|
630
|
+
for a caller-owned postgres.js Drizzle instance without exporting the full
|
|
631
|
+
`MemoryStore` contract.
|
|
543
632
|
- Postgres schema setup is explicit; the client does not create tables or
|
|
544
633
|
indexes for you.
|
|
545
634
|
- `findDuplicates`, audit-log workflows, and `experimental.consolidate` are
|
|
@@ -548,7 +637,8 @@ Current behavior:
|
|
|
548
637
|
Known limitations before v1:
|
|
549
638
|
|
|
550
639
|
- The internal `MemoryStore` boundary is not a public adapter API yet.
|
|
551
|
-
`drizzleStore(db)`
|
|
640
|
+
`drizzleStore(db)` returns an opaque config value and currently supports only
|
|
641
|
+
postgres.js, the `public` schema, and pre-applied Mnemocyte migrations.
|
|
552
642
|
- Configured provider timeouts abort the per-attempt `AbortSignal`; the
|
|
553
643
|
underlying provider request only stops promptly when the embedder honors that
|
|
554
644
|
signal.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors-
|
|
1
|
+
{"version":3,"file":"errors-DIPysVWl.mjs","names":[],"sources":["../src/errors.ts"],"sourcesContent":["/**\n * Stable, machine-readable error code attached to every {@link MnemocyteError}.\n *\n * - `\"CONFIG\"` — invalid client configuration (e.g. missing or malformed embedder).\n * - `\"VALIDATION\"` — invalid argument passed to a client method.\n * - `\"DB\"` — Postgres or driver-level failure.\n * - `\"EMBEDDING\"` — embedder threw or returned an invalid vector.\n * - `\"NOT_FOUND\"` — referenced memory or entity does not exist.\n * - `\"CONFLICT\"` — the requested mutation conflicts with stored relationships.\n * - `\"MIGRATION\"` — schema/migration check failed against the target database.\n * - `\"TIMEOUT\"` — a provider call exceeded its configured timeout.\n * - `\"ABORTED\"` — the operation was cancelled via an `AbortSignal`.\n */\nexport type MnemocyteErrorCode =\n\t| \"CONFIG\"\n\t| \"VALIDATION\"\n\t| \"DB\"\n\t| \"EMBEDDING\"\n\t| \"NOT_FOUND\"\n\t| \"CONFLICT\"\n\t| \"MIGRATION\"\n\t| \"TIMEOUT\"\n\t| \"ABORTED\";\n\n/**\n * Error type thrown by every public Mnemocyte API.\n *\n * Use the {@link MnemocyteError.code} property — not the message — to branch\n * on failure modes, or call {@link isMnemocyteError} as a type guard when\n * working with `unknown` errors.\n *\n * @example\n * ```ts\n * try {\n * await client.recall({ entityId: \"u1\", query: \"hi\" });\n * } catch (err) {\n * if (isMnemocyteError(err) && err.code === \"DB\") {\n * // handle database failure\n * }\n * throw err;\n * }\n * ```\n */\nexport class MnemocyteError extends Error {\n\t/** Stable, machine-readable failure code. See {@link MnemocyteErrorCode}. */\n\treadonly code: MnemocyteErrorCode;\n\t/** Underlying cause, if any (e.g. an original driver or embedder error). */\n\toverride readonly cause?: unknown;\n\n\t/**\n\t * @param message - Human-readable error message.\n\t * @param code - Stable failure code; see {@link MnemocyteErrorCode}.\n\t * @param cause - Optional underlying cause (driver error, network error, etc.).\n\t */\n\tconstructor(message: string, code: MnemocyteErrorCode, cause?: unknown) {\n\t\tsuper(message);\n\t\tthis.name = \"MnemocyteError\";\n\t\tthis.code = code;\n\t\tthis.cause = cause;\n\t}\n}\n\n/**\n * Type guard for {@link MnemocyteError}.\n *\n * This guard uses `instanceof` and recognizes errors created by the same loaded\n * Mnemocyte class. It does not recognize structurally similar errors or errors\n * created by another installed copy of the package.\n *\n * @param error - Value to test (typically a caught `unknown`).\n * @returns `true` if `error` is a {@link MnemocyteError}.\n */\nexport function isMnemocyteError(error: unknown): error is MnemocyteError {\n\treturn error instanceof MnemocyteError;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA2CA,IAAa,iBAAb,cAAoC,MAAM;;CAEzC;;CAEA;;;;;;CAOA,YAAY,SAAiB,MAA0B,OAAiB;EACvE,MAAM,OAAO;EACb,KAAK,OAAO;EACZ,KAAK,OAAO;EACZ,KAAK,QAAQ;CACd;AACD;;;;;;;;;;;AAYA,SAAgB,iBAAiB,OAAyC;CACzE,OAAO,iBAAiB;AACzB"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,24 +1,26 @@
|
|
|
1
|
-
import { A as
|
|
1
|
+
import { A as PruneInput, C as MnemocyteConfig, D as MnemocyteStoreConfig, E as MnemocyteOperation, F as RetrievalConfig, I as RetrievalExplanation, L as RetrievalScoreWeights, M as RecallInput, N as RememberInput, O as ObservabilityConfig, P as RememberManyInput, R as RetrievalScores, S as MnemocyteClient, T as MnemocyteObservationPhase, _ as ListAuditLogInput, a as ConsolidateInput, b as MemoryWithScore, c as DuplicatePair, d as ExperimentalMnemocyteClient, f as FindDuplicatesInput, g as JsonValue, h as JsonObject, i as BuildContextInput, j as PruneResult, k as ProviderResilienceConfig, l as Embedder, m as ImportanceLevel, n as AuditEvent, o as ConsolidateResult, p as GlobalStats, r as AuditLogCursor, s as ContextFormat, t as AuditConfig, u as EntityStats, v as Memory, w as MnemocyteObservation, x as MnemocyteBackend, y as MemoryType, z as TokenCounter } from "./types-XUWYDoXM.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/client.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* Create a Mnemocyte client.
|
|
6
6
|
*
|
|
7
|
-
* When {@link MnemocyteConfig.
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* for tests, demos,
|
|
7
|
+
* When {@link MnemocyteConfig.store} is provided, that adapter is used. When
|
|
8
|
+
* {@link MnemocyteConfig.databaseUrl} is provided, a URL-owned Postgres client
|
|
9
|
+
* is used (requires the `pgvector` extension and the bundled migrations).
|
|
10
|
+
* When neither is supplied, an in-memory client is returned for tests, demos,
|
|
11
|
+
* and short-lived processes.
|
|
11
12
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
13
|
+
* Call {@link MnemocyteClient.close} when finished. URL-created database
|
|
14
|
+
* resources are owned and closed by Mnemocyte; resources behind a supplied
|
|
15
|
+
* store retain the ownership policy documented by that adapter.
|
|
15
16
|
*
|
|
16
17
|
* @param config - Client configuration. {@link MnemocyteConfig.embedder} is required.
|
|
17
18
|
* @returns A {@link MnemocyteClient} instance.
|
|
18
19
|
* @throws {MnemocyteError} With code `"CONFIG"` if `embedder`, retrieval
|
|
19
20
|
* tuning, provider resilience, or the database URL is malformed or does not
|
|
20
|
-
* use the `postgres:` / `postgresql:` protocol, or `
|
|
21
|
-
* `databaseUrl` is explicitly
|
|
21
|
+
* use the `postgres:` / `postgresql:` protocol, or if `databaseUrl` and
|
|
22
|
+
* `store` are both provided; or `"VALIDATION"` if `databaseUrl` is explicitly
|
|
23
|
+
* empty.
|
|
22
24
|
*
|
|
23
25
|
* @example Postgres-backed client
|
|
24
26
|
* ```ts
|
|
@@ -88,5 +90,5 @@ declare class MnemocyteError extends Error {
|
|
|
88
90
|
*/
|
|
89
91
|
declare function isMnemocyteError(error: unknown): error is MnemocyteError;
|
|
90
92
|
//#endregion
|
|
91
|
-
export { type AuditConfig, type AuditEvent, type AuditLogCursor, type BuildContextInput, type ConsolidateInput, type ConsolidateResult, type ContextFormat, type DuplicatePair, type Embedder, type EntityStats, type ExperimentalMnemocyteClient, type FindDuplicatesInput, type GlobalStats, type ImportanceLevel, type JsonObject, type JsonValue, type ListAuditLogInput, type Memory, type MemoryType, type MemoryWithScore, type MnemocyteBackend, type MnemocyteClient, type MnemocyteConfig, MnemocyteError, type MnemocyteErrorCode, type MnemocyteObservation, type MnemocyteObservationPhase, type MnemocyteOperation, type ObservabilityConfig, type ProviderResilienceConfig, type PruneInput, type PruneResult, type RecallInput, type RememberInput, type RememberManyInput, type RetrievalConfig, type RetrievalExplanation, type RetrievalScoreWeights, type RetrievalScores, type TokenCounter, createMnemocyte, isMnemocyteError };
|
|
93
|
+
export { type AuditConfig, type AuditEvent, type AuditLogCursor, type BuildContextInput, type ConsolidateInput, type ConsolidateResult, type ContextFormat, type DuplicatePair, type Embedder, type EntityStats, type ExperimentalMnemocyteClient, type FindDuplicatesInput, type GlobalStats, type ImportanceLevel, type JsonObject, type JsonValue, type ListAuditLogInput, type Memory, type MemoryType, type MemoryWithScore, type MnemocyteBackend, type MnemocyteClient, type MnemocyteConfig, MnemocyteError, type MnemocyteErrorCode, type MnemocyteObservation, type MnemocyteObservationPhase, type MnemocyteOperation, type MnemocyteStoreConfig, type ObservabilityConfig, type ProviderResilienceConfig, type PruneInput, type PruneResult, type RecallInput, type RememberInput, type RememberManyInput, type RetrievalConfig, type RetrievalExplanation, type RetrievalScoreWeights, type RetrievalScores, type TokenCounter, createMnemocyte, isMnemocyteError };
|
|
92
94
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/client.ts","../src/errors.ts"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/client.ts","../src/errors.ts"],"mappings":";;;;;AA2CA;;;;;;;;AAAyE;;;;AC9BzE;;;;AAA8B;AA8B9B;;;;;;;;;;iBDAgB,eAAA,CAAgB,MAAA,EAAQ,eAAA,GAAkB,eAAe;;;;;;AAAzE;;;;;;;;AAAyE;;KC9B7D,kBAAA;;AAAZ;;;;AAA8B;AA8B9B;;;;;;;;;;;;;cAAa,cAAA,SAAuB,KAAA;EAWA;EAAA,SAT1B,IAAA,EAAM,kBAAA;EASwC;EAAA,SAPrC,KAAA;EAOoD;AAkBvE;;;;cAlBa,OAAA,UAAiB,IAAA,EAAM,kBAAA,EAAoB,KAAA;AAAA;;;AAkBiB;;;;;;;;iBAAzD,gBAAA,CAAiB,KAAA,YAAiB,KAAA,IAAS,cAAc"}
|