#19100: Fix memory vector store dimension mismatch by resetting index
size: S
trusted-contributor
Cluster:
Memory Management Enhancements
## Description
When switching embedding models (e.g. text-embedding-3-small to nomic-embed-text), the vector dimensions change, causing qmd update/embed commands to fail with 'dimension mismatch'. This leaves the memory system broken.
## Fix
Detect dimension mismatch errors during update/embed loop, and automatically reset the index (delete index.sqlite) to trigger a full re-index. The repair is attempted once per manager lifetime to avoid infinite loops.
Key improvement over previous attempt: `resetIndex()` does NOT call `this.close()`, which would permanently disable the memory manager after repair.
## AI Transparency
- **Assisted by**: OpenClaw Agent (Claude Opus)
- **Testing level**: Manual review + type check verification
- **Prompt strategy**: Extracted targeted fix from multi-feature PR
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Added automatic recovery for dimension mismatch errors that occur when switching embedding models. When `qmd update` or `qmd embed` fails with a dimension mismatch, the system now detects the error and resets the index by deleting the SQLite database files and re-initializing collections. The repair is attempted once per manager lifetime via the `attemptedDimensionMismatchRepair` flag to prevent infinite loops.
Key improvements:
- Detects dimension mismatch errors through pattern matching on error messages
- `resetIndex()` closes the read-only DB handle without calling `this.close()`, which would permanently disable the manager
- Handles both `update` and `embed` command failures
- Falls back gracefully if the reset itself fails
<h3>Confidence Score: 4/5</h3>
- Safe to merge with low risk - implements a focused auto-repair mechanism for a known error scenario
- The implementation follows the existing pattern for null-byte repair, correctly avoids calling `this.close()` during reset (which was the bug in the previous attempt), and includes proper once-per-lifetime guard against infinite loops. The dimension mismatch detection patterns are reasonable and the error handling is consistent with the codebase style. Minor confidence deduction for lack of test coverage for the new repair logic.
- No files require special attention - the changes are well-contained and follow established patterns
<sub>Last reviewed commit: ea26886</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#11179: fix(memory): replace confusing "No API key" errors in memory tools ...
by liuxiaopai-ai · 2026-02-07
73.6%
#21471: fix: check QMD backend before memory search config
by lbo728 · 2026-02-20
73.4%
#17660: fix: skip embedding provider check in doctor when QMD backend is co...
by echoVic · 2026-02-16
73.2%
#16917: fix(memory): close stale SQLite connection after qmd update
by zerone0x · 2026-02-15
73.2%
#9149: Fix: Allow QMD backend to work without OpenAI auth
by vishaltandale00 · 2026-02-04
73.1%
#9624: fix(memory): resolve QMD search returning empty results [AI-assisted]
by kowshik24 · 2026-02-05
73.0%
#20125: fix(doctor): skip memorySearch provider check when using QMD backend
by brandonwise · 2026-02-18
72.9%
#19115: fix(logging): improved redaction for config objects and unquoted keys
by Clawborn · 2026-02-17
72.9%
#21816: Add configurable `dimensions` for embedding models (Matryoshka supp...
by matthewspear · 2026-02-20
72.7%
#11364: fix(memory/qmd): prevent cascading failure when query fails or retu...
by blazerui · 2026-02-07
72.1%