fix(search): recover from Chroma ID lookup divergence - #1463
Conversation
When Chroma metadata gets ahead of its HNSW segment, MCP search can fail even though the SQLite-backed lexical path can still answer scoped queries. Route that transient drawer-query failure through the existing BM25 SQLite fallback and log lower-risk closet/neighbor divergence as ranking degradation. Tested: uv run pytest tests/test_searcher.py -v; uv run pytest tests/test_mcp_server.py::TestSearchTool::test_search_retries_once_on_hnsw_flush_transient tests/test_mcp_server.py::TestSearchTool::test_search_returns_second_error_if_retry_also_fails -v; uv run ruff check .; uv run ruff format --check mempalace/searcher.py tests/test_searcher.py Co-authored-by: OmX <omx@oh-my-codex.dev>
There was a problem hiding this comment.
Code Review
This pull request introduces a mechanism to handle transient Chroma ID lookup errors by falling back to BM25 search via SQLite. It adds helper functions to detect these errors, perform recovery, and provide conditional logging, refactoring the search_memories function to be more resilient. New tests verify the recovery logic and ensure that failures in specific search components do not cause the entire search to fail. Feedback was provided regarding the fragility of the _log_chroma_id_lookup_or_debug helper's string formatting requirements.
|
+1. This is the narrow case of the same architectural move as #1005 (when vector underdelivers, fall through to sqlite BM25) — bounded to Operator-experience data point: on a ~160K-drawer production palace this week we've been working through HNSW degradation cases including a capacity-divergence event. The exception-vs-empty-result split between this PR and #1005 means narrow catches don't fight broader catches — if Graceful degrade for closet/neighbor lookups with the log surface is also the right call — those layers are enrichment, not primary signal. A partially-ranked result with a logged warning beats a hard failure. Thanks for the fallback semantics. |
What does this PR do?
Fixes #1398.
When Chroma raises
Error finding idduring MCP search, the drawer search now falls back to the existing SQLite BM25 path instead of returning an error. Closet and neighbor lookups with the same error degrade gracefully to the drawer/base result and log the reduced ranking quality.How to test
uv run python -m pytest tests/ -vuv run pytest tests/test_searcher.py -vuv run pytest tests/test_mcp_server.py::TestSearchTool::test_search_retries_once_on_hnsw_flush_transient tests/test_mcp_server.py::TestSearchTool::test_search_returns_second_error_if_retry_also_fails -vuv run ruff check .uv run ruff format --check mempalace/searcher.py tests/test_searcher.pyChecklist
python -m pytest tests/ -v)ruff check .)