fix(searcher): use filter-fallback in CLI search path for HNSW drift (#1665) - #1750
fix(searcher): use filter-fallback in CLI search path for HNSW drift (#1665)#1750rodboev wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the search mechanism in mempalace/searcher.py to use a fallback query function (_query_drawers_with_filter_fallback) when a filtered query fails, allowing it to fall back to an unfiltered query and post-filter the results in Python. A corresponding unit test has been added in tests/test_searcher.py to verify this behavior. I have no feedback to provide as there are no review comments.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
|
The fix works, but check the #1665 thread before review: four open PRs already cover this same failure (#1005 delegates CLI search to |
|
@rodboev Just one request, please verify problem/fix by actually running MemPalace, rather than reviewing the code theoretically. |
|
Ran it locally against a small test palace. CLI search works fine with and without wing filters on a healthy index. The tricky part is reproducing the actual drift scenario from #1665, since it requires orphaned HNSW IDs left behind after a bulk delete. The fix itself is straightforward routing: |
|
Withdrawing this PR. The batch had serious quality problems, as you rightly pointed out. I genuinely did not see the issues and apologize for that. Closing everything and going back to the drawing board. Sorry for the noise. |
Summary
search()(CLI path) andsearch_memories()(MCP/API path) diverged in their handling of filtered HNSW failures.search_memoriesalready routes through_query_drawers_with_filter_fallback(added for #1245/#1035), which retries unfiltered and post-filters in Python when ChromaDB raisesError finding idon awhere=-scoped query.search()did not — itsexcept Exceptionblock atsearcher.py:381caught the error and re-raised asSearchError, so wing-filtered CLI searches failed with a cryptic message while the equivalent MCP call recovered cleanly.The fix routes
search()through the same helper, making CLI and MCP behavior consistent. No new infrastructure: the helper already handles the unfiltered-retry, Python post-filter, and warning log.Fix
Replace the inline
col.query(**kwargs)call insearch()(searcher.py:379) with_query_drawers_with_filter_fallback(col, kwargs, query, n_results, wing, room). The helper signature accepts the same kwargs dict and the existing wing/room locals, so no refactoring is needed around the call site.Add a regression in
tests/test_searcher.py: mock a collection whosequeryraises only whenwhere=is present, callsearch()with a wing filter, assert noSearchErroris raised and results are returned.Related work
Open PRs #951, #1005, #1463, and #1598 address overlapping search-fallback surfaces. This PR is the narrowest fix: it routes the CLI
search()path through the existing_query_drawers_with_filter_fallbackhelper thatsearch_memories()already uses. #1005 and #1598 both subsume this change as part of broader scope; if either lands first, this PR is redundant.Test plan
python -m pytest tests/test_searcher.py -v— 31 passedruff check .— cleanruff format --check .— clean