Skip to content

Getting started

turbomem gives your LLM agents persistent, semantically-searchable memory that runs entirely inside your Node/Bun process. Type-safe, adapter-based, and dependency-light. No separate memory server required.

Deploying to edge?

See the Edge guide for Upstash Vector setup on Cloudflare Workers, Vercel Edge, and other stateless runtimes.

Install

bash
npm install turbomem

The default stack (OpenAI embeddings + PGlite storage) works out of the box. PGlite ships as a dependency, no extra setup.

Environment

Set your OpenAI API key for embeddings and fact extraction:

bash
export OPENAI_API_KEY=sk-...

Basic usage

ts
import { TurboMemory } from "turbomem";

const memory = new TurboMemory({
  embeddings: "openai",
  storage: "pglite",
  extraction: { provider: "openai", model: "gpt-4.1-mini" },
  openai: { apiKey: process.env.OPENAI_API_KEY },
  pglite: { dataDir: ".turbomem" },
});

await memory.init();

await memory.add(
  [
    { role: "user", content: "Hey, I love hiking and I'm training for a half marathon this fall." },
    { role: "assistant", content: "Nice — I'll remember your fitness goals." },
  ],
  { userId: "user_123" },
);

const results = await memory.search("What outdoor activities is the user into?", {
  userId: "user_123",
  limit: 5,
});

for (const { memory: m, score } of results) {
  console.log(`[${score.toFixed(3)}] ${m.content}`);
}

await memory.close();

init() is required before any other method. It runs storage migrations and loads embedding models (for local embeddings). Calling other methods before init() throws NotInitialisedError.

Why embedded memory?

Many agent-memory setups rely on a separate service. A Python server, a hosted platform, or a vector database you operate yourself. For a TypeScript app that often means running another process, managing extra infrastructure, and crossing a network boundary for every memory operation.

turbomem is fully embedded:

turbomem (embedded)Server-based memory
RuntimeTypeScript, in-processSeparate server / hosted API
Deploymentnpm installRun or host a service
Network hopNone (local)HTTP per call
StoragePGlite (WASM Postgres)External vector store
Best forTS apps, edge, embedding into a productMulti-language or managed infra

If you need a cross-language managed platform, a dedicated memory service may fit better. If you're shipping a TypeScript app and want memory as a library, that's turbomem.

Next steps