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:
export OPENAI_API_KEY=sk-...basic-node
Minimal Node.js script showing the core add / search flow with OpenAI embeddings and PGlite storage.
pnpm --filter @turbomem/example-basic-node startSource: examples/basic-node/src/index.ts
mastra-agent
Shows how to wrap TurboMemory as a Mastra memory provider via @turbomem/mastra.
pnpm --filter @turbomem/example-mastra-agent startSource: 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).
pnpm --filter @turbomem/example-vercel-ai-chatbot devKey files:
app/api/chat/route.ts— streams a response and wires in the memory toolslib/memory.ts— a lazily-initialised sharedTurboMemoryinstanceapp/page.tsx— minimal chat UI usinguseChat
PGlite writes to a local directory. On serverless platforms, point
TURBOMEM_DATA_DIRat 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.
pnpm --filter turbomem build
pnpm --filter @turbomem/example-browser-vite devYou'll need a Google AI API key for Gemini embeddings. The demo stores the key in sessionStorage for convenience only.