SDKs
TypeScript
The Node SDK with native bindings, the hosted client and MemoryTool.
Installation
npm install mentedbOr with yarn/pnpm: yarn add mentedb / pnpm add mentedb. Requires Node.js 18+. The package includes pre-built native bindings (N-API) for the Rust core and ships TypeScript types. Supports Linux, macOS, and Windows.
Quick Start
import { MenteDB } from "mentedb";
const db = new MenteDB("./my-data");
// processTurn is positional and synchronous, no object arg and no await
const result = db.processTurn("I switched from Postgres to SQLite", "Got it!", 0);
// result.context, relevant memories for your prompt (each: { id, content, score })
// result.factsExtracted, what was learned
// result.contradictionCount, conflicts detected
for (const mem of result.context) {
console.log(mem.content);
}
db.close();API Methods
The TypeScript SDK provides a native Node.js interface to MenteDB via N-API bindings. Calls are synchronous and return result objects directly, with camelCase fields.
new MenteDB(dataDir: string)Open or create a database at the given directory path.
Returns: MenteDB instance
processTurn(userMessage: string, assistantResponse?: string, turnId?: number, projectContext?: string, agentId?: string, sessionId?: string)Process a conversation turn through the full cognitive pipeline. Positional and synchronous, returns the result object directly. This is the primary API, one call per turn. Pass agentId to keep each agent's memory isolated and sessionId to record the turn's session in its provenance; leave both unset for a single owner app.
Returns: ProcessTurnResult (context, factsExtracted, contradictionCount, storedIds, predictedTopics)
store(options: StoreOptions)Store a new memory using an options object. StoreOptions: { content: string, memoryType: string, embedding?: number[], agentId?: string, tags?: string[] }. Returns the UUID.
Returns: string (UUID)
recall(query: string)Context-assembled recall using MQL. Returns a RecallResult with text, token count, and memory count.
Returns: RecallResult (text, totalTokens, memoryCount)
search(embedding: number[], k?: number, filter?: { sessionId?: string; source?: string })Search memories by raw vector embedding (cosine similarity), optionally only those written in a session or from a source.
Returns: SearchResult[] (id, score)
relate(source: string, target: string, edgeType: EdgeType = EdgeType.Related, weight: number = 1.0)Create a typed, weighted relationship between two memories.
Returns: void
forget(memoryId: string)Delete a memory by its ID.
Returns: void
getMemory(memoryId: string)One stored memory, including its provenance (sessionId, source, sourceRef, writtenBy, writtenAt, derivedFrom, or null for memories written before provenance existed). Throws when the id is unknown.
Returns: Memory
memoryIdsInSession(sessionId: string)Ids of every memory written in a session, read from the provenance index.
Returns: string[]
erase(memoryId: string, options?: { includeSources?: boolean; verify?: boolean })Verified erase: the memory, everything derived from it, and every copy of their bytes, then a scan for residue.
Returns: ErasureReceipt (ids and hashes, never content)
eraseSession(sessionId: string, options?: { includeSources?: boolean; verify?: boolean })Verified erase of every memory written in a session and everything derived from them, with one receipt.
Returns: SessionErasureReceipt
ingest(conversation: string, provider?: string, agentId?: string)Extract memories from a raw conversation transcript with the LLM pipeline and store them. Needs an LLM configured (MENTEDB_LLM_PROVIDER).
Returns: IngestResult (memoriesStored, rejectedLowQuality, storedIds, ...)
new MemoryTool({ baseUrl?, token?, database?, agentId?, userId? })The backend for Claude's client side memory tool, against your server or MenteDB Cloud, over the global fetch. Pass MemoryTool.TOOL in tools; await results(response.content) for the tool_result blocks. Failures throw MemoryToolError with the HTTP status. See Claude memory tool.
Returns: MemoryTool
close()Close the database and flush pending writes to disk.
Returns: void
new CognitionStream(bufferSize?: number)Monitor an LLM token stream for contradictions, forgotten facts, corrections, and reinforcements. Methods: feedToken(token), drainBuffer().
Returns: CognitionStream
new TrajectoryTracker(maxTurns?: number)Track the reasoning arc of a conversation and predict likely next topics. Methods: recordTurn(topic, decisionState, openQuestions?), getResumeContext(), predictNextTopics().
Returns: TrajectoryTracker
Types
StoreOptions{ content: string, memoryType: string, embedding?: number[], agentId?: string, tags?: string[] }
RecallResult{ text: string, totalTokens: number, memoryCount: number }
SearchResult{ id: string, score: number }