Repository navigation
fix(engine) #5747: do not rebuild a persisted HNSW graph on close - #5787
Merged
lvca merged 1 commit intoAug 5, 2026
Merged
Conversation
… close `LSMVectorIndex.flush()` rebuilds the graph when `graphState` is LOADING or MUTABLE. MUTABLE is correct: there are pending changes. LOADING is not, because LOADING means "not loaded into memory", which is not the same as "not persisted on disk". The graph is lazily loaded on the first search, so a session that only reads documents leaves the state at LOADING even when a complete graph is already on disk. Close then rebuilds it from scratch to produce a file that already exists. The cost is O(n log n) in the index size and lands on sessions that never touched the index. `initializeGraphIndex()` already draws exactly this distinction with `graphFile.hasPersistedGraph()`; this applies the same test in `flush()`. LOADING now rebuilds only when there is genuinely nothing on disk. Measured on one host, 64-dim COSINE index, 9 reps with 3 warmup, median: | vectors | session | close before | close after | |---|---|---|---| | 100k | reads a document | 6,197.79 ms | 4.34 ms | | 1M | reads a document | 216,068.3 ms | 13.2 ms | | 1M | runs a vector search | 14.1 ms | 16.3 ms | | 3M | reads a document | 1,006,000 ms | - | The third row is the safety check: sessions that do search the index already skipped the rebuild, and this change leaves them alone. At 3M the close was 1,006 s against an original build of 1,011 s, so the rebuild is a complete re-run of the build. Correctness checks beyond the new test: after adding 200 vectors to an existing index, closing and reopening, all 200 new and 200 pre-existing vectors are still found by search, on both the patched and unpatched build. The full com.arcadedb.index.vector suite (22 classes) passes. One behaviour change worth stating: if a session adds vectors and then crashes before close, the on-disk graph is stale and the state is LOADING. Today's unconditional rebuild repairs that incidentally; with this change the repair happens at the next search instead, via the existing staleness check in `ensureGraphAvailable()` (`graphSize < rebuiltOrdinalToVectorId.length`). So the repair moves from incidental to deliberate rather than disappearing. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Contributor
|
Tick the box to add this pull request to the merge queue (same as
|
Up to standards ✅🟢 Issues
|
Member
|
Thanks @tae898 ! |
tae898
added a commit
to humemai/arcadedb-embedded-python
that referenced
this pull request
Aug 11, 2026
Brings the fork up to 26.9.1-SNAPSHOT, which carries the August fixes we filed: ArcadeData#5711 (HTTP row truncation), ArcadeData#5745/ArcadeData#5788 (GAV), ArcadeData#5746 (Cypher through GAVFusedChain), ArcadeData#5747 (close-time HNSW rebuild, our PR ArcadeData#5787), ArcadeData#5796 (Redis port), ArcadeData#5824 (@Rid IN replanned as FETCH FROM RIDs). All verified against the shipped jars before this merge. Conflicts resolved: - 15 .github files kept deleted. Upstream CI the fork does not run; we carry only the five Python workflows. - test-python-examples.yml took upstream's two dependabot SHA bumps (setup-java v5.6.0 -> v5.7.0, cache v4.3.0 -> v6.1.0), staying aligned with the SHA-pinning their review requires. - test_server_wire_protocols.py kept ours. Upstream carries the version from PR ArcadeData#5807, which still has the redis xfail; ArcadeData#5796 is fixed and the marker was retired in a5d82c0. Behaviour changes to watch, none of which renamed or removed a JPype-facing API: ArcadeData#5969 now validates SQL function and method arity, ArcadeData#5908 makes sum/avg reject non-numeric input, ArcadeData#5983 bounds regex backtracking, and ArcadeData#5786 caps vector.neighbors groupBy output per index. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_0173qFfapQBiGxaV7apSZ4X8
tae898
added a commit
to humemai/arcadedb-embedded-python
that referenced
this pull request
Aug 19, 2026
…ebuild The fp32 embedded arm cannot complete a deep10m cell in a 24g heap on 26.8.1, under any graphBuildCacheSize or graphBuildCacheMaxHeapPercent setting we tried: 25/15/10/5% and a fixed 100k bound all failed. That uniformity is the clue. If the corpus cache were binding, a 1.2 GiB cache should not behave like a 5.36 GiB one. What every failing arm shares is that it CLOSES. Since ArcadeData#5747, LSMVectorIndex.flush() rebuilds the graph whenever graphState is LOADING, which means "not resident" rather than "not on disk", so a close constructs a second graph while the first index and its caches are still referenced. The evidence lines up: close_s tracks build_s on every dense embedded arm (5636 s against a 5550 s build at deep10m, 154 s at small), the one OutOfMemoryError was thrown INSIDE close(), the served arm is unaffected because its close() is a no-op that never touches the database, and the int8 arm survives because its quantized graph is small enough that two fit. The fix is ours, PR ArcadeData#5787 merged 08-05, and it is NOT in 26.8.1, which was tagged 08-03. No dev tag carries it either; it exists only on main. So this flag answers the question one cell can answer: skip the close and see whether the build ever needed the heap. The row records close_skipped and a reason, because a cell that silently omits a phase is not comparable with one that does not. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01E2Ytwsz6uQvs1dBoqGBSrV
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #5747.
LSMVectorIndex.flush()rebuilds the HNSW graph whengraphStateisLOADINGor
MUTABLE.MUTABLEis right: there are pending changes.LOADINGis not,because it means "not loaded into memory", which is not the same as "not
persisted on disk".
The graph loads lazily on the first search, so a session that only reads
documents leaves the state at
LOADINGeven when a complete graph is already ondisk, and close then rebuilds it from scratch to produce a file that already
exists.
initializeGraphIndex()already draws exactly this distinction withgraphFile.hasPersistedGraph(); this applies the same test inflush().Measured
One host, 64-dim COSINE, 9 reps with 3 warmup, median. Both arms are the same
harness on the same data; a classpath check confirms which jar each arm loaded.
The fifth row is the safety check. Sessions that do search already skipped the
rebuild, and this leaves them where they were.
At 3M the close was 1,006 s against an original build of 1,011 s, so the close
rebuild is a complete re-run of the build. The cost is also per index rather
than per database: with two indexes and only one queried, the untouched one
still cost 190 s on its own.
Correctness
VectorIndexNoRebuildOnUnusedCloseTestasserts the persisted graphis byte-identical and unmodified after a session that reads documents and
never searches. It fails on unpatched code and passes with the change.
reopening, all 200 new and all 200 pre-existing vectors are still found by
search, identically on patched and unpatched builds. The
MUTABLEbranchstill rebuilds as it should.
com.arcadedb.index.vectorsuite (22 classes) passes.One behaviour change worth stating
If a session adds vectors and then crashes before close, the on-disk graph is
stale and the state is
LOADING. The current unconditional rebuild repairs thatincidentally. With this change the repair happens at the next search instead,
through the staleness check already in
ensureGraphAvailable()(
graphSize < rebuiltOrdinalToVectorId.length, added for #3722). So the repairmoves from incidental to deliberate rather than disappearing, but it is a real
change and you may prefer a different call on it.
Happy to adjust the approach or add cases to the test.