cencori 1.4.0 → 1.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.
@@ -54,6 +54,258 @@ interface SearchResult {
54
54
  count: number;
55
55
  latencyMs: number;
56
56
  }
57
+ type MemoryScope = 'session' | 'user';
58
+ interface WriteScopedMemoryOptions {
59
+ userId?: string;
60
+ sessionId?: string;
61
+ scope?: MemoryScope;
62
+ content: string;
63
+ namespace?: string;
64
+ metadata?: Record<string, unknown>;
65
+ importance?: number;
66
+ }
67
+ interface ScopedMemory {
68
+ id: string;
69
+ scope: MemoryScope;
70
+ scopeKey: string;
71
+ namespace?: string | null;
72
+ content: string;
73
+ importance: number;
74
+ createdAt: string;
75
+ }
76
+ interface SearchScopedMemoryOptions {
77
+ userId?: string;
78
+ sessionId?: string;
79
+ scope?: MemoryScope;
80
+ query: string;
81
+ topK?: number;
82
+ threshold?: number;
83
+ namespace?: string;
84
+ /**
85
+ * Temporal recall: search memory as it was valid at this instant (ISO 8601),
86
+ * including facts later superseded. Omit for current state.
87
+ */
88
+ asOf?: string;
89
+ /**
90
+ * Graph-aware recall (default true): when the query names an entity we know,
91
+ * also walk its relations and return facts about the connected entities that
92
+ * similarity alone would miss. Set false for strictly vector search.
93
+ */
94
+ graph?: boolean;
95
+ }
96
+ interface ScopedSearchResult {
97
+ results: Array<{
98
+ id: string;
99
+ content: string;
100
+ /** Cosine similarity, or 0 for a memory reached across the graph. */
101
+ score: number;
102
+ namespace: string | null;
103
+ importance: number;
104
+ createdAt: string | null;
105
+ /** 'vector' (matched), 'graph' (walked to), or 'session'. */
106
+ source?: 'vector' | 'graph' | 'session';
107
+ /** Hops from the query's entity, for graph-reached memories. */
108
+ hops?: number;
109
+ }>;
110
+ count: number;
111
+ latencyMs: number;
112
+ }
113
+ interface ListScopedMemoryOptions {
114
+ userId?: string;
115
+ sessionId?: string;
116
+ scope?: MemoryScope;
117
+ namespace?: string;
118
+ limit?: number;
119
+ cursor?: string;
120
+ }
121
+ interface ScopedMemoryList {
122
+ memories: Array<{
123
+ id: string;
124
+ namespace?: string | null;
125
+ content: string;
126
+ metadata?: Record<string, unknown>;
127
+ importance: number;
128
+ accessCount?: number;
129
+ createdAt: string | null;
130
+ }>;
131
+ count: number;
132
+ nextCursor: string | null;
133
+ }
134
+ interface RecallOptions {
135
+ scope?: MemoryScope;
136
+ sessionId?: string;
137
+ namespace?: string;
138
+ topK?: number;
139
+ threshold?: number;
140
+ /** Temporal recall: memory as it was valid at this instant (ISO 8601). */
141
+ asOf?: string;
142
+ /**
143
+ * Graph-aware recall (default true): also walk the entity graph from the
144
+ * entities the query names, pulling in connected facts.
145
+ */
146
+ graph?: boolean;
147
+ /**
148
+ * 'inject' (default) returns an inject-ready block of full memory contents.
149
+ * 'index' returns a compact table of contents (`- [id] summary`) — fetch a
150
+ * full note with `memory.fetch(id)` when the summary is relevant.
151
+ */
152
+ mode?: 'inject' | 'index';
153
+ }
154
+ interface RememberExchange {
155
+ user?: string;
156
+ assistant?: string;
157
+ }
158
+ interface RememberOptions {
159
+ scope?: MemoryScope;
160
+ sessionId?: string;
161
+ namespace?: string;
162
+ extract?: {
163
+ model?: string;
164
+ prompt?: string;
165
+ minImportance?: number;
166
+ };
167
+ }
168
+ interface RememberResult {
169
+ written: Array<{
170
+ id: string;
171
+ content: string;
172
+ importance: number;
173
+ }>;
174
+ extracted: number;
175
+ count: number;
176
+ scope: MemoryScope;
177
+ }
178
+ interface ForgetSuggestionsOptions {
179
+ userId?: string;
180
+ sessionId?: string;
181
+ scope?: MemoryScope;
182
+ namespace?: string;
183
+ /** Max suggestions (weakest first). Default 20. */
184
+ limit?: number;
185
+ /** Only suggest memories not used in at least this many days. Default 60. */
186
+ minIdleDays?: number;
187
+ }
188
+ interface ForgetSuggestionsResult {
189
+ suggestions: Array<{
190
+ id: string;
191
+ content: string;
192
+ /** Query-independent durability score, 0–1 (lower = safer to forget). */
193
+ strength: number;
194
+ idleDays: number;
195
+ importance: number;
196
+ }>;
197
+ count: number;
198
+ /** How many active memories were evaluated. */
199
+ evaluated: number;
200
+ }
201
+ interface RememberGraphOptions {
202
+ userId?: string;
203
+ sessionId?: string;
204
+ scope?: MemoryScope;
205
+ namespace?: string;
206
+ user?: string;
207
+ assistant?: string;
208
+ }
209
+ interface RememberGraphResult {
210
+ entities: number;
211
+ created: number;
212
+ merged: number;
213
+ relations: number;
214
+ costUsd: number;
215
+ }
216
+ interface GraphQueryOptions {
217
+ userId?: string;
218
+ sessionId?: string;
219
+ scope?: MemoryScope;
220
+ namespace?: string;
221
+ /** Entity name to start the traversal from. */
222
+ entity: string;
223
+ /** How many hops outward (1–4). Default 2. */
224
+ hops?: number;
225
+ }
226
+ interface GraphResult {
227
+ seed: {
228
+ id: string;
229
+ name: string;
230
+ type: string;
231
+ } | null;
232
+ nodes: Array<{
233
+ id: string;
234
+ name: string;
235
+ type: string;
236
+ hops: number;
237
+ path: string[];
238
+ }>;
239
+ edges: Array<{
240
+ source: string;
241
+ relation: string;
242
+ target: string;
243
+ }>;
244
+ message?: string;
245
+ }
246
+ interface ListEntitiesOptions {
247
+ userId?: string;
248
+ sessionId?: string;
249
+ scope?: MemoryScope;
250
+ namespace?: string;
251
+ type?: string;
252
+ limit?: number;
253
+ }
254
+ interface EntitiesResult {
255
+ entities: Array<{
256
+ id: string;
257
+ name: string;
258
+ type: string;
259
+ aliases: string[];
260
+ mentionCount: number;
261
+ createdAt: string;
262
+ }>;
263
+ count: number;
264
+ }
265
+ /** Full memory returned by `memory.fetch(id)` / GET /v1/memory/:id. */
266
+ interface FetchedMemory {
267
+ id: string;
268
+ scope: MemoryScope;
269
+ scopeKey: string;
270
+ namespace: string | null;
271
+ content: string;
272
+ metadata?: Record<string, unknown>;
273
+ importance: number;
274
+ accessCount?: number;
275
+ lastAccessedAt?: string | null;
276
+ expiresAt?: string | null;
277
+ createdAt: string | null;
278
+ updatedAt?: string | null;
279
+ }
280
+ /**
281
+ * Function-tool schema for index-mode agents. Register it in your `tools` so the
282
+ * model can pull a full memory by id (from the recall index) on demand, then
283
+ * resolve the call with `memory.fetch(id)`.
284
+ *
285
+ * @example
286
+ * ```typescript
287
+ * tools: [MEMORY_FETCH_TOOL]
288
+ * // when the model calls memory_fetch({ id }): const m = await cencori.memory.fetch(id);
289
+ * ```
290
+ */
291
+ declare const MEMORY_FETCH_TOOL: {
292
+ readonly type: "function";
293
+ readonly function: {
294
+ readonly name: "memory_fetch";
295
+ readonly description: "Fetch the full content of a stored memory by its id (shown in the memory index). Only call this for memories whose summary is relevant to the current request; do not fetch memories you do not need.";
296
+ readonly parameters: {
297
+ readonly type: "object";
298
+ readonly properties: {
299
+ readonly id: {
300
+ readonly type: "string";
301
+ readonly description: "The memory id from the memory index, e.g. \"mem_abc123\".";
302
+ };
303
+ };
304
+ readonly required: readonly ["id"];
305
+ readonly additionalProperties: false;
306
+ };
307
+ };
308
+ };
57
309
  /**
58
310
  * Memory class for vector storage operations
59
311
  */
@@ -62,6 +314,121 @@ declare class MemoryClient {
62
314
  private baseUrl;
63
315
  constructor(config: CencoriConfig);
64
316
  private request;
317
+ /**
318
+ * Write a scoped memory for an end user (or session).
319
+ *
320
+ * @example
321
+ * ```typescript
322
+ * await cencori.memory.write({
323
+ * userId: session.user.id,
324
+ * content: 'Prefers dark mode. Uses TypeScript primarily.',
325
+ * });
326
+ * ```
327
+ */
328
+ write(options: WriteScopedMemoryOptions): Promise<ScopedMemory>;
329
+ /**
330
+ * Semantic search over an end user's memories.
331
+ *
332
+ * @example
333
+ * ```typescript
334
+ * const memories = await cencori.memory.searchUser({
335
+ * userId: session.user.id,
336
+ * query: 'ui preferences',
337
+ * topK: 3,
338
+ * });
339
+ * ```
340
+ */
341
+ searchUser(options: SearchScopedMemoryOptions): Promise<ScopedSearchResult>;
342
+ /**
343
+ * Forget a memory by id — a hard delete, not an annotation.
344
+ */
345
+ forget(id: string): Promise<{
346
+ deleted: boolean;
347
+ id: string;
348
+ }>;
349
+ /**
350
+ * List an end user's memories (paginated).
351
+ */
352
+ list(options: ListScopedMemoryOptions): Promise<ScopedMemoryList>;
353
+ /**
354
+ * Suggest memories worth forgetting — stale, low-strength, long-idle
355
+ * candidates (never auto-deleted). Review, then `forget(id)` the ones you
356
+ * want gone. The product never silently forgets a user's memories.
357
+ *
358
+ * @example
359
+ * ```typescript
360
+ * const { suggestions } = await cencori.memory.forgetSuggestions({ userId });
361
+ * for (const s of suggestions) await cencori.memory.forget(s.id);
362
+ * ```
363
+ */
364
+ forgetSuggestions(options: ForgetSuggestionsOptions): Promise<ForgetSuggestionsResult>;
365
+ /**
366
+ * Extract entities + relations from an exchange and add them to the user's
367
+ * memory graph (Layer 5). Enables multi-hop recall — "who does Sarah report
368
+ * to, and where do they work?".
369
+ *
370
+ * @example
371
+ * ```typescript
372
+ * await cencori.memory.rememberGraph({ userId, user: message, assistant: reply });
373
+ * ```
374
+ */
375
+ rememberGraph(options: RememberGraphOptions): Promise<RememberGraphResult>;
376
+ /**
377
+ * Traverse the memory graph outward from an entity, returning connected
378
+ * entities and the relations linking them.
379
+ *
380
+ * @example
381
+ * ```typescript
382
+ * const { nodes, edges } = await cencori.memory.graph({ userId, entity: 'Sarah', hops: 2 });
383
+ * ```
384
+ */
385
+ graph(options: GraphQueryOptions): Promise<GraphResult>;
386
+ /**
387
+ * List the entities in a user's memory graph (most-mentioned first).
388
+ */
389
+ entities(options: ListEntitiesOptions): Promise<EntitiesResult>;
390
+ /**
391
+ * Recall — search a user's memories and return an inject-ready system
392
+ * string. The provider-agnostic read path: drop the result into your own
393
+ * OpenAI/Anthropic/etc. call as a system message. Returns '' when there's
394
+ * nothing relevant yet.
395
+ *
396
+ * @example
397
+ * ```typescript
398
+ * const context = await cencori.memory.recall(userId, userMessage);
399
+ * const reply = await openai.chat.completions.create({
400
+ * model: 'gpt-4o',
401
+ * messages: [
402
+ * ...(context ? [{ role: 'system', content: context }] : []),
403
+ * { role: 'user', content: userMessage },
404
+ * ],
405
+ * });
406
+ * ```
407
+ */
408
+ recall(userId: string, query: string, options?: RecallOptions): Promise<string>;
409
+ /**
410
+ * Fetch one scoped memory's full content by id — the "pull the full note"
411
+ * half of index-mode recall. Scoped to your project; a foreign id 404s.
412
+ * (`get` is the legacy namespace store; `fetch` is the /v1 scoped store.)
413
+ *
414
+ * @example
415
+ * ```typescript
416
+ * const memory = await cencori.memory.fetch('mem_abc123');
417
+ * ```
418
+ */
419
+ fetch(id: string): Promise<FetchedMemory>;
420
+ /**
421
+ * Remember — hand us a completed {user, assistant} exchange and we extract
422
+ * the durable facts and persist them (redacted, org-isolated). The
423
+ * provider-agnostic write path: pair it with `recall` around your own
424
+ * model call and you have full memory without routing inference through us.
425
+ *
426
+ * @example
427
+ * ```typescript
428
+ * await cencori.memory.remember(userId, { user: userMessage, assistant: reply });
429
+ * ```
430
+ */
431
+ remember(userId: string, exchange: RememberExchange, options?: RememberOptions): Promise<RememberResult>;
65
432
  /**
66
433
  * Create a new memory namespace
67
434
  */
@@ -123,4 +490,4 @@ declare class MemoryClient {
123
490
  }
124
491
  declare function createMemoryClient(config: CencoriConfig): MemoryClient;
125
492
 
126
- export { type CreateNamespaceOptions, type Memory, MemoryClient, type MemoryNamespace, type SearchMemoryOptions, type SearchResult, type StoreMemoryOptions, createMemoryClient };
493
+ export { type CreateNamespaceOptions, type EntitiesResult, type FetchedMemory, type ForgetSuggestionsOptions, type ForgetSuggestionsResult, type GraphQueryOptions, type GraphResult, type ListEntitiesOptions, type ListScopedMemoryOptions, MEMORY_FETCH_TOOL, type Memory, MemoryClient, type MemoryNamespace, type MemoryScope, type RecallOptions, type RememberExchange, type RememberGraphOptions, type RememberGraphResult, type RememberOptions, type RememberResult, type ScopedMemory, type ScopedMemoryList, type ScopedSearchResult, type SearchMemoryOptions, type SearchResult, type SearchScopedMemoryOptions, type StoreMemoryOptions, type WriteScopedMemoryOptions, createMemoryClient };