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 startSource: 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 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).
bash
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).