Spaces:
Paused
Paused
File size: 5,284 Bytes
3c59c25 ad75abf 3c59c25 ad75abf 5ec8557 36f3df7 5ec8557 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | ---
title: Mem0
emoji: π
colorFrom: pink
colorTo: pink
sdk: docker
pinned: false
---
# mem0 Self-Hosted on HuggingFace Spaces
Single-container deployment of mem0 (API + Dashboard + PostgreSQL) for HuggingFace Spaces, following the patterns from `buzz` (single-container) and `hermes` (supervisord + nginx).
## Architecture
```
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Single Container (Port 7860) β
β βββββββββββββββ βββββββββββββββ βββββββββββββββββββββββ β
β β PostgreSQL β β mem0 API β β mem0 Dashboard β β
β β (5432) β β (8000) β β (3000) β β
β ββββββββ¬βββββββ ββββββββ¬βββββββ ββββββββββββ¬βββββββββββ β
β β β β β
β ββββββββββββββββββΌβββββββββββββββββββββββ β
β βΌ β
β βββββββββββββββ β
β β Nginx β β
β β (7860) β β
β βββββββββββββββ β
β β β
β βββββββ΄ββββββ β
β β Supervisord β
β βββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
```
## Quick Start
### 1. Clone and Setup
```bash
cd mem0
cp .env.example .env
# Edit .env with your values (required: POSTGRES_PASSWORD, OPENAI_API_KEY, JWT_SECRET)
```
### 2. Build and Run
```bash
docker compose build
docker compose up -d
```
### 3. Access
- **Dashboard**: http://localhost:7860
- **API Docs**: http://localhost:7860/docs
- **Health Check**: http://localhost:7860/health
## Required Environment Variables
| Variable | Description | Required |
|----------|-------------|----------|
| `POSTGRES_PASSWORD` | PostgreSQL password (generate: `openssl rand -base64 32`) | Yes |
| `OPENAI_API_KEY` | OpenAI API key for LLM/embeddings | Yes |
| `JWT_SECRET` | JWT signing secret (generate: `openssl rand -base64 48`) | Yes |
| `ADMIN_API_KEY` | Optional admin API key (generate: `openssl rand -base64 32`) | No |
| `AUTH_DISABLED` | Set to `true` for local dev only | No (default: false) |
## Features
- β
**Single container** - All services in one container (like buzz)
- β
**HF Spaces compatible** - Singleton guard prevents duplicate runners
- β
**UID 1000** - Works with HF FUSE idmapped mounts
- β
**Supervisord** - Manages PostgreSQL, API, Dashboard, Nginx
- β
**Nginx routing** - Single port 7860 routes to all services
- β
**Persistent storage** - PostgreSQL data persisted to `/data` volume
- β
**Auth enabled by default** - Secure by default (JWT + API keys)
- β
**Health checks** - Built-in health endpoints
## Nginx Routing
| Path | Proxies To |
|------|------------|
| `/` | Dashboard (Next.js on 3000) |
| `/api/` | mem0 API (FastAPI on 8000) |
| `/docs` | OpenAPI docs |
| `/redoc` | ReDoc docs |
| `/openapi.json` | OpenAPI spec |
| `/health` | Health check (direct) |
## Data Persistence
- **PostgreSQL**: `/data/pgdata` β cluster lives directly on the HF persistent volume (no sync/backup loop; FUSE-safe boot repair for empty dirs, `.git/` injection, and `pg_tblspc` symlink)
- **Request logs**: `/opt/data/history` (ephemeral; survives restarts only while the container lives)
## Development
### View Logs
```bash
docker compose logs -f mem0
```
### Access Container
```bash
docker compose exec mem0 bash
```
### Run Migrations Manually
```bash
docker compose exec mem0 gosu mem0 alembic upgrade head
```
## HF Spaces Deployment
1. Create new Space with **Docker** SDK
2. Push this repository
3. Set required secrets in Space settings:
- `POSTGRES_PASSWORD`
- `OPENAI_API_KEY`
- `JWT_SECRET`
- `ADMIN_API_KEY` (optional)
4. Space will auto-deploy on port 7860
## Troubleshooting
### PostgreSQL won't start
Check logs: `docker compose logs mem0 | grep postgresql`
### Dashboard shows "API connection failed"
Verify `NEXT_PUBLIC_API_URL=http://localhost:7860/api` in environment
### Auth errors
Ensure `JWT_SECRET` is set and `AUTH_DISABLED=false` (default)
### Port conflicts
Change port mapping in `docker-compose.yml`: `"7860:7860"` β `"YOUR_PORT:7860"`
## License
Apache 2.0 - Based on mem0 (https://github.com/mem0ai/mem0)
|