Skip to content

fix(vsearch): skip missing vec tables instead of aborting (#161)#164

Closed
J0nd1sk wants to merge 1 commit into
TSchonleber:mainfrom
J0nd1sk:fix/vsearch-skip-missing-vec-tables-161
Closed

fix(vsearch): skip missing vec tables instead of aborting (#161)#164
J0nd1sk wants to merge 1 commit into
TSchonleber:mainfrom
J0nd1sk:fix/vsearch-skip-missing-vec-tables-161

Conversation

@J0nd1sk

@J0nd1sk J0nd1sk commented Jun 29, 2026

Copy link
Copy Markdown

Closes #161.

Problem

cmd_vsearch defaults to tables = ["memories", "events", "context"] (_impl.py:8081), but vec_events / vec_context are never created or populated anywhere in the codebase. The inner _vsearch_table (_impl.py:8091) ran the MATCH query with no guard, so the first missing table raised OperationalError, 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 default brainctl vsearch <query> failed on any real brain.db (and the hint is wrong: init doesn't create those tables either).

Fix

Catch sqlite3.OperationalError for a missing table in _vsearch_table and return [] for that source, so vsearch returns hits from the tables that exist. Any other OperationalError re-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.py builds a full-schema DB (via the cli_db fixture) with a populated real vec_memories and no vec_events, then drives cmd_vsearch(tables="memories,events") and asserts it returns the memory hit with events == [] and never raises. Skips if the sqlite-vec dylib isn't available.

Verification

$ pytest tests/test_mcp_tools_vsearch.py tests/test_vsearch_missing_vec_table.py -q
14 passed

# end-to-end: default vsearch (memories,events,context) against a DB with only
# vec_memories present now returns memory hits instead of erroring.

`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>
@J0nd1sk J0nd1sk closed this by deleting the head repository Jun 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] vsearch aborts on a missing vec table instead of skipping it (vec_events/vec_context are never created)

1 participant