# Mem0 Memory Storage - PolarDB-X Zero

## Quick Start

To get a free Mem0 memory storage instance:

### Step 1: Request an instance

```bash
curl -s -X POST https://zero.polardbx.com/api/v1/mem0 \
  -H 'Content-Type: application/json' \
  -d '{"tag":"agent-trial"}'
```

Response:
```json
{
  "id": "mem0_xxx",
  "endpoint": "http://xxx.polardbx.rds.aliyuncs.com:8080",
  "apiKey": "your-api-key",
  "region": "cn-hangzhou"
}
```

### Step 2: Use the Mem0 API

**Important: All API URLs must end with a trailing slash `/` to avoid 307 redirect issues.**

Add a memory:
```bash
curl -L -X POST http://ENDPOINT/v1/memories/ \
  -H "Authorization: Token API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"messages":[{"role":"user","content":"I like pizza"}],"user_id":"demo"}'
```

Search memories:
```bash
curl -L -X POST http://ENDPOINT/v1/memories/search/ \
  -H "Authorization: Token API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"query":"food preferences","user_id":"demo"}'
```

Get a specific memory:
```bash
curl -L http://ENDPOINT/v1/memories/MEMORY_ID/ \
  -H "Authorization: Token API_KEY"
```

Delete a memory:
```bash
curl -L -X DELETE http://ENDPOINT/v1/memories/MEMORY_ID/ \
  -H "Authorization: Token API_KEY"
```

### Step 3: Python SDK (optional)

```python
from mem0ai import MemoryClient
client = MemoryClient(api_key="API_KEY", host="ENDPOINT")
client.add("I like pizza", user_id="demo")
results = client.search("food preferences", user_id="demo")
print(results)
```

## Important Notes

- **URL trailing slash**: All Mem0 API paths must end with `/` (e.g. `/v1/memories/`). Without it, the server returns 307 redirect, and curl won't forward the Authorization header by default.
- **Use `-L` flag with curl**: This follows redirects. Combined with trailing slash, it ensures requests work correctly.
- **Auth format**: `Authorization: Token <apiKey>` (not Bearer).
- Free trial, no payment required.
- API is compatible with mem0ai Python SDK.
