TypeScript
The embedded engine, or the same API over HTTP.
The engine and the HTTP client implement the same interface, MemnestApi. Start embedded on SQLite, move to Postgres or a server later, and your application code does not change.
Install
npm install @memnest/core @memnest/store-sqlite # embedded, SQLite npm install @memnest/store-postgres # or Postgres + pgvector npm install @memnest/client # or talk to a running server
Embedded
import { createMemnest, scopeOf } from '@memnest/core'; import { createSqliteStore } from '@memnest/store-sqlite'; const store = createSqliteStore({ filename: 'memnest.db', autoMigrate: true }); const memnest = createMemnest({ store, queue: store.jobQueue() }); // Returns as soon as the text is indexed; extraction runs in a job. await memnest.add({ containerTag: 'user:123', customId: conversationId, // turns sharing this id are extracted as one session content: [{ role: 'user', content: 'I prefer Postgres.' }], }); const { memories, chunks, trace } = await memnest.search( 'which database?', scopeOf('user:123'), { tokenBudget: 400 }, );
Extraction needs a completion model and a worker in the process: pass completion to createMemnest and call memnest.startWorker(), or run memnest worker beside your app. Until then chunks are searchable but no facts are extracted.
Postgres with embeddings
import { createMemnest } from '@memnest/core'; import { ollamaCompletion, ollamaEmbeddings } from '@memnest/providers'; import { createPostgresStore } from '@memnest/store-postgres'; const store = await createPostgresStore({ connectionString: process.env.MEMNEST_DATABASE_URL }); const memnest = createMemnest({ store, queue: store.jobQueue(), completion: ollamaCompletion({ model: 'llama3.1:8b' }), embedder: ollamaEmbeddings({ model: 'nomic-embed-text' }), }); memnest.startWorker();
Run memnest migrate once against the database. Jobs are claimed with SKIP LOCKED, so any number of workers can share it.
Against a server
import { createMemnestClient } from '@memnest/client'; import { scopeOf } from '@memnest/core'; const memnest = createMemnestClient({ baseUrl: 'http://localhost:8787', apiKey: process.env.MEMNEST_KEY }); const { memories } = await memnest.search('which database?', scopeOf('user:123'), { tokenBudget: 400 });
Works in Node, browsers and workers. A key scoped to one container can only ever reach that container.
The API
// Implemented by the embedded engine and by @memnest/client. interface MemnestApi { add(input): Promise<AddResult>; // returns at 'indexed' getDocument(scope, id); deleteDocument(scope, id); // tombstone: text erased, source kept addMemories(input): Promise<Memory[]>; // direct write, provenance still recorded getMemory(scope, id); listMemories(scope, page?, filter?); getLineage(scope, memoryId); forget(scope, memoryId); graph(scope, opts?); searchMemories(query, scope, opts?); // facts only searchDocuments(query, scope, opts?); // source chunks only search(query, scope, opts?); // both, plus the trace profile(scope); rebuildProfile(scope); deleteContainer(scope); // hard delete listExtractionRuns(scope, opts?); close(); }
The embedded engine adds what only the process owning the store can do: startWorker(), processDueJobs() and backfillEmbeddings(scope).
Errors
import { MemnestError } from '@memnest/core'; try { await memnest.forget(scope, id); } catch (error) { if (error instanceof MemnestError && error.code === 'not_found') /* … */; }
Codes: validation, not_found, scope_violation, provenance, configuration, provider, unauthorized.
Testing without a database or a model
@memnest/core/testing ships an in-memory store, a fixed clock, deterministic ids, a hash embedder and a scripted model, so your tests exercise the real engine with no I/O. It is what the live preview on this site runs.
import { createInMemoryStore, fixedClock, hashEmbedder, scriptedModel } from '@memnest/core/testing';