fix(search): hint at mempalace repair when filtered query hits HNSW index mismatch (#1035)#1081
fix(search): hint at mempalace repair when filtered query hits HNSW index mismatch (#1035)#1081potterdigital wants to merge 2 commits intoMemPalace:developfrom
mempalace repair when filtered query hits HNSW index mismatch (#1035)#1081Conversation
… index mismatch (MemPalace#1035) When a pre-1.0 palace is queried with a `where` filter, ChromaDB raises an opaque `Error finding id ...` and the user has no way to discover that `mempalace repair` rebuilds the HNSW index. Detect that exact signature (filter in play + `Error finding id` in the message) in both the CLI `search()` and the API `search_memories()` paths and surface a hint pointing at the repair command before re-raising / returning the error dict. Guarded so unrelated query failures (no filter, or different error text) do not get a misleading repair suggestion. Three new tests in tests/test_searcher.py::TestHNSWRepairHint cover the CLI positive, API positive, and negative-guard paths. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
jphein
left a comment
There was a problem hiding this comment.
Reviewed on review/1081 branch against upstream/develop:
- All three
TestHNSWRepairHinttests pass locally (pytest tests/test_searcher.py::TestHNSWRepairHint -v). - Full
tests/test_searcher.pysuite: 24 passed. - Diff reads clean — guard
where and "Error finding id" in str(e)is correctly narrow; CLI prints hint before re-raising, API path returns it as a first-classhintkey so MCP-server consumers don't have to parse stderr.
On the live-data smoke: my own palace (1.5.x, 165K drawers) doesn't reproduce the stale-HNSW failure mode the hint targets, so the hint is unreachable on my corpus by design — I can't add a "confirmed against real palace" data point the way I had hoped. Left the review as tests-and-diff-only for that reason; no changes requested.
|
Hi, Both the CLI and API/MCP hint text tells users to run Severity: remediation recommended | Category: correctness How to fix: Interpolate palace_path in hint Agent prompt to fix - you can give this to your LLM of choice:
We noticed a couple of other issues in this PR as well - happy to share if helpful. Found by Qodo code review |
Address Qodo review on MemPalace#1081: the hint string contained a literal `<palace_path>` placeholder in both the CLI print and the API dict, even though `palace_path` is in scope at both sites. Use an f-string so the suggested `mempalace repair <path>` command is directly copy-pasteable. Also strengthens both positive tests in `TestHNSWRepairHint` to assert the interpolated path appears AND the literal `<palace_path>` placeholder does not — guards against the same mistake in future edits to the hint text. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
Fixed in 54029c7 — both hint strings now use an f-string to interpolate
@qodo-ai-reviewer yes please — go ahead and surface the others. |
jphein
left a comment
There was a problem hiding this comment.
Re-reviewed 54029c7 against the 2026-04-21 approval baseline.
The change is small (2 lines in searcher.py, strengthened tests in test_searcher.py): replaces the literal <palace_path> placeholder in both hint sites with f-string interpolation, so the suggested command is directly copy-pasteable. Both positive tests in TestHNSWRepairHint now assert both (a) the interpolated path appears and (b) the literal <palace_path> doesn't leak — good regression guard for future edits to the hint text.
No changes to the guard logic (where and "Error finding id" in str(e)) I approved earlier. Re-approving.
Summary
Fixes #1035. When a palace's HNSW index predates 1.0 (i.e. built under
chromadb0.6.x), a filtered search on 1.5.x raises an opaqueValueError: Error finding id .... The repair command already handlesthe actual upgrade (
mempalace repair), but users upgrading in placehave no way to discover that from the error alone.
This PR catches the exception in both query paths in
searcher.py,detects the specific signature (a
wherefilter was in play andthe exception message contains
"Error finding id"), and surfaces ahint pointing at
mempalace repairbefore re-raising (CLI) orreturning the error dict (API / MCP). The no-palace path already pairs
error+hintin the returned dict, so the API branch mirrors thatshape.
Changes
mempalace/searcher.py— detect-and-hint inside the existingexceptblocks insearch()(CLI) andsearch_memories()(API),guarded by
where and "Error finding id" in str(e)CHANGELOG.md— one-line entry under### Bug Fixesin the[Unreleased] — v3.3.0sectiontests/test_searcher.py::TestHNSWRepairHint— three focused tests:CLI positive, API positive, and a negative-guard test to ensure
unrelated failures don't get a misleading repair suggestion
All 1060 tests in the full suite pass.
ruff checkandruff format --checkboth clean on the touched files.Scope note for the maintainer
In the issue thread, #851 and #1016 were mentioned as related —
happy to be corrected, but my read is those address SQLite parameter
limits in
col.get()pagination, which is a different code path fromthe HNSW
col.query()failure this PR addresses. If you'd like thisto also cover the pagination path, I'm glad to extend the PR; I kept
it narrow since your earlier reply greenlit a ~5-line detect-and-hint
specifically against the 0.6.x→1.5.x HNSW failure.
Known related gap
The
mempalace repaircommand this hint points at currentlysegfaults on a sufficiently corrupt HNSW index —
repaircallscol.count()before doing any repair work, and that's the call thatcrashes on drift. That's tracked separately in #1108 (wiring
quarantine_stale_hnsw()from #1000 into the backend open path). Onpalaces where the index is merely stale (not corrupt enough to crash
count()),repairworks as intended and this hint is actionable;#1108 closes the remaining case.
Test plan
pytest tests/test_searcher.py -v— 24 passed (3 new)pytest -x— 1060 passedruff check mempalace/searcher.py tests/test_searcher.pyruff format --check mempalace/searcher.py tests/test_searcher.py