Skip to content

Declare HNSW index update must run after the node table write (part of #896 fix) - #80

Closed
adsharma wants to merge 1 commit into
mainfrom
fix-896-hnsw-update-order
Closed

Declare HNSW index update must run after the node table write (part of #896 fix)#80
adsharma wants to merge 1 commit into
mainfrom
fix-896-hnsw-update-order

Conversation

@adsharma

@adsharma adsharma commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Follow-up to #78 (merged).

Problem

The main-repo fix for LadybugDB/ladybug#896 reorders NodeTable::update() so indexes are updated around the table write. But the two index kinds have conflicting needs:

  • FTS delete_ re-tokenizes the document from the node table, so it needs the old value → must run before the row is written.
  • HNSW re-scans the updated node's embedding during re-insertion (e.g. shrinkForNode()), so it needs the new value → must run after.

Running all indexes on one side either crashes HNSW (stale NULL embedding) or corrupts FTS (FTS index is inconsistent: term ... missing during delete, as caught by CI on LadybugDB/ladybug#900).

Change

Add an Index::updateAfterTableWrite() virtual (default false, preserving existing behavior for all other index types) and return true for OnDiskHNSWIndex. NodeTable::update() (main repo) runs "before" indexes, applies the row write, then runs "after" indexes.

Testing

All FTS + vector extension e2e tests pass locally, plus 146 core update/set/index e2e tests.

Index::update implementations either need the OLD value from the node
table (FTS re-tokenizes the document being deleted) or the NEW value
(HNSW re-scans the updated node's embedding during re-insertion, e.g.
in shrinkForNode). Add updateAfterTableWrite() and return true for
OnDiskHNSWIndex so NodeTable::update() runs HNSW maintenance after the
row is written.

Part of the fix for LadybugDB/ladybug#896.
@adsharma

adsharma commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

Closing in favor of a self-contained fix in LadybugDB/ladybug#900: the update ordering is keyed on the serialized index type name in NodeTable::update(), so no Index API change (and no extensions-side change) is needed. The extensions CI builds against ladybug main, which cannot carry the new virtual until #900 lands — making this PR unbuildable in the meantime.

@adsharma adsharma closed this Sep 2, 2026
@adsharma
adsharma deleted the fix-896-hnsw-update-order branch September 2, 2026 19:27
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