Keep the semantic vector scans on their keyset range when account is set, and drop their per-row copy probes #102
Labels
No labels
bug
enhancement
epic
needs-info
needs-triage
ready-for-agent
ready-for-human
svd:go
svd:hold
wontfix
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
dev/mail-mind-mcp#102
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Follow-up to #96, split at its architect gate (ruling R3).
Problem
#96 makes keyword and filter searches cheap with the v10
copy_keycolumn. The semantic path keeps its per-row probes:Store.vector_chunksandStore.attachment_vector_chunkstake their filters and the row shown from_vector_filters._vector_filtersadds_shown_idand aNOT EXISTScopy probe for every vector-bearing row.So semantic mode, hybrid mode and
similar_tostill run about one probe per vector-bearing row. On a mirror near the brute-force bound of ADR 0005 §8, which is about 200,000 vectors, that is one probe per row per query.To find out (decide at triage)
similar_toon thescripts/bench_search.pystore with vectors, before and after #96.copy_keywith its index can choose the representative once per query, before the scan, for example as a temporary set of shown ids. The scan would then join to that set instead of probing.Acceptance
Blocked by
Filed under: operator word "File a follow-up (Recommended)" sha256:7e1e5164212a
Agent Brief
Category: bug
Summary: An
accountfilter makes the semantic vector scans quadratic. Keep each scan on its keyset range, then replace the per-row copy probes with the #96copy_keycolumn if that measurably helps.Operator rulings (2026-11-01). Where this brief differs from the issue body, the brief holds.
Current behavior (measured 2026-11-01 on main
d0ee0f1, medians of 3):a, a copy of every twentieth in accountb, and a random 384-dimension vector per row. Scoring usedsemantic.top_kwith k = 25.embeddingsplus scoringStore.vector_chunks, no filterStore.vector_chunks,account="a"+m.account = ?in that scan's WHEREStore.vector_chunks,since=+accountset, SQLite drives the scan from the indexmessages_msgid (account, message_id)(EXPLAIN QUERY PLAN:SEARCH m USING INDEX messages_msgid (account=?), thenUSE TEMP B-TREE FOR ORDER BY). It does not use them.id > ?rowid range. So every 2048-row keyset page re-reads and re-sorts the whole account, about 100 pages for 200,000 rows. The other(account, …)indexes (messages_date,messages_from,messages_thread) can win the same way.Store.vector_chunksandStore.attachment_vector_chunksboth take their WHERE fromStore._vector_filters, which usesStore._filters. Semantic mode, hybrid mode andsimilar_toall go through these scans._vector_filtersadds_shown_idand aNOT EXISTScopy probe per vector-bearing row. That accounts for most of the gap between 169 ms and 642 ms. #96 adds the v10copy_keycolumn and leaves these probes to this issue (#96 gate ruling R3).Desired behavior:
m.idforvector_chunks, andae.rowidforattachment_vector_chunks. No filter may switch it to an(account, …)index.+on the filter's account term, only in those scans. Another: aCROSS JOINorder.Store._filtersitself keeps its current SQL, because keyword search and filter search want the account index.copy_key, not through per-row probes.vector_chunksscan drops by 20% or more against part 1 alone, and every semantic output stays the same. Otherwise drop it and record the numbers in the PR.scripts/bench_search.py(from #96) gains semantic cases: no filter,account=aandsince=. It uses random unit vectors and the plain scan as the floor, and needs no model.Key interfaces:
Store._vector_filters,Store.vector_chunks,Store.attachment_vector_chunksandStore._filtersinsrc/imap_mailmind_mcp/store.py.copy_keycolumn and themessages_copy_keyindex from #96.Acceptance criteria:
EXPLAIN QUERY PLANof both vector scans withaccountset: the outer table is searched by its keyset range (rowid), and not by an(account, …)index.vector_chunkswithaccount="a"costs at most 1.2 times the unfiltered scan. Put the numbers in the PR.similar_toresults are byte-for-byte the same as on main, with copies, filters and attachment chunks. Add an equivalence test.tests/test_source.pypasses: there is no mail-server call inserver.py.make checkpasses.Out of scope:
sqlite-vec, which ADR 0005 §8 calls a new decision.Blocked by
Make the semantic scans use the copy_key column instead of per-row copy probesto Keep the semantic vector scans on their keyset range when account is set, and drop their per-row copy probes⏸ SVD architect gate: dev/imap-mailmind-mcp#102 keep-the-semantic-vector-scans-on-their-keyset-range-when-ac
Status: CLEAN after 0 rework round(s) · 0 blocking defect(s) · 0 lens(es) INCONCLUSIVE (could not run) · 0 lens(es) DEGRADED (deterministic denial) · complexity
standard· dispatch effortmediumRun:
20261101T202518Z-5014d0eeHeld because: CLEAN but 3 open risk(s) (2 verification · 1 decision) — HOLD-ALL parks everything. The risks, verbatim:
Open risks:
uv run python scripts/bench_search.py --semanticoutput showing vector account=a at most 1.2x vector none at commit A. For Part 2 it must show vector none(B) at most 0.8x vector none(A); otherwise commit B is reverted and both numbers are recorded. [verification]Change: Land two commits. Commit A (Part 1): add a keyword-only
keyset=Falseparameter toStore._filters(store.py:1393-1444). When it is true, the account term becomes+{alias}.account = ?. Only_vector_filters(store.py:1625-1635) passeskeyset=True, and only for its outermterms. Every other caller keeps its SQL byte-for-byte. A probe this session showed+restoresSEARCH m USING INTEGER PRIMARY KEY (rowid>?)andSEARCH ae … (rowid>?)for every account filter set. Commit A also gives scripts/bench_search.py a--semanticflag (random unit vectors, a plain embeddings keyset scan as the floor, cases none, account=a and since=) and adds tests/test_vector_scans.py. Commit B (Part 2, conditional): mirror_collapse_ctes'cand/dup/ranked(store.py:1465-1508) in a once-per-scan_vector_copieshelper. It returnsshown_of(first vector-bearing copy → rn=1 representative),hidden(other vector-bearing copies) and ahighid bound. The scans drop_shown_idand the NOT EXISTS probe, filter and label rows in Python, move the cursor on the last raw row, never yield an empty chunk (best_k reshape at semantic.py:38) and bound bym.id <= high. Keep commit B only if unfilteredvector_chunksis at most 0.8× commit A on the bench. Otherwise revert it and record both numbers in the PR.Files:
src/imap_mailmind_mcp/store.py·scripts/bench_search.py·tests/test_vector_scans.py·README.mdDecision: accept the 3 open risk(s) above and dispatch this spec (
svd:go), or park (svd:skip) / re-spec (svd:respec)?Your call (when this issue is held at the gate via
svd:hold):svd:go— approve; Half-B dispatch accepts exactly this spec (open risks accepted)svd:firebesidesvd:go— approve AND authorise the Half-B fire from the phone; never on its ownsvd:skip— park it; dispatch refuses it and the issue stays for a humansvd:respec— discard this spec; the next Half-A run re-produces it with this record as prior-attempt contextSpec:
/Users/piers/.local/state/exhaust/groupthink/specs/2026-11-01-keep-the-semantic-vector-scans-on-their-keyset-range-when-ac.md— next:codex-svd dispatch --args '<same-json>' --approved-spec-path /Users/piers/.local/state/exhaust/groupthink/specs/2026-11-01-keep-the-semantic-vector-scans-on-their-keyset-range-when-ac.mdspec-verify-dispatch Half B for dev/imap-mailmind-mcp#102 keep-the-semantic-vector-scans-on-their-keyset-range-when-ac completed integration verify.
0003f3ea320003f3e: absent0003f3e(the statuses list is empty, so the row is absent). Local make check is green with 754 passed. The spec's fast-verify suite is green with 382 passed.0003f3e: The Forgejo statuses API returns an empty list for the PR head; the repo has no CI files (CLAUDE.md: .woodpecker is added by the architect). No tracking pointer exists. — reported as absent, not blocking (gh#633)codex-svd ship --run-id 20261101T203624Z-3057ed21 --confirm-merge)