Deploy Mem0
Memory layer for AI agents: Mem0 REST API, dashboard and pgvector
Just deployed
Just deployed
/app/history
Postgres
Just deployed
/var/lib/postgresql/data
Deploy and Host Mem0 on Railway
Mem0 is the open-source memory layer for AI agents and assistants. Your app sends it the messages of a conversation; Mem0 uses a language model to pull out the facts worth keeping ("is vegetarian", "prefers short answers", "works on the billing service"), stores them per user, agent or run, updates or drops old ones when new information contradicts them, and gives back the relevant memories for the next prompt through a vector search. It is licensed Apache-2.0. This template runs Mem0 2.2.1's self-hosted server on Railway: the REST API, the dashboard and Postgres with pgvector, with logins and API keys required from the first boot.
This is a community template, not made or supported by Mem0.
About Hosting Mem0
Before deploying, paste a model key into OPENAI_API_KEY on the Mem0 service. An OpenAI key works as is (Mem0 uses gpt-5-mini and text-embedding-3-small). For OpenRouter, paste an OpenRouter key there and set OPENAI_BASE_URL=https://openrouter.ai/api/v1; the models then default to openai/gpt-5-mini and openai/text-embedding-3-small. MEM0_DEFAULT_LLM_MODEL and MEM0_DEFAULT_EMBEDDER_MODEL pick others.
Deploy and wait for the green checks. Then:
- Dashboard: open the Dashboard service's domain and sign in with
ADMIN_EMAILandADMIN_PASSWORDfrom the Mem0 service's variables (the password is generated). There you browse and delete memories, see every user and agent that has memories, watch the request log, change the models, and create API keys. - API: the Mem0 service's domain. Send
X-API-Key: ‹key›with each request: the generatedADMIN_API_KEYfrom the Mem0 service's variables, or a per-user key from the dashboard. Interactive docs are at/docs.
curl -X POST https://‹your-mem0-domain›/memories \
-H "X-API-Key: ‹key›" -H "Content-Type: application/json" \
-d '{"messages":[{"role":"user","content":"I am vegetarian and allergic to peanuts."}],"user_id":"alice"}'
curl -X POST https://‹your-mem0-domain›/search \
-H "X-API-Key: ‹key›" -H "Content-Type: application/json" \
-d '{"query":"what can alice eat?","filters":{"user_id":"alice"}}'
Why the admin is created for you: upstream's server lets whoever first opens the setup page (or calls /auth/register) become the admin. This template creates the admin from ADMIN_EMAIL and ADMIN_PASSWORD before the API opens, so registration is closed from the start. Change the password later in the dashboard's Settings. Lost it? Set RESET_ADMIN_PASSWORD=true on the Mem0 service, redeploy (the password goes back to ADMIN_PASSWORD), then delete the variable.
Model costs: every POST /memories makes one or two model calls (extracting facts, then deciding what to add, update or delete) plus embeddings; every search makes one embedding call. The defaults are small, cheap models; watch your provider's usage page in the first days.
Your data: memories (vectors) and the users, API keys and settings live in the Postgres service on its volume. The Mem0 service's own volume keeps the memory change history and the recent messages Mem0 reads when extracting new facts. Redeploys keep both.
Telemetry: upstream sends anonymous usage events by default. This template sets MEM0_TELEMETRY=false; set it to true to send them.
Common Use Cases
- Long-term memory for a chatbot, support assistant or coding agent, kept on your own infrastructure
- Remembering each user's preferences and facts across sessions without resending whole transcripts
- Shared or per-agent memory in multi-agent setups (scope memories by
user_id,agent_idorrun_id) - A memory backend for the Mem0 Python and TypeScript SDKs, LangChain, LangGraph, CrewAI and other frameworks that speak Mem0's REST API
- Inspecting and cleaning what an assistant has learned about a user from a dashboard
Dependencies for Mem0 Hosting
- Postgres with pgvector (included)
- An API key for OpenAI, OpenRouter or another OpenAI-compatible provider that serves both chat and embeddings
Deployment Dependencies
Implementation Details
- Services: Mem0 (the FastAPI server, on a Railway domain, with a small volume), Dashboard (Next.js, on its own domain) and Postgres 17 with pgvector on Railway's private network. Upstream's optional graph memory (Neo4j) is left out.
- Images: Mem0's own server image stopped updating in September 2025, so this template builds the 2.2.1 release itself on GitHub Actions: upstream's
server/code unmodified, themem0ailibrary pinned to the same version, and the dashboard built as upstream's Dockerfile does. A deploy pulls finished images; updates come as tested version bumps. - Database: the first boot creates the
mem0_appdatabase (users, keys, settings) next to the memory database and runs upstream's migrations on every start. - Never crash-looping on a variable: with no model key, a key the provider rejects, a too-short
JWT_SECRETorADMIN_PASSWORD, an invalidADMIN_EMAILor a database that never answers, the API serves a message saying what to fix instead of restarting over and over. The deploy logs say the same. - Other providers: Mem0's image also bundles Anthropic and Gemini. Switch to them on the dashboard's Configuration page (or
POST /configure); embeddings then need OpenAI-compatible or Gemini. - Memory: measured on Railway with every service capped at 0.5 GB and again at 1 GB, under 20 memory adds and 60 searches: the API about 230 MB, the dashboard 50–150 MB and Postgres about 40–90 MB (Railway's figure, which includes file cache). Each fits a 0.5 GB service; no service was killed at either cap.
Why Deploy Mem0 on Railway?
Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.
By deploying Mem0 on Railway, you are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more on Railway.
Template Content
OPENAI_API_KEY
Required: an OpenAI key (Mem0 uses gpt-5-mini to extract memories and text-embedding-3-small to search them). An OpenRouter key works too with OPENAI_BASE_URL set below.
Postgres
pgvector/pgvector:0.8.7-pg17
