QuickstartNode / TypeScript

Quickstart: Node / TypeScript

@mnemo-ai/client-ts is a typed HTTP client for Node 20+, Bun, Deno, Workers and browsers. It is a client: it needs a running server.

There is no embedded or library mode. The engine packages (core, server, llm-providers) are internal and are not published to npm. To use Mnemosyne from a Node app, run the server and call it over HTTP.

Start a server and mint a key

Follow the Docker quickstart until curl http://localhost:3939/health/ready reports every check as ok, then mint a key and export it:

docker compose exec server node scripts/create-api-key.cjs --label "node"
export MNEMO_KEY=mns_live_...

Install the client

pnpm add @mnemo-ai/client-ts

Create the client

memory.ts
import { MnemosyneClient } from "@mnemo-ai/client-ts";
 
export const memory = new MnemosyneClient({
  url: "http://localhost:3939",
  apiKey: process.env.MNEMO_KEY!,
});

The API key authenticates the caller and decides the workspace, so no workspace id is passed on each call.

Remember and recall

import { memory } from "./memory";
 
await memory.remember({ statement: "Acme prefers communication in Spanish." });
 
const { hits } = await memory.recall({
  query: "what language should we use with Acme?",
  topK: 5,
});
 
for (const hit of hits) {
  console.log(hit.score, hit.content);
}

Each hit carries id, content, score, validFrom and validTo.

Sessions

Start a session, add the turns and collapse it. The server extracts facts, decisions and entities from the conversation.

const session = await memory.createSession({ agentId: "agent_support" });
await memory.appendTurn(session.id, { role: "user", content: "I need to cancel my subscription" });
await memory.appendTurn(session.id, { role: "assistant", content: "Done, it ends on the 30th." });
await memory.collapseSession(session.id, { strategy: "auto" });
 
const { hits } = await memory.recall({ query: "subscription status", topK: 5 });

Collapsing a session needs an LLM on the server. The Docker stack uses the bundled Ollama for it.

Client options

OptionDefaultWhat it does
urlrequiredBase URL of the server
apiKeyrequiredAPI key, sent as a bearer token
timeout30000Request timeout in milliseconds
retry3 attempts, exponential backoff with jitterRetry policy
fetchthe global fetchCustom fetch implementation
userAgentnoneSuffix added to the client’s User-Agent header

A failed request throws MnemosyneAPIError, MnemosyneNetworkError or MnemosyneTimeoutError. All three extend MnemosyneError.

Embeddings are configured on the server

The client does not embed anything and takes no provider key. The server reads its providers from the environment: MNEMO_EMBED_PROVIDER, MNEMO_EMBED_API_KEY and MNEMO_EMBED_MODEL. See Full guide for the full block.