Quickstart
Advanced: Direct Postgres Runtime
Skip the service only when your app intentionally owns database credentials.
Direct Postgres mode runs the memory engine inside your application process. The recommended default is the containerized service; use this path only when your app intentionally owns database credentials.
Both direct runtimes take a Postgres URL, run MemexAI migrations, and execute memory tools directly against the database.
JavaScript/TypeScript direct runtime
npm install @memexai/core ai @ai-sdk/googleimport { createMemex } from '@memexai/core'
import { generateText, stepCountIs } from 'ai'
import { createGoogleGenerativeAI } from '@ai-sdk/google'
const google = createGoogleGenerativeAI()
const memex = createMemex({
databaseUrl: process.env.DATABASE_URL!,
model: google('gemini-2.5-flash'),
})
await memex.migrate()
const memory = memex.forUser({ userId: 'user_123', actor: 'assistant' })
const system = await memory.getSystemPrompt('You are a helpful assistant with durable user memory.')
const result = await generateText({
model: google('gemini-2.5-flash'),
system,
prompt: 'Remember that I prefer quiet neighborhoods near good schools.',
tools: memory.createAgenticToolset(),
stopWhen: stepCountIs(5),
})
console.log(result.text)
await memex.end()Python direct runtime
python3 -m pip install -e "sdks/python[test]"from memexai import create_memex
memex = await create_memex({
"databaseUrl": "postgresql://memexai:memexai@localhost:5433/memexai",
})
await memex.migrate()
memory = memex.for_user("user_123", actor="assistant")
await memory.write_file(
"user/profile.md",
"# Profile\n\n- Prefers quiet neighborhoods.",
reason="captured preference",
)
result = await memory.search("quiet neighborhoods")
await memex.close()Admin UI
Inspect direct-mode memory with the local admin CLI:
npx @memexai/admin --database-url postgresql://...The CLI opens http://localhost:4040/admin.