---
title: "Deploy Mem0 Memory API + pgvector"
description: "Mem0 memory layer for AI agents: REST API, dashboard and pgvector Postgres"
category: "AI/ML"
url: https://railway.com/deploy/mem0-memory-api-pgvector
---

# Deploy Mem0 Memory API + pgvector

Mem0 memory layer for AI agents: REST API, dashboard and pgvector Postgres

**[Deploy Mem0 Memory API + pgvector on Railway](https://railway.com/template/mem0-memory-api-pgvector)**

Machine-readable deploy manifest (JSON, validated by TemplateCI): https://railway.com/deploy/mem0-memory-api-pgvector/manifest.json

- **Creator:** Protemplate
- **Category:** AI/ML
- **Total deploys:** 4

## Template content

### Postgres https://devicons.railway.app/i/postgresql.svg

- **Image:** pgvector/pgvector:pg17

### Mem0 API https://raw.githubusercontent.com/mem0ai/mem0/main/docs/logo/favicon.svg

- **Source:** https://github.com/mem0ai/mem0
- **Start command:** `sh -c 'pip install --no-cache-dir --quiet "psycopg[binary]" && alembic upgrade head && exec uvicorn main:app --host 0.0.0.0 --port "$PORT" --proxy-headers --forwarded-allow-ips "*"'`
- **Health check:** /docs
- **Public domain:** Yes

### Mem0 Dashboard https://raw.githubusercontent.com/mem0ai/mem0/main/docs/logo/favicon.svg

- **Source:** https://github.com/mem0ai/mem0
- **Health check:** /api/health
- **Public domain:** Yes

## Documentation

# Deploy and Host Mem0 on Railway

Mem0 is an open-source memory layer for AI agents and apps. It extracts durable facts from conversations, stores them as embeddings, and lets your agent recall them per user, agent, or session through a simple REST API. This template deploys the official self-hosted Mem0 server with its web dashboard and a pgvector Postgres database.

## About Hosting Mem0

Hosting Mem0 means running the FastAPI REST server next to PostgreSQL with the pgvector extension, which holds both the memory embeddings and the app tables for users, API keys, request logs, and runtime settings. The dashboard is a separate Next.js service that talks to the API over its public HTTPS domain, and the API's CORS allow-list contains only the dashboard origin. Both app services are built directly from the upstream repository (`server/` and `server/dashboard/`), because Mem0 does not publish a maintained prebuilt image for the current server. Authentication is on by default: the first visit to the dashboard runs a setup wizard that creates the admin account, and a generated `ADMIN_API_KEY` lets you call the API immediately.

## Common Use Cases

- **Agent memory**: give chatbots and autonomous agents long-term memory across sessions
- **Personalisation**: remember user preferences, facts, and history per `user_id`
- **Multi-agent state**: scope memories by `agent_id` and `run_id`
- **Semantic recall**: `POST /search` returns the most relevant memories for a query
- **Auditing**: the dashboard shows every API request, entity, and memory

## Dependencies for Mem0 Hosting

- **PostgreSQL with pgvector** (included, `pgvector/pgvector:pg17`)
- **OpenAI API key** (required; the server initialises its OpenAI LLM and embedder at startup and will not boot without one)
- **Anthropic or Google keys** (optional; switch providers later in the dashboard Configuration page)
- **No Neo4j and no Redis** are needed for the REST server

### Deployment Dependencies

- [Mem0 REST API docs](https://docs.mem0.ai/open-source/features/rest-api)
- [Mem0 server README](https://github.com/mem0ai/mem0/tree/main/server)
- [Mem0 GitHub repository](https://github.com/mem0ai/mem0)

### Implementation Details

The API service installs the `psycopg[binary]` Postgres driver (upstream's Dockerfile currently omits it), runs `alembic upgrade head` so the app tables exist on first boot, then starts uvicorn on `0.0.0.0` so Railway's healthcheck can reach it. Memory history lives on a volume at `/app/history`. Both app services build from the upstream `main` branch, so a redeploy picks up upstream changes. Postgres holds the `memories` vector table and the app tables in one database.

```env
PORT=8000
OPENAI_API_KEY=
JWT_SECRET=${{secret(64)}}
ADMIN_API_KEY=${{secret(32)}}
POSTGRES_HOST=${{Postgres.PGHOST}}
DASHBOARD_URL=https://${{Mem0 Dashboard.RAILWAY_PUBLIC_DOMAIN}}
NEXT_PUBLIC_API_URL=https://${{Mem0 API.RAILWAY_PUBLIC_DOMAIN}}
API_INTERNAL_URL=https://${{Mem0 API.RAILWAY_PUBLIC_DOMAIN}}
```

After deploy, open the dashboard URL and complete the setup wizard, then create a per-user API key under API Keys. Store a memory with `POST /memories` and the `X-API-Key` header, and read it back with `GET /memories?user_id=...`. Interactive API docs live at `/docs` on the API service.

## 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 get the API, dashboard, and pgvector database wired together with generated secrets, health checks, managed SSL, and private networking to the rest of your project.


## Similar templates

- [Chat Chat](https://railway.com/deploy/-WWW5r) — Chat Chat, your own unified chat and search to AI platform.
- [stella](https://railway.com/deploy/stella) — Self-host stella with web, API, Postgres, Redis, and object storage.
- [Hermes Agent | OpenClaw Alternative with Dashboard](https://railway.com/deploy/hermes-agent-or-openclaw-alternative-wit) — Self-Hosted Hermes AI Agent for Telegram, Discord & Slack

Open this page in a browser: https://railway.com/deploy/mem0-memory-api-pgvector
