@melandlabs/memory-store 0.3.0 → 1.0.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 +209 -56
- package/dist/{config-2Q092MUz.d.ts → config-CnbqSek5.d.ts} +215 -2
- package/dist/contracts.d.ts +1 -0
- package/dist/contracts.js +2 -0
- package/dist/http.d.ts +21 -5
- package/dist/http.js +1051 -155
- package/dist/index.d.ts +230 -15
- package/dist/index.js +1087 -152
- package/dist/mcp.d.ts +14 -5
- package/dist/mcp.js +1188 -174
- package/dist/policies/memory-graph-correction-policy.d.ts +1 -0
- package/dist/policies/memory-graph-correction-policy.js +4 -0
- package/dist/policies/memory-graph-write-policy.d.ts +1 -0
- package/dist/policies/memory-graph-write-policy.js +2 -0
- package/dist/search/unified-search.d.ts +6 -19
- package/dist/search/unified-search.js +749 -145
- package/dist/server/cli-http.js +1051 -155
- package/dist/server/cli-mcp.js +1185 -171
- package/dist/server/cli-shared.d.ts +5 -2
- package/dist/server/cli-shared.js +6 -4
- package/dist/storage/chroma-memory-index.d.ts +1 -0
- package/dist/storage/chroma-memory-index.js +1 -2
- package/dist/storage/postgres-raw-message-factory.d.ts +4 -1
- package/dist/storage/raw-message-store.d.ts +5 -2
- package/dist/storage/raw-message-store.js +6 -4
- package/dist/storage/sqlite-raw-message-store.d.ts +5 -1
- package/dist/storage/sqlite-raw-message-store.js +6 -4
- package/dist/storage/sqlite-vector-index.d.ts +4 -1
- package/dist/storage/sqlite-vector-index.js +4 -4
- package/dist/unified-search-Bft57TRH.d.ts +122 -0
- package/package.json +11 -7
package/dist/index.d.ts
CHANGED
|
@@ -1,35 +1,250 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
export {
|
|
1
|
+
import * as _melandlabs_memory_consolidation from '@melandlabs/memory-consolidation';
|
|
2
|
+
import { OwnerScope } from '@melandlabs/memory-consolidation';
|
|
3
|
+
import { d as SearchInput, e as SearchOutput, M as MemoryStoreConfig } from './config-CnbqSek5.js';
|
|
4
|
+
export { E as EmbedQueryFn, I as IterativeRecallCandidate, x as IterativeRecallExecutor, y as IterativeRecallPlanner, z as IterativeRecallPlannerOptions, A as IterativeRecallResult, B as IterativeRecallSearchRequest, C as IterativeRecallSearchResult, D as IterativeRecallStats, F as MemoryStoreDb, a as MemoryStoreEnv, Q as QueryRewriter, G as QueryRewriterInput, H as QueryRewriterOptions, c as SearchEvidence, i as SearchSource, S as SearchTier, j as UnifiedMemoryMergeStrategy, k as UnifiedMemoryRankedList, J as UnifiedMemoryReasoningInfo, l as UnifiedMemoryReasoningStrategy, f as UnifiedMemorySearchInput, g as UnifiedMemorySearchOutput, h as UnifiedMemorySearchResult, m as UnifiedMemorySearchSource, b as UnifiedMemorySearchWarning, K as UnifiedSearchInsightsResult, L as UnifiedSearchKnowledgeResult, N as UnifiedSearchReasoningDeps, V as VectorBackend, n as clampUnifiedMemorySearchLimit, o as clampUnifiedMemorySearchThreshold, O as createIdentityIterativePlanner, P as createIdentityRewriter, R as createIterativeRecallPlanner, T as createUserVoiceRewriter, p as isRawMemorySemanticResult, q as mergeUnifiedMemorySearchResults, r as mergeUnifiedMemorySearchResultsRrf, t as normalizeUnifiedMemoryReasoningStrategy, u as normalizeUnifiedMemorySearchSources, v as toKnowledgeResult, w as toMemoryResult } from './config-CnbqSek5.js';
|
|
5
|
+
import { U as UnifiedSearch, A as ApplyConsolidateInput, a as ApplyConsolidateOutput } from './unified-search-Bft57TRH.js';
|
|
6
|
+
export { b as applyReflectedPlan, c as createUnifiedSearch } from './unified-search-Bft57TRH.js';
|
|
7
|
+
import { StoreVsaFactInput, StoreVsaFactOutput, VsaRecallInput, VsaRecallOutput, VsaListInput, VsaFactSummary, VsaForgetInput, VsaForgetOutput, VsaFactStorage } from '@melandlabs/contracts';
|
|
8
|
+
export { StoreVsaFactInput, StoreVsaFactOutput, VsaFact, VsaFactStorage, VsaFactSummary, VsaForgetInput, VsaForgetOutput, VsaListInput, VsaRecallInput, VsaRecallOutput, VsaRecallScore, VsaVocabularyEntry } from '@melandlabs/contracts';
|
|
5
9
|
import { RawMessageStore, getRawMessageManager } from './storage/raw-message-store.js';
|
|
6
10
|
export { RawMessageStorageBackend, RawMessageStorageManagerWithSearch, closeRawMessageStore, createRawMessageStore, getRawMessageStorageBackend, isRawMessageStorageAvailable } from './storage/raw-message-store.js';
|
|
7
11
|
export { PostgresFactoryFn, PostgresRawMessageManagerLike, clearPostgresFactory, hasPostgresFactory, registerPostgresFactory, resolvePostgresFactory } from './storage/postgres-raw-message-factory.js';
|
|
12
|
+
import { RawMessageGraphEvolutionStorage } from '@melandlabs/indexeddb';
|
|
13
|
+
import { Peer } from '@melandlabs/contracts/peer';
|
|
14
|
+
export { SQLiteVsaStore, SQLiteVsaStoreOptions, closeSQLiteVsaStore, getSQLiteVsaStore } from '@melandlabs/sqlite';
|
|
8
15
|
export { RawMessage } from './contracts.js';
|
|
9
|
-
import '@melandlabs/indexeddb/storage';
|
|
10
16
|
import '@melandlabs/ai/memory';
|
|
11
17
|
|
|
12
18
|
/**
|
|
13
|
-
*
|
|
19
|
+
* `@melandlabs/memory-store` — VSA (Vector Symbolic Architecture) facade.
|
|
14
20
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
21
|
+
* Four verbs on top of any `VsaFactStorage` backend:
|
|
22
|
+
*
|
|
23
|
+
* - `storeFact(input)` — persist a (role, filler) binding.
|
|
24
|
+
* - `recall(input)` — rebuild the memory vector from the user's
|
|
25
|
+
* facts, unbind by the requested role, and pick
|
|
26
|
+
* the best vocabulary entry.
|
|
27
|
+
* - `listFacts(input)` — read-side projection of stored facts (no vectors).
|
|
28
|
+
* - `forget(input)` — soft-delete facts by id (idempotent).
|
|
29
|
+
*
|
|
30
|
+
* The facade intentionally does NOT route through `unified-search`. VSA
|
|
31
|
+
* recall semantics differ: a single best-match from a vocabulary, not
|
|
32
|
+
* top-K nearest neighbours. Folding both into one result set would require
|
|
33
|
+
* a confusing union type and a fake "similarity" field that doesn't mean
|
|
34
|
+
* the same thing across sources.
|
|
35
|
+
*
|
|
36
|
+
* Persistence shapes live in `@melandlabs/contracts/vsa-fact`. The HRR
|
|
37
|
+
* algebra (`bind` / `unbind` / `superpose` / `cleanup` / `cosineSimilarity`)
|
|
38
|
+
* is imported from `@melandlabs/vsa` — a leaf package with no runtime deps.
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
interface VsaRecallFacade {
|
|
42
|
+
storeFact(input: StoreVsaFactInput): Promise<StoreVsaFactOutput>;
|
|
43
|
+
recall(input: VsaRecallInput): Promise<VsaRecallOutput>;
|
|
44
|
+
listFacts(input: VsaListInput): Promise<VsaFactSummary[]>;
|
|
45
|
+
forget(input: VsaForgetInput): Promise<VsaForgetOutput>;
|
|
46
|
+
}
|
|
47
|
+
declare function createVsaRecall(storage: VsaFactStorage): VsaRecallFacade;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* `attachMemoryGraphStore` — opt-in helper for hosts that want to wire
|
|
51
|
+
* a memory graph store onto an existing `MemoryStore` without going
|
|
52
|
+
* through `createMemoryStore({ graphStore })`.
|
|
53
|
+
*
|
|
54
|
+
* Usage:
|
|
55
|
+
* ```ts
|
|
56
|
+
* const store = await createMemoryStore();
|
|
57
|
+
* attachMemoryGraphStore(store, {
|
|
58
|
+
* storage: indexedDbStorage,
|
|
59
|
+
* ownerScope: { userId: "u-42" },
|
|
60
|
+
* });
|
|
61
|
+
* ```
|
|
62
|
+
*
|
|
63
|
+
* Returns the same `MemoryStore` reference for chaining. When
|
|
64
|
+
* `storage.compareAndSwapGraphLedger` is missing, no graph store is
|
|
65
|
+
* attached and a warning is emitted via the supplied logger — callers
|
|
66
|
+
* may still run `consolidate`, but it will skip `persistPlan` and
|
|
67
|
+
* emit a `reflect_apply_graph_store_not_configured` warning. The
|
|
68
|
+
* deprecation path through `storage.deprecateRecords` continues to
|
|
69
|
+
* work as long as a `MemoryStorageAdapter` is wired elsewhere.
|
|
19
70
|
*/
|
|
20
71
|
|
|
72
|
+
interface AttachMemoryGraphStoreInput {
|
|
73
|
+
storage: RawMessageGraphEvolutionStorage;
|
|
74
|
+
ownerScope: OwnerScope;
|
|
75
|
+
botId?: string;
|
|
76
|
+
now?: () => number;
|
|
77
|
+
/**
|
|
78
|
+
* Optional logger; falls back to `console`. The helper does not log on
|
|
79
|
+
* the happy path; it only warns when `compareAndSwapGraphLedger` is
|
|
80
|
+
* missing on the storage.
|
|
81
|
+
*/
|
|
82
|
+
logger?: Pick<Console, "warn">;
|
|
83
|
+
}
|
|
84
|
+
declare function attachMemoryGraphStore(store: MemoryStore, input: AttachMemoryGraphStoreInput): MemoryStore;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Peer-centric profile + relationship facade.
|
|
88
|
+
*
|
|
89
|
+
* A higher-level pattern over `UnifiedSearch` that turns the underlying
|
|
90
|
+
* `search()` primitives into two question-shaped entry points a chat
|
|
91
|
+
* assistant can answer on demand:
|
|
92
|
+
*
|
|
93
|
+
* - `getProfile(peer)` — synthesises a peer profile from the
|
|
94
|
+
* raw message tier (and any other tier the host enables).
|
|
95
|
+
* - `getRelationships(peer)` — discovers other peers co-mentioned
|
|
96
|
+
* with the target, confirms each via a pair-scoped
|
|
97
|
+
* `search()` call, and ranks by co-mention count.
|
|
98
|
+
*
|
|
99
|
+
* The facade is purely additive: it composes existing primitives and
|
|
100
|
+
* never modifies `UnifiedSearch`. It assumes the host has already
|
|
101
|
+
* wired `UnifiedSearchDeps` (raw messages, summaries, insights,
|
|
102
|
+
* knowledge, peer-scope check, optional reranker, optional LLM).
|
|
103
|
+
*
|
|
104
|
+
* Host responsibilities:
|
|
105
|
+
* - provide a `listKnownPeers()` callback so the facade can resolve
|
|
106
|
+
* peer IDs to `Peer` records;
|
|
107
|
+
* - optionally provide a `listPeerMentions()` callback so the
|
|
108
|
+
* facade can enumerate co-mention candidates without scanning
|
|
109
|
+
* every message.
|
|
110
|
+
*/
|
|
111
|
+
|
|
112
|
+
interface PeerPosting {
|
|
113
|
+
/** Stable identifier of the source posting (message ID, episode ID, ...). */
|
|
114
|
+
id: string;
|
|
115
|
+
/** ID of the peer who authored the posting. */
|
|
116
|
+
authorId: string;
|
|
117
|
+
/** IDs of peers mentioned in this posting (excludes the author). */
|
|
118
|
+
mentionedIds?: ReadonlyArray<string>;
|
|
119
|
+
/**
|
|
120
|
+
* Structured mentions (preferred over `mentionedIds`). Letting hosts pass
|
|
121
|
+
* full `Peer` records preserves `kind` (user vs agent) instead of
|
|
122
|
+
* collapsing every mention to a bare id that the resolver must guess at.
|
|
123
|
+
* Falls back to `mentionedIds` when omitted.
|
|
124
|
+
*/
|
|
125
|
+
mentionedPeers?: ReadonlyArray<Peer>;
|
|
126
|
+
}
|
|
127
|
+
interface PeerProfileDeps {
|
|
128
|
+
/** Underlying unified-search facade (provides `search`; legacy `searchUnifiedMemory` is a deprecated alias). */
|
|
129
|
+
search: UnifiedSearch;
|
|
130
|
+
/** Workspace / tenant namespace used for all underlying searches. */
|
|
131
|
+
userId: string;
|
|
132
|
+
/**
|
|
133
|
+
* Resolve a peer ID to the canonical `Peer` record. The facade
|
|
134
|
+
* uses this to convert string IDs from `PeerPosting` into the
|
|
135
|
+
* `Peer` instances passed to `peerFilter`. May be omitted if the
|
|
136
|
+
* host already returns `Peer` from `listKnownPeers` and prefers
|
|
137
|
+
* the facade to derive IDs from `peer.id`.
|
|
138
|
+
*/
|
|
139
|
+
resolvePeer?: (peerId: string) => Peer | undefined;
|
|
140
|
+
/**
|
|
141
|
+
* All known peers the facade can answer queries about. Required.
|
|
142
|
+
*/
|
|
143
|
+
listKnownPeers: () => ReadonlyArray<Peer>;
|
|
144
|
+
/**
|
|
145
|
+
* Enumerate every peer→peer co-mention edge observed in the
|
|
146
|
+
* corpus. The facade uses these to discover relationship
|
|
147
|
+
* candidates before confirming each one via
|
|
148
|
+
* `search()`. May return an async iterable for
|
|
149
|
+
* large corpora.
|
|
150
|
+
*/
|
|
151
|
+
listPeerMentions?: () => Promise<ReadonlyArray<PeerPosting>> | ReadonlyArray<PeerPosting>;
|
|
152
|
+
/**
|
|
153
|
+
* Minimum similarity for the profile synthesis search. Defaults to
|
|
154
|
+
* `DEFAULT_PROFILE_THRESHOLD`. `0` widens recall (noisy); raise it to
|
|
155
|
+
* drop weakly-matching raw messages from the LLM context.
|
|
156
|
+
*/
|
|
157
|
+
profileThreshold?: number;
|
|
158
|
+
/**
|
|
159
|
+
* Minimum similarity for the relationship confirmation search. Defaults
|
|
160
|
+
* to `DEFAULT_RELATIONSHIP_THRESHOLD`.
|
|
161
|
+
*/
|
|
162
|
+
relationshipThreshold?: number;
|
|
163
|
+
}
|
|
164
|
+
interface PeerProfile {
|
|
165
|
+
peer: Peer;
|
|
166
|
+
/** LLM-synthesised answer (empty string when no LLM is configured or synthesis fails). */
|
|
167
|
+
answer: string;
|
|
168
|
+
/** Stable IDs of the evidence items the LLM saw. */
|
|
169
|
+
evidenceIds: string[];
|
|
170
|
+
/** Warning codes from the reflect pipeline (e.g. `reflect_llm_failed`). */
|
|
171
|
+
warnings: string[];
|
|
172
|
+
}
|
|
173
|
+
interface PeerRelationship {
|
|
174
|
+
from: Peer;
|
|
175
|
+
to: Peer;
|
|
176
|
+
summary: string;
|
|
177
|
+
evidenceIds: string[];
|
|
178
|
+
/** Number of co-mention observations between `from` and `to`. */
|
|
179
|
+
strength: number;
|
|
180
|
+
}
|
|
181
|
+
interface PeerProfileFacade {
|
|
182
|
+
/** Synthesise a profile for `peerId` via `search({ synthesize: true })`. */
|
|
183
|
+
getProfile(peerId: string): Promise<PeerProfile>;
|
|
184
|
+
/** Discover and rank relationships `peerId` has with other peers. */
|
|
185
|
+
getRelationships(peerId: string): Promise<PeerRelationship[]>;
|
|
186
|
+
/** All peers the facade knows about. */
|
|
187
|
+
getKnownPeers(): ReadonlyArray<Peer>;
|
|
188
|
+
}
|
|
189
|
+
declare function createPeerProfile(deps: PeerProfileDeps): PeerProfileFacade;
|
|
190
|
+
|
|
21
191
|
interface MemoryStore {
|
|
22
192
|
/** Underlying raw-message store (sqlite vs postgres). */
|
|
23
193
|
raw: RawMessageStore;
|
|
24
|
-
/**
|
|
25
|
-
|
|
194
|
+
/**
|
|
195
|
+
* Unified read entry point. Cross-source retrieval (memory +
|
|
196
|
+
* insights + knowledge + summaries) with RRF merge, reasoning
|
|
197
|
+
* strategies (`rewrite` / `iterative`), date filtering, and
|
|
198
|
+
* lexical fallback. Set `synthesize: true` to opt into the LLM
|
|
199
|
+
* synthesis path (formerly `reflect()`).
|
|
200
|
+
*
|
|
201
|
+
* Use `store.consolidate()` for the agentic write-back loop.
|
|
202
|
+
*/
|
|
203
|
+
search(input: SearchInput): Promise<SearchOutput>;
|
|
26
204
|
/** Resolve the active raw-message manager. */
|
|
27
205
|
getRawMessageManager: typeof getRawMessageManager;
|
|
28
|
-
/**
|
|
206
|
+
/**
|
|
207
|
+
* @deprecated Use `store.search(input)` instead. Forwarding shim
|
|
208
|
+
* kept for one release window.
|
|
209
|
+
*/
|
|
29
210
|
searchUnifiedMemory: UnifiedSearch["searchUnifiedMemory"];
|
|
30
|
-
/**
|
|
211
|
+
/**
|
|
212
|
+
* @deprecated Use `store.search({ ...input, sources: ["memory"] })`
|
|
213
|
+
* and read `.results` instead.
|
|
214
|
+
*/
|
|
31
215
|
searchRawMemorySemantically: UnifiedSearch["searchRawMemorySemantically"];
|
|
216
|
+
/**
|
|
217
|
+
* Agentic write-back: gathers evidence, vets a consolidation plan
|
|
218
|
+
* with the LLM, persists via the attached graph store +
|
|
219
|
+
* soft-deprecates via the storage adapter. The `graphStore` and
|
|
220
|
+
* `storage` fields are forwarded from this `MemoryStore` instance
|
|
221
|
+
* when the caller omits them on the input.
|
|
222
|
+
*/
|
|
223
|
+
consolidate(input: ApplyConsolidateInput): Promise<ApplyConsolidateOutput>;
|
|
224
|
+
/**
|
|
225
|
+
* Optional write-back graph store. Set via `attachMemoryGraphStore`;
|
|
226
|
+
* consumers can read it for diagnostic / replay tooling. Absent when
|
|
227
|
+
* the host has not wired one in.
|
|
228
|
+
*/
|
|
229
|
+
graphStore?: _melandlabs_memory_consolidation.MemoryGraphStoreWithOperationHistory;
|
|
230
|
+
/**
|
|
231
|
+
* Optional storage adapter carrying `deprecateRecords`. Forwarded into
|
|
232
|
+
* `consolidate` when callers want deprecation writes without
|
|
233
|
+
* attaching a full graph store.
|
|
234
|
+
*/
|
|
235
|
+
storage?: _melandlabs_memory_consolidation.MemoryStorageAdapterLike;
|
|
236
|
+
/**
|
|
237
|
+
* Vector Symbolic Architecture facade. Always available — backed by
|
|
238
|
+
* the same SQLite DB the raw-message manager uses. Routes through its
|
|
239
|
+
* own `vsa_facts` table; never mixed into the unified search.
|
|
240
|
+
*
|
|
241
|
+
* - `vsaStoreFact(input)` — persist a (role, filler) binding.
|
|
242
|
+
* - `vsaRecall(input)` — rebuild memory vector + best-match cleanup.
|
|
243
|
+
* - `vsaListFacts(input)` — read-side projection (no vectors).
|
|
244
|
+
* - `vsaForget(input)` — soft-delete by id.
|
|
245
|
+
*/
|
|
246
|
+
vsa: VsaRecallFacade;
|
|
32
247
|
}
|
|
33
248
|
declare function createMemoryStore(config?: MemoryStoreConfig): Promise<MemoryStore>;
|
|
34
249
|
|
|
35
|
-
export { type MemoryStore, MemoryStoreConfig, UnifiedSearch, createMemoryStore, getRawMessageManager };
|
|
250
|
+
export { ApplyConsolidateInput, ApplyConsolidateOutput, type AttachMemoryGraphStoreInput, type MemoryStore, MemoryStoreConfig, type PeerPosting, type PeerProfile, type PeerProfileDeps, type PeerProfileFacade, type PeerRelationship, SearchInput, SearchOutput, UnifiedSearch, type VsaRecallFacade, attachMemoryGraphStore, createMemoryStore, createPeerProfile, createVsaRecall, getRawMessageManager };
|