Skip to content

N2: FTS-first retrieval candidate generation (retire 5k scan cap) - #56

Merged
aspotton merged 7 commits into
mainfrom
feat/n2-fts-first-candidates
Oct 12, 2026
Merged

aspotton merged 7 commits into
mainfrom
feat/n2-fts-first-candidates

Conversation

@aspotton

Copy link
Copy Markdown
Owner

TL;DR: Retrieval previously scanned every active memory (up to a 5k cap) per request. This branch adds an opt-out-able candidate-union fast path: five SQL arms (lexical content, topic slug, FTS join, high-authority rows, long-row/phrase-window backstop) with a future N7 eligibility predicate seam, a batched row loader (kills per-memory N+1 fetches), and a watermark-invalidated embedding-matrix cache — with a byte-identical-score parity test gate and a config kill switch.

Ideal-state fidelity (verified 1:1 by the F-wave; F1-F4 all APPROVE):

IS Delivered by Proof
IS-1 T3/T4/T5 Batched loader serves BOTH modes; vector cache behind its own watermark — no per-request blob fetch. Honest headline: on our live qwen3-embedding store the fast path mostly falls back (semantic-arm cosines saturate the union); the guaranteed wins are the loader batching + vector cache in both modes. Sublinear gains are lexical-dominant-store dependent.
IS-2 T1/T3/T4 WARNING at the 5k scan cap; arms return None on saturation; fallback warning once per (reason, watermark).
IS-3 T2/T4/T7 Parity property matrix: fast path == verbatim full-scan, exact ids+scores (embeddings on/off, threshold 1 vs huge); corpus 15/15 BOTH modes.
IS-4 T3/T4 Paraphrase / topic-glued / tab / near-dup / high-authority / >8192 crafted counterexamples in the parity gate.
IS-5 T4 Relevance floor unchanged; existing gate tests unmodified green at default 500.
IS-6 T7 memory.full_scan_threshold default 500; huge value = kill switch (documented).
IS-7 T3 extra_predicate_sql seam ANDed into every SQL arm (N7 drops in).
IS-8 T6 Startup embedding backfill with model-scoped heal; second-run no-op.

Probe results: Live store (read-only): 2213 actives, 55 non-ASCII-glued rows (documented completeness-boundary class), 0 rows >8192 chars. Fresh-store manual QA: short queries served mode=candidates non-degenerate on a 605-row store; degeneracy warning exactly once per watermark move; kill-switch boot returns byte-identical results on 20 sampled queries; cross-mode corpus 15/15.

Honest live-store note: this branch does NOT yet make retrieval sublinear on the production store — semantic-arm saturation degenerates the union there until the live-embeddings decision (roadmap N3) lands. It makes every store cheaper via the loader/cache wins and retires the silent 5k scan cap with a loud WARNING.

Verification: suite 513 passed; Final Wave F1 (compliance) / F2 (code quality) / F3 (live HTTP QA incl. live-box probes) / F4 (IS fidelity) all APPROVE, evidence in .omo/evidence/F{1..4}-n2-fts-first-candidates.log (local ledger).

Known follow-ups (not blocking, not in this PR): consolidation.py still does a per-pass whole-working-set embedding fetch (background path only); the semantic arm carries no N7 predicate yet (relevant when N7 lands); fallback memo set is unbounded across process lifetime by design.

@aspotton
aspotton merged commit 24fdefb into main Oct 12, 2026
1 check passed
@aspotton
aspotton deleted the feat/n2-fts-first-candidates branch October 12, 2026 17:45
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.

1 participant