Skip to content

Examples

Runnable examples live in the examples/ directory. Clone the repo and run with pnpm from the monorepo root.

All examples require OPENAI_API_KEY:

bash
export OPENAI_API_KEY=sk-...

basic-node

Minimal Node.js script showing the core add / search flow with OpenAI embeddings and PGlite storage.

bash
pnpm --filter @turbomem/example-basic-node start

Source: examples/basic-node/src/index.ts

mastra-agent

Shows how to wrap TurboMemory as a Mastra memory provider via @turbomem/mastra.

bash
pnpm --filter @turbomem/example-mastra-agent start

Source: examples/mastra-agent/src/index.ts

vercel-ai-chatbot

A Next.js (App Router) chatbot that gives the model long-term memory using @turbomem/vercel-ai tools (rememberFact / recallMemories).

bash
pnpm --filter @turbomem/example-vercel-ai-chatbot dev

Key files:

  • app/api/chat/route.ts — streams a response and wires in the memory tools
  • lib/memory.ts — a lazily-initialised shared TurboMemory instance
  • app/page.tsx — minimal chat UI using useChat

PGlite writes to a local directory. On serverless platforms, point TURBOMEM_DATA_DIR at a writable, persistent volume (or swap in a hosted storage adapter).

browser-vite

A Vite SPA showing turbomem running entirely in the browser with IndexedDB-backed PGlite storage. Add facts, search, and reload — memories persist in IndexedDB.

bash
pnpm --filter turbomem build
pnpm --filter @turbomem/example-browser-vite dev

You'll need a Google AI API key for Gemini embeddings. The demo stores the key in sessionStorage for convenience only.

Source: examples/browser-vite/src/main.ts