|
| 1 | +# OpenClaw + LEANN Setup Guide |
| 2 | + |
| 3 | +Two ways to connect LEANN to your OpenClaw agent: **MCP server** (recommended) |
| 4 | +or **ClawHub skill**. |
| 5 | + |
| 6 | +--- |
| 7 | + |
| 8 | +## Option A: MCP Server (Recommended) |
| 9 | + |
| 10 | +OpenClaw natively supports MCP tools. LEANN ships an MCP server that exposes |
| 11 | +`leann_search` and `leann_list` as tools your agent can call directly. |
| 12 | + |
| 13 | +### 1. Install LEANN |
| 14 | + |
| 15 | +```bash |
| 16 | +pip install leann-core |
| 17 | +# or |
| 18 | +uv tool install leann-core --with leann |
| 19 | +``` |
| 20 | + |
| 21 | +### 2. Build an index on your memory files |
| 22 | + |
| 23 | +Using Ollama embeddings (recommended if you already run Ollama): |
| 24 | + |
| 25 | +```bash |
| 26 | +leann build openclaw-memory \ |
| 27 | + --docs ~/.openclaw/workspace/MEMORY.md ~/.openclaw/workspace/memory/ \ |
| 28 | + --embedding-mode ollama \ |
| 29 | + --embedding-model nomic-embed-text |
| 30 | +``` |
| 31 | + |
| 32 | +Or using local sentence-transformers (no Ollama required): |
| 33 | + |
| 34 | +```bash |
| 35 | +leann build openclaw-memory \ |
| 36 | + --docs ~/.openclaw/workspace/MEMORY.md ~/.openclaw/workspace/memory/ \ |
| 37 | + --embedding-mode sentence-transformers \ |
| 38 | + --embedding-model all-MiniLM-L6-v2 |
| 39 | +``` |
| 40 | + |
| 41 | +Add extra directories if you have them: |
| 42 | + |
| 43 | +```bash |
| 44 | +leann build openclaw-memory \ |
| 45 | + --docs ~/.openclaw/workspace/MEMORY.md \ |
| 46 | + ~/.openclaw/workspace/memory/ \ |
| 47 | + ~/Documents/notes/ \ |
| 48 | + --embedding-mode ollama \ |
| 49 | + --embedding-model nomic-embed-text |
| 50 | +``` |
| 51 | + |
| 52 | +### 3. Register the MCP server with OpenClaw |
| 53 | + |
| 54 | +Add to `~/.openclaw/openclaw.json`: |
| 55 | + |
| 56 | +```json5 |
| 57 | +{ |
| 58 | + // ... your existing config ... |
| 59 | + "mcpServers": { |
| 60 | + "leann": { |
| 61 | + "command": "leann_mcp", |
| 62 | + "args": [], |
| 63 | + "env": {} |
| 64 | + } |
| 65 | + } |
| 66 | +} |
| 67 | +``` |
| 68 | + |
| 69 | +### 4. Use it |
| 70 | + |
| 71 | +Ask your agent: |
| 72 | +- "Search my memories for database decisions" |
| 73 | +- "What did we decide about the API design?" |
| 74 | +- "Find my notes on deployment" |
| 75 | + |
| 76 | +The agent will call `leann_search` via MCP and return structured results. |
| 77 | + |
| 78 | +### 5. Keep the index fresh |
| 79 | + |
| 80 | +```bash |
| 81 | +# Re-run build (idempotent — only processes changed files) |
| 82 | +leann build openclaw-memory \ |
| 83 | + --docs ~/.openclaw/workspace/MEMORY.md ~/.openclaw/workspace/memory/ |
| 84 | + |
| 85 | +# Or use watch mode for continuous auto-sync |
| 86 | +leann watch openclaw-memory --interval 30 |
| 87 | +``` |
| 88 | + |
| 89 | +--- |
| 90 | + |
| 91 | +## Option B: ClawHub Skill |
| 92 | + |
| 93 | +If you prefer the skill-based approach: |
| 94 | + |
| 95 | +```bash |
| 96 | +clawhub install leann-team/leann-memory |
| 97 | +``` |
| 98 | + |
| 99 | +Or copy `skills/leann-memory/` from this repo to |
| 100 | +`~/.openclaw/workspace/skills/leann-memory/`. |
| 101 | + |
| 102 | +The skill tells your agent how to call `leann search` via shell commands. |
| 103 | +Setup steps (install + build index) are the same as above. |
| 104 | + |
| 105 | +--- |
| 106 | + |
| 107 | +## Important: Ollama Configuration |
| 108 | + |
| 109 | +If you use Ollama as your OpenClaw model provider, make sure your |
| 110 | +`~/.openclaw/openclaw.json` uses the **native Ollama API** — not the |
| 111 | +OpenAI-compatible endpoint: |
| 112 | + |
| 113 | +```json5 |
| 114 | +{ |
| 115 | + "models": { |
| 116 | + "providers": { |
| 117 | + "ollama": { |
| 118 | + "baseUrl": "http://127.0.0.1:11434", // no /v1 suffix |
| 119 | + "apiKey": "ollama-local", |
| 120 | + "api": "ollama" // NOT "openai-completions" or "openai-responses" |
| 121 | + } |
| 122 | + } |
| 123 | + } |
| 124 | +} |
| 125 | +``` |
| 126 | + |
| 127 | +Using `"openai-completions"` or `"openai-responses"` silently breaks tool |
| 128 | +calling — the model outputs tool calls as plain text instead of structured |
| 129 | +`tool_calls`. See [astral-sh/ty#21243](https://github.com/openclaw/openclaw/issues/21243). |
| 130 | + |
| 131 | +--- |
| 132 | + |
| 133 | +## Storage Comparison |
| 134 | + |
| 135 | +| Scenario | Default memory-core | LEANN | |
| 136 | +|---|---|---| |
| 137 | +| 1 year daily logs (~12K chunks) | ~23 MB | **~0.7 MB** | |
| 138 | +| + session transcripts (~100K chunks) | ~190 MB | **~6 MB** | |
| 139 | +| + 10 GB indexed documents (~500K chunks) | ~950 MB | **~30 MB** | |
| 140 | + |
| 141 | +All numbers assume 384-dimensional embeddings (all-MiniLM-L6-v2 or |
| 142 | +nomic-embed-text). |
| 143 | + |
| 144 | +--- |
| 145 | + |
| 146 | +## Troubleshooting |
| 147 | + |
| 148 | +**"leann: command not found"** |
| 149 | +Ensure LEANN is on your PATH. If installed via `uv tool install`, run |
| 150 | +`uv tool update-shell` and restart your terminal. |
| 151 | + |
| 152 | +**"Index not found"** |
| 153 | +Run `leann list` to see available indexes. Build one first with `leann build`. |
| 154 | + |
| 155 | +**Slow first search** |
| 156 | +The first query loads the embedding model (~90 MB). Subsequent queries reuse the |
| 157 | +warm daemon and are fast (~0.5s). Use `leann warmup openclaw-memory` to |
| 158 | +pre-warm. |
| 159 | + |
| 160 | +**Memory files changed but search results are stale** |
| 161 | +Re-run `leann build openclaw-memory --docs ...` — it detects changes |
| 162 | +automatically and only re-indexes what changed. |
| 163 | + |
| 164 | +**Agent doesn't use LEANN tools** |
| 165 | +Make sure your Ollama model supports tool calling (e.g. `qwen3:8b` or larger). |
| 166 | +Smaller models like `qwen3:4b` may not reliably invoke tools. |
0 commit comments