Skip to content

Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors

Rust

docs+readme: rank Haiku as default; full per-provider config guide

AkitaOnRails5824c929e665
diff --git a/README.md b/README.md
index b85c4ca3..cfa59d48 100644
--- a/README.md
+++ b/README.md
@@ -206,24 +206,147 @@ preview without writing.
## LLM provider — recommended defaults
You can run ai-memory entirely without an LLM (FTS5 search +
-rule-based summaries, $0). When you do configure one, sensible
-defaults kick in for the model:
+rule-based summaries, $0). When you *do* configure one, the
+options below are ranked by fitness for ai-memory's
+consolidation workload — see
+[`docs/llm-provider-comparison.md`](docs/llm-provider-comparison.md)
+for the empirical writeup behind this ranking.
+
+> **TL;DR.** Use **Claude Haiku 4.5** as your default. Switch
+> to **GPT-5.4-mini** if you want the same quality cheaper +
+> faster. Switch to **qwen3:32b on Ollama** if you have a
+> local LLM server and prefer $0 / fully-self-hosted. The
+> three are interchangeable; pick once and forget.
+
+### Option 1 — Claude Haiku 4.5 *(recommended default)*
+
+Best balance of speed (~7 s), restraint, and classification
+quality. The only model that consistently classifies durable
+project rules as `kind: rule` so the consolidator auto-routes
+them to `_rules/<slug>.md`. ~$0.02 per consolidation; cost
+is negligible for personal use.
-| Provider env | Default model | Notes |
-|---|---|---|
-| `AI_MEMORY_LLM_PROVIDER=anthropic` | `claude-sonnet-4-6` | Smart enough to summarise a session, cheap enough to run on every session-end. |
-| `AI_MEMORY_LLM_PROVIDER=openai` | `gpt-4o-mini` | OpenAI equivalent of the Sonnet tier in price/quality. |
-| `AI_MEMORY_LLM_PROVIDER=openai-compat` | (required) | Set `AI_MEMORY_LLM_BASE_URL` + `AI_MEMORY_LLM_MODEL`. Use for Ollama, OpenRouter, vLLM, LM Studio. |
+```bash
+AI_MEMORY_LLM_PROVIDER=anthropic
+AI_MEMORY_LLM_MODEL=claude-haiku-4-5
+ANTHROPIC_API_KEY=sk-ant-…
+```
+
+Or via OpenRouter (handy if you already have an OpenRouter
+account and want one bill):
+
+```bash
+AI_MEMORY_LLM_PROVIDER=openai-compat
+AI_MEMORY_LLM_BASE_URL=https://openrouter.ai/api/v1
+AI_MEMORY_LLM_MODEL=anthropic/claude-haiku-4.5
+LLM_API_KEY=sk-or-v1-…
+```
+
+### Option 2 — OpenAI GPT-5.4-mini *(cheaper alternative)*
+
+~5× cheaper than Haiku, ~2× faster (~4 s avg). Same parse
+reliability, same faithfulness. One known weakness: mild
+over-classification on trivial sessions (will sometimes
+manufacture an extra `decisions/` page for a thin
+session). Acceptable for most users.
+
+```bash
+AI_MEMORY_LLM_PROVIDER=openai
+AI_MEMORY_LLM_MODEL=gpt-5.4-mini
+OPENAI_API_KEY=sk-…
+```
+
+Or via OpenRouter:
+
+```bash
+AI_MEMORY_LLM_PROVIDER=openai-compat
+AI_MEMORY_LLM_BASE_URL=https://openrouter.ai/api/v1
+AI_MEMORY_LLM_MODEL=openai/gpt-5.4-mini
+LLM_API_KEY=sk-or-v1-…
+```
+
+### Option 3 — Local Ollama qwen3:32b *(free / self-hosted)*
+
+$0 per consolidation. Requires a machine with at least ~24 GB
+of unified or VRAM memory to keep the Q4_K_M weights warm
+(~20 GB) plus headroom. Strix Halo / Apple Silicon / a
+recent NVIDIA card all work. Latency is ~90 s but
+consolidation is a background job — users never see it.
-Embedding defaults (when `AI_MEMORY_EMBEDDING_PROVIDER` is set):
+One-time setup on the Ollama host:
+
+```bash
+ollama pull qwen3:32b
+ollama pull nomic-embed-text # for embeddings; see below
+# Recommended Ollama env:
+# OLLAMA_KEEP_ALIVE=20m (keep models warm between consolidations)
+# OLLAMA_FLASH_ATTENTION=1
+# OLLAMA_KV_CACHE_TYPE=q8_0 (halves KV memory)
+```
+
+ai-memory env:
+
+```bash
+AI_MEMORY_LLM_PROVIDER=openai-compat
+AI_MEMORY_LLM_BASE_URL=http://<ollama-host>:11434/v1
+AI_MEMORY_LLM_MODEL=qwen3:32b
+LLM_API_KEY=ollama-local # any non-empty value; Ollama doesn't validate
+```
+
+If you bind ai-memory to a non-loopback address so Claude
+Code on a different machine can reach it, also set:
+
+```bash
+AI_MEMORY_ALLOWED_HOSTS=<your-host-or-ip>,localhost,127.0.0.1
+```
+
+(Without this rmcp's DNS-rebinding guard rejects external
+`Host` headers with 403. See
+[`docs/llm-provider-comparison.md`](docs/llm-provider-comparison.md)
+for the discovery story.)
+
+### What we don't recommend
+
+- **Claude Sonnet 4.5** — strictly dominated by Haiku for
+ this task: same parse reliability, 3× cost, hallucinated
+ details before the prompt was tightened. Use it only if
+ you specifically need extended reasoning (e.g. cross-page
+ lint sweeps).
+- **Reasoning-mode models** (Kimi-K2.6, Claude with extended
+ thinking enabled, GPT-o3, Gemini "thinking" variants) —
+ these models burn `max_tokens` budget on internal
+ reasoning before emitting visible content; with the
+ strict-JSON consolidation prompt they hang or emit empty
+ responses. If you must use one, turn reasoning off.
+
+### Embedding provider
+
+The LLM provider drives consolidation + lint. Embeddings are
+a *separate* concern (hybrid retrieval over the wiki — BM25
++ vector RRF). Defaults when `AI_MEMORY_EMBEDDING_PROVIDER`
+is set:
| Provider | Default model | Dim |
|---|---|---|
| `openai` | `text-embedding-3-small` | 1536 |
| `voyage` | `voyage-3` | 1024 |
-Per-tier feature breakdown + the openai-compat / Ollama setup is in
-[`docs/install.md`](docs/install.md#llm-provider-tiers).
+For the local stack, point the OpenAI embedder at Ollama:
+
+```bash
+AI_MEMORY_EMBEDDING_PROVIDER=openai
+AI_MEMORY_EMBEDDING_BASE_URL=http://<ollama-host>:11434/v1
+AI_MEMORY_EMBEDDING_MODEL=nomic-embed-text
+AI_MEMORY_EMBEDDING_DIM=768
+OPENAI_API_KEY=ollama-local
+```
+
+Skipping the embedding provider entirely is fine —
+`memory_query` falls back to pure FTS5 (BM25) and still
+works; you just lose vector re-ranking.
+
+Per-tier feature breakdown + the openai-compat / Ollama setup
+is in [`docs/install.md`](docs/install.md#llm-provider-tiers).
## Architecture in 60 seconds
diff --git a/docs/llm-provider-comparison.md b/docs/llm-provider-comparison.md
index fb50966b..b9306e0b 100644
--- a/docs/llm-provider-comparison.md
+++ b/docs/llm-provider-comparison.md
@@ -20,13 +20,18 @@
> typo-fix session (mild over-classification), where Haiku
> correctly emitted only the session log.
>
-> **Production choice**: Ollama `qwen3:32b` for default
-> consolidation ($0, latency irrelevant since consolidation is
-> background). **Best hosted fallback if budget is tight**:
-> GPT-5.4-mini (cheapest + fastest). **Best hosted fallback if
-> restraint matters most**: Haiku 4.5 (more disciplined on
-> "say nothing when there's nothing to say"). Reproduce the
-> comparison in [`evals/`](../evals/).
+> **Recommended default for most users: Claude Haiku 4.5.**
+> Hosted (always available), fast (~7 s), cheap enough that
+> per-session cost doesn't matter for personal use, and the
+> most disciplined hosted model on restraint + classification.
+> **Cheaper alternative**: GPT-5.4-mini (~5× cheaper than
+> Haiku, ~2× faster, mild over-classification on trivial
+> sessions). **Free alternative if you have a local LLM
+> server** (Ollama / vLLM / llama-swap with a 30B-class
+> model): qwen3:32b on Ollama — $0 per consolidation,
+> background latency invisible to users. See
+> [README → LLM provider configuration](../README.md#llm-provider--recommended-defaults)
+> for setup. Reproduce the comparison in [`evals/`](../evals/).
## Why this document exists
@@ -475,15 +480,16 @@ exuberant than Haiku.
Ranking on a 0–5 scale per axis, then aggregated.
**Higher is better** in every column except Cost (where
lower-cost gets a higher score). Bold = best in that column.
+Rows sorted by overall fitness for ai-memory.
-| Provider | Parse | Speed | Cost† | Faithfulness | Restraint | Classification | Fitness for ai-memory |
-|---|---|---|---|---|---|---|---|
-| **qwen3:32b (Ollama)** | 5 | 1 | **5** ($0) | 5 | **5** | 4 | **5** — production default |
-| **Haiku 4.5** | 5 | 4 | 3 | 5 | **5** | **5** | 5 — best hosted fallback |
-| GPT-5.4-mini | 5 | **5** | **5** | 5 | 3 | 4 | 4 — cheap+fast but mild over-extraction |
-| Sonnet 4.5 | 5 | 4 | 1 | 4‡ | 4 | 3 | 3 — displaced by Haiku |
-| DeepSeek V4 Flash | 5 | 2 | 4 | 5 | **5** | **5** | 4 — solid but no edge over Haiku |
-| Kimi-K2.6 | 0 | 0 | n/a | n/a | n/a | n/a | **0** — ineligible (reasoning model) |
+| # | Provider | Parse | Speed | Cost† | Faithfulness | Restraint | Classification | Fitness |
+|---|---|---|---|---|---|---|---|---|
+| 1 | **Haiku 4.5** | 5 | 4 | 3 | 5 | **5** | **5** | **5** — recommended default |
+| 2 | **GPT-5.4-mini** | 5 | **5** | **5** | 5 | 3 | 4 | 4 — cheaper alternative |
+| 3 | **qwen3:32b (Ollama)** | 5 | 1 | **5** ($0) | 5 | **5** | 4 | 4 — free if you have a local server |
+| 4 | DeepSeek V4 Flash | 5 | 2 | 4 | 5 | **5** | **5** | 4 — no edge over GPT-mini or Haiku |
+| 5 | Sonnet 4.5 | 5 | 4 | 1 | 4‡ | 4 | 3 | 3 — displaced by Haiku |
+| 6 | Kimi-K2.6 | 0 | 0 | n/a | n/a | n/a | n/a | **0** — ineligible (reasoning model) |
† Cost score derived from order-of-magnitude $/M output tokens:
$0 (qwen3) = 5; ~$0.40 (DeepSeek) = 4; ~$1 (GPT-mini) = 5 by
@@ -525,24 +531,44 @@ better defaults for this task.
For ai-memory's consolidation task specifically:
-1. **qwen3:32b on Ollama** — fits free, restrained, faithful,
- homelab handles latency invisibly. Tied for top on every
- non-speed axis; speed doesn't matter for background work.
-2. **Haiku 4.5** — best hosted choice when local is unreachable.
- Restraint + classification edge over GPT-mini and DeepSeek.
-3. **GPT-5.4-mini** — pick if you're hosted-only and budget-
- sensitive. Fastest + cheapest, only weak point is
- over-classification of trivial sessions.
-4. **DeepSeek V4 Flash** — solid but no edge over GPT-mini or
- Haiku on either cost+speed or quality. Pick if your stack
- is already DeepSeek-ish.
-5. **Sonnet 4.5** — only if you specifically need the extra
- reasoning headroom (lint sweep, cross-page contradiction
- detection); for plain consolidation it's strictly dominated
- by Haiku.
-6. **Kimi-K2.6** — ineligible. Reasoning model burns
- `max_tokens` on internal thinking before emitting visible
- content.
+1. **Haiku 4.5** — **recommended default for most users.**
+ Hosted (always available), 7 s avg latency, restraint +
+ classification top of the field, ~$0.02/run is negligible
+ for personal use. The benchmark every other option is
+ measured against.
+2. **GPT-5.4-mini** — **cheaper hosted alternative.** ~5×
+ cheaper than Haiku, 2× faster (4 s avg). Only weakness is
+ mild over-classification on trivial sessions
+ (manufactures one extra "decisions/" page on a typo-fix
+ session). If budget matters more than restraint, pick
+ this.
+3. **qwen3:32b on Ollama** — **free alternative for those
+ with a local server.** $0 per consolidation. ~92 s
+ latency is invisible because consolidation is a background
+ job. Restraint + faithfulness match the top hosted models.
+ Requires Ollama (or compatible OpenAI-compat server) with
+ `qwen3:32b` pulled and enough RAM/VRAM (~20 GB) to keep
+ it warm.
+4. **DeepSeek V4 Flash** — **solid but no clear edge.** All
+ reliability bars met, faithful, restrained, correctly
+ classifies rules. But GPT-mini matches it on quality and
+ beats it on speed; Haiku matches it on quality and beats
+ it on classification consistency. Pick only if your
+ workflow is already DeepSeek-leaning.
+5. **Sonnet 4.5** — **strictly dominated by Haiku** for
+ plain consolidation. 3× the cost for the same parse rate
+ and only marginally different latency. Reserve for tasks
+ that *specifically* need extended reasoning (cross-page
+ lint sweeps that compare contradictory claims across many
+ pages, or for sparse-observation sessions where you want
+ the model to infer more aggressively).
+6. **Kimi-K2.6** — **ineligible.** Reasoning model burns
+ `max_tokens` budget on internal thinking before emitting
+ visible content. Hangs indefinitely on strict-JSON
+ prompts. Same caveat applies to any other reasoning-mode
+ model (Claude with extended thinking, GPT-o3, Gemini
+ "thinking" variants) — turn reasoning off or budget
+ tokens with consumption in mind before using them here.
## Qualitative read (Run 2)