WrenAI icon indicating copy to clipboard operation
WrenAI copied to clipboard

wren memory index is full-rebuild only; blocks concurrent memory fetch/recall (no incremental/background mode)

Open Kaede10 opened this issue 2 months ago • 1 comments

Summary

wren memory index performs a full rebuild of the LanceDB embedding index every run, and there is no incremental or background mode. While a rebuild is running, memory fetch / memory recall — which read the same LanceDB files under .wren/memory/ — degrade drastically (observed 140s+ waits, effectively queued). This makes the CLI unusable for querying while indexing runs.

Environment

  • wrenai CLI: 0.13.3 (pip, with the memory extra)
  • Backend: lancedb
  • Project scale: 2730 models, 44439 schema_items rows, .wren/memory/ ~120 MB

Evidence

wren memory index --help shows no incremental / background option:

Usage: wren memory index [OPTIONS]

Options:
  --mdl          -m   <str>  Path to MDL JSON file.
  --path         -p   <str>  LanceDB storage directory.
  --instructions --no-instructions   Also index user instructions ...
  --no-seed                Skip generating seed NL-SQL examples.
  --no-queries             Skip auto-loading project queries.yml.

wren memory status:

Backend: lancedb
  query_history: 4846 rows
  schema_items: 44439 rows

wren memory fetch --help notes large schemas use embedding search (i.e. depend on the same index being ready):

Small schemas are returned as full plain text. Large schemas use
embedding search with optional --type and --model filters.

Impact

  • On large projects (thousands of models), every memory index re-embeds all schema_items even when only a few rules / MDL column descriptions changed.
  • Cannot run fetch/recall concurrently with index, so the edit → index → query workflow must be strictly serial, blocking agent workflows for minutes per change.
  • Frequent small edits become impractical because each triggers a multi-minute full rebuild.

Suggested improvements

  1. Incremental indexing — only re-embed changed models/rules/cubes (track a hash/mtime per schema_item + knowledge file) and skip unchanged rows.
  2. Non-blocking / atomic-swap indexing — build into a new LanceDB table/directory and atomically swap on completion, so readers continue against the previous index until the new one is ready (read isolation during rebuild).
  3. At minimum, document that memory index is a full rebuild that blocks fetch/recall, so users sequence operations accordingly.

Any of these would significantly improve the UX of the memory extra on large projects.

Kaede10 avatar Sep 22 '26 08:09 Kaede10

Hi, I'd like to take a shot at this. The contributing guide says to talk before larger changes, so here's what I have in mind: make 'wren memory index' incremental by tracking a hash per schema item, re-embedding only what changed and dropping rows for models that no longer exist. Does that direction work for you, or would you also want a background mode so fetch and recall stay responsive while it runs? Happy to start once I know which way you prefer.

tharunsridhar avatar Nov 09 '26 09:11 tharunsridhar