Skip to content

refactor(core): index_sync module owns insert/remove/persist policy (operations.rs) - #1347

Merged
ajianaz merged 1 commit into
developfrom
refactor/index-sync-module
Oct 7, 2026
Merged

ajianaz merged 1 commit into
developfrom
refactor/index-sync-module

Conversation

@ajianaz

@ajianaz ajianaz commented Oct 7, 2026

Copy link
Copy Markdown
Collaborator

What

Step 1 of the index sync module (#1340, tracked in #1345).

  • New uteke-core/src/index_sync.rs: an IndexWriter seam (adapters: VectorIndex, plus a recording/failing fake in tests), one SyncPolicy (3 attempts, 200 ms), and a SyncOutcome that says what actually happened (insert_error, persist_error, missing). Entry points: upsert, remove_ids, persist.
  • Migrated every index call in operations.rs — remember, update_memory, forget, soft_forget, promote, bulk_forget_{by_tag,cold,all} (soft + hard) and delete_namespace — plus Uteke::add_to_index / remove_from_index in lib.rs. Direct index calls in operations.rs: 15 → 0.
  • Deleted the three inline copies of the 3×200 ms retry and persist_index_after_delete.
  • Callers keep their existing contract: forget and bulk deletes still return an error when the index cannot be persisted (the DB rows are gone), remember still reports embedding_written=false / vector_error, soft_forget/promote still only warn.

Why

~60 index call sites across 7 modules hand-sequenced store write → insert/remove → save with five different failure policies. A policy change (or a bug like the lock-timeout deletion fixed in #1320) had to be made in every copy. One module = one place to change, and a fake adapter lets the failure policy be tested without files or locks.

Behaviour changes (intended)

  • A dimension mismatch is deterministic: reported immediately instead of 3 × 200 ms retries holding the index write lock.
  • soft_forget / promote persist with the same retry as the other paths (they used a single attempt, promote ignored the error).
  • Error text for failed persistence after a delete is unified (<op>: database rows were changed, but the vector index could not be updated: …. Run uteke repair).

Testing

  • 9 new tests on the module with a fake adapter: clean path, transient insert retry, exhausted retries (no save), dimension mismatch not retried, empty embedding no-op, persist failure reported (in-memory index still correct), batch removal counts missing and saves once, delete result errors only when persisting failed, and the real VectorIndex.
  • cargo fmt --check, cargo clippy --workspace --all-targets clean; cargo test --workspace green (core 596); vecq-only core build green (594).
  • Not covered: end-to-end failure of the real index file during forget (exercised only through the fake adapter).

Not in this PR

The remaining 33 direct call sites (maintenance.rs 14, lib.rs 8 incl. document paths, consolidate.rs 4, edges.rs 4, import_export.rs 3) follow in the next PR; document upsert atomicity is #1341; debounced saves live behind this seam later.

Refs #1340

🤖 Generated with Claude Code

…operations.rs)

Introduce index_sync with an IndexWriter seam (VectorIndex + a recording/failing
fake in tests), one retry/persist policy and a SyncOutcome that reports what
landed. Migrate every index call in operations.rs (remember, update, forget,
soft_forget, promote, bulk_forget_*, delete_namespace) and the lib.rs
add_to_index/remove_from_index helpers. Removes three inline copies of the
3x200ms retry plus persist_index_after_delete, and stops retrying
deterministic dimension-mismatch errors.

Refs #1340

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@ajianaz ajianaz added enhancement New feature or request scope:core Core engine work labels Oct 7, 2026
@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown

🔍 Cora AI Code Review

✅ No issues found. Code looks good!


Review powered by cora-code · BYOK · MIT

@ajianaz
ajianaz merged commit 6e00da0 into develop Oct 7, 2026
15 checks passed
@ajianaz
ajianaz deleted the refactor/index-sync-module branch October 13, 2026 00:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request scope:core Core engine work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant