Skip to main content
Glama
README.md
# Hippo

Self-hosted personal memory layer for Claude.ai, Claude Code, and any AI agent that supports MCP.

Stores memories as semantic embeddings in Qdrant using Ollama for local inference — no OpenAI, no external embedding API. Exposes an MCP server that Claude.ai connects to via OAuth, and a REST API for agent scripts.

Includes a weekly reconcile job that deduplicates and merges near-identical memories using an LLM, with a Telegram-based review and approve flow.

---

## What it does

- **Add memories** — any connected client can store a memory (text → embedding → Qdrant)
- **Search memories** — semantic search across everything stored
- **Weekly reconcile** — finds near-duplicate memories, proposes merges via Claude, sends a Telegram summary with a one-click approve link
- **Claude.ai integration** — full OAuth 2.1 + PKCE flow so Claude.ai can connect as an MCP remote server
- **Claude Code integration** — API key header auth for local use
- **Agent scripts** — simple REST endpoints (`POST /add_memory`, `POST /search_memory`) for shell scripts or any HTTP client

---

## Stack

| Component | Role |
|-----------|------|
| `hippo-mcp.py` | MCP server + REST API + OAuth server |
| `hippo-reconcile.py` | Weekly deduplication script |
| Qdrant (Docker) | Vector database |
| Ollama | Local embeddings (`nomic-embed-text`, 768 dims) |
| cloudflared | Tunnel to expose the server publicly (for Claude.ai) |
| systemd | Service management |

---

## Prerequisites

- Linux server (tested on Ubuntu 24.04)
- Docker + Docker Compose
- Ollama installed and running (`ollama serve`)
- `nomic-embed-text` pulled: `ollama pull nomic-embed-text`
- A public domain or subdomain pointing to your server via cloudflared
- Python 3.10+ (3.10 minimum for `match` syntax used in the reconcile script)
- An OpenRouter API key (for the reconcile LLM calls — Claude Haiku)
- A Telegram bot and chat ID (for reconcile notifications)

---

## Installation

### 1. Clone the repo

```bash
git clone https://github.com/sebastienlauzie/hippocampus.git /srv/hippo
cd /srv/hippo
```

### 2. Start Qdrant

```bash
docker compose up -d
```

Qdrant will be available at `http://localhost:6333`. The collection is created automatically on first run.

### 3. Set up the Python environment

```bash
python3 -m venv venv
venv/bin/pip install -r requirements.txt
```

### 4. Create the API key

Generate a random key and store it where the service expects it:

```bash
sudo mkdir -p /etc/hippo
openssl rand -hex 32 | sudo tee /etc/hippo/api_key
sudo chmod 640 /etc/hippo/api_key
sudo chown root:$(whoami) /etc/hippo/api_key
```

### 5. Configure Telegram notifications (for reconcile)

```bash
sudo tee /etc/hippo/telegram.json > /dev/null << 'EOF'
{
  "botToken": "your-telegram-bot-token",
  "chatId": your-chat-id
}
EOF
sudo chmod 640 /etc/hippo/telegram.json
sudo chown root:$(whoami) /etc/hippo/telegram.json
```

### 6. Configure OpenRouter key (for reconcile)

```bash
echo "your-openrouter-api-key" | sudo tee /etc/hippo/openrouter_key
sudo chmod 640 /etc/hippo/openrouter_key
sudo chown root:$(whoami) /etc/hippo/openrouter_key
```

### 7. Set up cloudflared

Install cloudflared and create a tunnel pointing to `localhost:8765`. Your tunnel's public URL is what you'll set as `HIPPO_PUBLIC_URL`.

See [Cloudflare Tunnel docs](https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/).

### 8. Install the systemd service

```bash
sudo cp hippo.service.example /etc/systemd/system/hippo.service
```

Edit the service file to set your values:

```ini
Environment=HIPPO_PUBLIC_URL=https://your-hippo-domain.example.com
Environment=HIPPO_DEFAULT_USER=yourname
```

Then enable and start:

```bash
sudo systemctl daemon-reload
sudo systemctl enable hippo
sudo systemctl start hippo
```

Check it's running:

```bash
sudo systemctl status hippo
curl http://localhost:8765/health
```

---

## Connecting Claude.ai

1. In Claude.ai, go to **Settings → Integrations → Add custom integration**
2. Set the MCP server URL to: `https://your-hippo-domain.example.com/mcp`
3. Set the OAuth Client ID to: `hippo`
4. Claude.ai will redirect you to your `/authorize` page — enter your API key to grant access
5. Token is valid for 90 days

## Connecting Claude Code

Add to your `~/.claude.json` MCP servers config:

```json
{
  "mcpServers": {
    "hippo": {
      "type": "http",
      "url": "http://localhost:8765/mcp",
      "headers": {
        "X-API-Key": "your-api-key"
      }
    }
  }
}
```

---

## Weekly reconcile

The reconcile script finds near-duplicate memories, asks Claude to decide whether to merge or keep them, and sends you a Telegram message with a review link.

**Set up a weekly cron job:**

```bash
# Run dry-run every Saturday at 2am (adjust to your timezone)
0 6 * * 6 /srv/hippo/venv/bin/python3 /srv/hippo/hippo-reconcile.py --dry-run
```

**Flow:**
1. Cron runs `--dry-run` → analyses all memories → saves proposed changes
2. Telegram message arrives with a link to review the proposals
3. You click "Approve" in the browser → merges are applied, Telegram confirmation sent
4. Token expires after 48h — if you don't approve, nothing changes

**Manual run:**

```bash
# Dry run (analyse and propose)
venv/bin/python3 hippo-reconcile.py --dry-run

# Execute pending proposals (after reviewing)
venv/bin/python3 hippo-reconcile.py --execute
```

---

## REST API (for agent scripts)

Both endpoints require `X-API-Key` header.

```bash
# Store a memory
curl -X POST http://localhost:8765/add_memory \
  -H "X-API-Key: your-api-key" \
  -H "Content-Type: application/json" \
  -d '{"text": "Some fact to remember"}'

# Search memories
curl -X POST http://localhost:8765/search_memory \
  -H "X-API-Key: your-api-key" \
  -H "Content-Type: application/json" \
  -d '{"query": "what do I know about X", "limit": 5}'
```

---

## Architecture notes

**Embeddings:** `nomic-embed-text` via Ollama, 768-dimensional Cosine similarity. Qdrant collection is created automatically on first start.

**Auth — two modes:**
- `X-API-Key` header — for Claude Code, scripts, direct API calls
- OAuth 2.1 + PKCE — for Claude.ai (the `/authorize` page asks for your API key and issues a 90-day bearer token)

**No OpenAI dependency.** Everything runs locally via Ollama except the reconcile LLM calls, which use Claude Haiku via OpenRouter. You could swap that for any OpenAI-compatible endpoint.

**Qdrant network:** Qdrant is bound to `127.0.0.1:6333` only — not exposed externally. If you're running Ollama on the same host as Docker, you may need a UFW rule to allow the Docker bridge subnet to reach port 11434:

```bash
# Allow Docker containers to reach Ollama on the host
# Add to /etc/ufw/before.rules (before the COMMIT line):
-A ufw-before-input -s 172.18.0.0/16 -p tcp --dport 11434 -j ACCEPT
```

Then `sudo ufw reload`.

---

## Environment variables

See `.env.example` for the full list. Key ones:

| Variable | Default | Description |
|----------|---------|-------------|
| `HIPPO_PUBLIC_URL` | *(required)* | Your public URL — used in OAuth and Telegram links |
| `HIPPO_DEFAULT_USER` | `user` | Default namespace for memories |
| `HIPPO_QDRANT_URL` | `http://localhost:6333` | Qdrant URL |
| `HIPPO_OLLAMA_URL` | `http://localhost:11434` | Ollama URL |
| `HIPPO_PORT` | `8765` | Port the MCP server listens on |