qmd update wipes the whole LLM cache (expansion + rerank) on every re-index
qmd update (and every re-index) unconditionally runs DELETE FROM llm_cache, so query-expansion and rerank results never survive an index refresh.
Where
qmd 2.8.3:
dist/cli/qmd.jsupdateCollections()→clearCache(db)(comment: "Clear Ollama cache on update")dist/cli/qmd.jsindexFiles()→clearCache(db)("Clear Ollama cache on index")dist/index.jsSDKupdate()→internal.clearCache()
clearCache is DELETE FROM llm_cache. There is no flag, env var or index.yml option to keep the cache.
Why it hurts
Anyone who keeps the index fresh (a file watcher calling qmd update, cron, a git hook) effectively runs without the LLM cache. We run qmd mcp --http as a shared server and refresh on file changes. Measured on Windows 11, GTX 1060 6 GB, 3.6k markdown files:
| step | time | rows in llm_cache |
|---|---|---|
query (candidateLimit 10), cold |
82.9 s | 10 |
| same query again | 7.6 s | 14 |
qmd update (0 files changed) |
7.2 s | 0 |
| same query again | 17.7 s | 10 |
With the default 40 rerank candidates a cold query takes 40–200 s here, so the cache is the difference between a result and an MCP client timeout (Claude Code aborts HTTP tool calls at 60 s). A retry after a timeout is exactly the case the cache should serve, but any update in between wipes it.
Why clearing looks unnecessary now
The cache keys already make stale entries unreachable:
- rerank:
getCacheKey("rerank", { query, model, chunk })— the chunk text is part of the key, so an edited document yields new keys; - expansion: keyed by query + model, independent of index content.
setCachedResult also trims the table to the newest 1000 rows (on ~1% of writes), so the size stays bounded without the wipe. The "Ollama" comments suggest this is left over from an earlier backend.
Proposal
Drop clearCache from updateCollections(), indexFiles() and SDK update() (keep it in qmd cleanup). If there is a reason to keep it, an opt-out (--keep-cache / QMD_KEEP_LLM_CACHE=1) would solve our case too.
Related: #921 (expansion-cache duplicates).
Source: tobi/qmd