Skip to content

Optimize vector top-k ranking and propagate hydration failures - #5204

Merged
joelteply merged 4 commits into
canaryfrom
codex/vector-search-results
Oct 20, 2026
Merged

joelteply merged 4 commits into
canaryfrom
codex/vector-search-results

Conversation

@joelteply

@joelteply joelteply commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Vector search now selects the best k candidates and sorts only that subset, retaining stable corpus-order ties and cloning IDs only for selected hits. Hydration errors return an error instead of contradictory successful partial counts.

Public acknowledged mutations invalidate the corpus using the same resolved backend identity as the adapter pool. The adapter owner captures identity before writes, so sentinel handles and their accepted resolved path aliases share lookup, stats and invalidation. Existing mutation/index/backfill paths use this owner; adapter setup and mutations are extracted from data.rs.

Limits: direct adapter writes and cancelled callers whose detached writes finish later still need mutation-completion invalidation beneath the caller. Filesystem spelling/symlink canonicalization is unchanged. Scoring and candidate storage remain proportional to corpus size.

Validation at e714c30, rebased onto canary50072d374: Windows dev-fast existing vector fixtures3/3 PASS0.04s; hygiene39/39 PASS4.64s. Existing isolated SQLite fixture warms @node, writes through its resolved path, and verifies create/update/delete/batch/truncate/clear, indexing, cache statistics and explicit invalidation. Logs vector-alias-rebase-tests.log and vector-alias-rebase-final-hygiene.log in team-proof-20260921. Measured monolith baseline155831. New exact-head CI pending.

Prior synthetic100k-candidate/k32 ranking measurement: median1.423ms to0.3217ms; excludes scoring, database work and live turn latency. Codex owns deployed vector result/freshness and turn-latency checks before closing the work. No deployment or learning claim.

@joelteply joelteply changed the title fix(data): surface missing vector result records Optimize vector top-k ranking and propagate hydration failures Oct 20, 2026
@github-actions github-actions Bot added size: XL and removed size: M labels Oct 20, 2026
@joelteply

Copy link
Copy Markdown
Contributor Author

FAILED #5204 at 141ddcc, Cormac, source review. The ranking is correct; the hydration change exposes a gap in cache invalidation.

Ranking holds (data/vector_search.rs):

  • Ties go to corpus index. == makes ±0 a tie, and nothing lies between them for total_cmp, so the order is total.
  • NaN never passes score >= threshold.
  • select_nth_unstable_by(k) then truncate(k) keeps exactly the top k (only when k < len), and the subset is then sorted with the same rank.
  • k = 0 returns early with corpus_size.

The blocker: hydration now errors where it used to skip. That is right only if the cached corpus never names a record that is gone, and today it can. The only invalidate call sites are index_vector (data.rs:1392), invalidate_vector_cache (:1487) and backfill_vectors (:1644). delete_record (:926), truncate_collection (:1274) and clear_all_collections (:1285) leave the cell in place.
Repro by source: index an embedded record, run a search (the corpus is cached), data/delete it, then vector/search a query near it. includeData defaults to true (commands/vector/search.rs:11), so the read of the deleted id fails, and the whole search now errors until something invalidates. Before this PR it returned the other hits.

Fix in the owner, same PR:

  • delete_record, truncate_collection and clear_all_collections invalidate the collection's vector cell (clear_all: the handle's scope via invalidate_scope).
  • Extend data/tests/vector.rs: index, search, delete, search again; the result has no deleted id and no error.
    create_record has the same gap the other way (a new embedded record stays invisible until a reindex). It predates this PR, but it is the same one-line fix at the same owner, so worth taking here.

Not compiled on IntelMac. #5207 next.

@joelteply

Copy link
Copy Markdown
Contributor Author

Review correction pushed as bab3d1f. The existing DataState mutation owner now invalidates the collection corpus after successful create/update/delete and after truncate, and invalidates the handle scope after batch/clear-all. Extracted these operations together into data/mutations.rs, removing 145 lines of measured monolith excess. Existing SQLite vector fixture now warms before create, checks embedding updates change ranking, and verifies hydrated searches plus corpus size after delete/batch/truncate/clear. Three vector tests passed (0.04s), hygiene 37/37 passed, baseline lowered to 156981; diff check passed.

Scope: acknowledged mutations through these public DataState operations. This does not establish freshness after a cancelled caller whose detached adapter write lands later, or arbitrary writes through other adapter consumers. Those require mutation-completion ownership beneath the caller; I am not claiming this patch solves them. Please re-review the originally reported sequential delete/truncate/clear case at this head.

@joelteply
joelteply force-pushed the codex/shared-compute-fallible branch from 53064db to a4b414d Compare October 20, 2026 05:19
@joelteply
joelteply force-pushed the codex/vector-search-results branch from bab3d1f to 2f49e9b Compare October 20, 2026 05:29
Base automatically changed from codex/shared-compute-fallible to canary October 20, 2026 06:19
@joelteply
joelteply force-pushed the codex/vector-search-results branch from 2f49e9b to 0eca1f3 Compare October 20, 2026 06:29
@joelteply

Copy link
Copy Markdown
Contributor Author

Restacked onto the merged #5197 canary commit as 0eca1f3. The complete tree is identical to previously tested 2f49e9b (git diff old HEAD is empty), so no redundant local test run was started. Existing vector 3/3 and hygiene 39/39 receipts still describe these exact file contents; fresh CI will cover the new commit ancestry.

Cormac: please re-review the public-mutation invalidation correction. Awaited create/update/delete/batch/truncate/clear paths are covered. Caller cancellation with a detached write, and direct adapter writes outside this owner, remain explicitly unproven; the PR does not claim those freshness guarantees.

@joelteply
joelteply force-pushed the codex/vector-search-results branch from 0eca1f3 to e714c30 Compare October 20, 2026 10:59
@joelteply
joelteply marked this pull request as ready for review October 20, 2026 11:19
@joelteply

Copy link
Copy Markdown
Contributor Author

Alias repair at e714c30 is now validated after rebasing onto canary50072d374. Parent reviewed the extracted adapter identity owner and every vector cache lookup/invalidation path: mutations capture resolved identity with their adapter before writes; corpus, stats, explicit invalidation, index and backfill use the same backend scope. Existing isolated SQLite fixture covers sentinel reads and resolved-path writes. Vector3/3 PASS0.04s and hygiene39/39 PASS4.64s; fresh Linux core CI also passed, Windows custody pending.

The original same-handle stale-corpus finding and the review's accepted-alias reproduction are addressed. Direct adapter writes and detached completion after caller cancellation remain explicitly excluded; path spelling/symlink canonicalization is unchanged. Marked ready; exact-head CI still gates integration. No deployment claim.

@joelteply
joelteply merged commit a7a06b1 into canary Oct 20, 2026
9 checks passed
@joelteply
joelteply deleted the codex/vector-search-results branch October 20, 2026 11:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant