fix(vsearch): skip missing vec tables instead of aborting (#161)#164
Closed
J0nd1sk wants to merge 1 commit into
Closed
fix(vsearch): skip missing vec tables instead of aborting (#161)#164J0nd1sk wants to merge 1 commit into
J0nd1sk wants to merge 1 commit into
Conversation
`cmd_vsearch` defaults to searching `memories,events,context`, but
`vec_events` and `vec_context` are never created anywhere — nothing
indexes events/context into a vector table. The inner `_vsearch_table`
ran `SELECT ... FROM {vec_table} WHERE embedding MATCH ?` with no guard,
so the first missing table raised OperationalError and the CLI turned it
into "Database table missing", discarding results from `vec_memories`
(which exists and has hits). Default `brainctl vsearch <query>` was
therefore broken on any real brain.db.
Catch `OperationalError` for a missing table in `_vsearch_table` and
return an empty result for that source, so vsearch still returns hits
from the tables that exist. Other OperationalErrors re-raise unchanged.
(The deeper gap — events/context are advertised in the default table
set but never indexed — is noted in #161 for a separate change.)
Fixes #161
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #161.
Problem
cmd_vsearchdefaults totables = ["memories", "events", "context"](_impl.py:8081), butvec_events/vec_contextare never created or populated anywhere in the codebase. The inner_vsearch_table(_impl.py:8091) ran theMATCHquery with no guard, so the first missing table raisedOperationalError, which the CLI surfaced as:{"error": "Database table missing: no such table: vec_events", "hint": "Run 'brainctl init' ..."}— discarding results from
vec_memories, which exists and has hits. So the defaultbrainctl vsearch <query>failed on any real brain.db (and the hint is wrong:initdoesn't create those tables either).Fix
Catch
sqlite3.OperationalErrorfor a missing table in_vsearch_tableand return[]for that source, so vsearch returns hits from the tables that exist. Any otherOperationalErrorre-raises unchanged.This is the minimal correctness fix. The deeper question — events/context are in the default table set but nothing ever indexes them — is called out in #161 as a separate change (implement the indexing, or drop them from the default set). Happy to follow up on whichever you prefer.
Test
tests/test_vsearch_missing_vec_table.pybuilds a full-schema DB (via thecli_dbfixture) with a populated realvec_memoriesand novec_events, then drivescmd_vsearch(tables="memories,events")and asserts it returns the memory hit withevents == []and never raises. Skips if the sqlite-vec dylib isn't available.Verification