Skip to content

fix(#7146): size the HNSW build cache from the heap ceiling so served matches embedded - #7147

Merged
lvca merged 2 commits into
ArcadeData:mainfrom
M-Tesla:fix-7146-graph-build-cache
Sep 4, 2026
Merged

lvca merged 2 commits into
ArcadeData:mainfrom
M-Tesla:fix-7146-graph-build-cache

Conversation

@M-Tesla

@M-Tesla M-Tesla commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #7146

What does this PR do?

graphBuildCacheMaxHeapPercent now takes its share of the JVM heap ceiling (-Xmx), then caps that at 90% of the heap currently available. A served ingest of the same corpus as an embedded build therefore gets the same cache at the default, instead of a third of it. The percent knob also applies to INT8/BINARY, and the INFO line is cache enabled: size=N of corpus.

Motivation

On DEEP-10M the same jars built in 190 to 198 min served against 38 to 42 min embedded, with identical recall. Pinning graphBuildCacheSize showed the two deployments are within 10% of each other at every matched cache capacity, so this is the default sizer, not the transport. The served arm had just ingested the corpus into the same heap, leftover was ~6.6 GB of 24 GB, and 25% of that leftover paid for 3.67 million of 9.99 million vectors. INT8 never read the percent knob at all: graphBuildCacheMaxHeapPercent=75 still chose 100,000.

Related issues

Additional Notes

The search cache is unchanged: it still budgets from leftover heap. Only the graph-build cache moves to percent-of-ceiling, because that is the working set whose size should be an operator policy of -Xmx, not of whatever happens to be live at the instant the build starts.

Checklist

  • I have run the build using mvn clean package command
  • My unit tests cover both failure and success scenarios

Targeted engine tests, all green: Issue7146GraphBuildCacheBudgetTest, LSMVectorIndexBuildCacheSizingTest, Issue6503VectorHeapBudgetTest, Issue6503RebuildAdmissionControlTest, LowRamProfileTest.

Summary by CodeRabbit

  • Bug Fixes

    • Improved vector index graph-build cache sizing for fp32, INT8, and BINARY indexes.
    • Caches can now accommodate the full vector corpus when within the configured heap budget.
    • Heap-based limits are consistently enforced and capped by currently available memory.
    • Reduced duplicate memory use during graph-build validation.
    • Improved logging to show cache capacity and vector count.
  • Tests

    • Added regression coverage for cache sizing across deployment modes, heap conditions, and percentage limits.

… so served matches embedded

graphBuildCacheMaxHeapPercent took a share of leftover heap, so a served ingest that
already held the corpus chose a third of the cache an embedded build of the same
corpus would get. Budget from -Xmx instead, cap at 90% of what is still free so
online rebuilds still shrink, apply the percent to INT8/BINARY, and log size=N of corpus.
@mergify

mergify Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity

Metric Results
Complexity 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@coderabbitai

coderabbitai Bot commented Sep 3, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Team

Run ID: 561a45ad-1f41-4c7c-9c72-39ddbaaef14b

📥 Commits

Reviewing files that changed from the base of the PR and between e9123ab and 318b6a5.

📒 Files selected for processing (4)
  • engine/src/main/java/com/arcadedb/index/vector/ArcadePageVectorValues.java
  • engine/src/main/java/com/arcadedb/index/vector/LSMVectorIndex.java
  • engine/src/test/java/com/arcadedb/index/vector/Issue7146GraphBuildCacheBudgetTest.java
  • engine/src/test/java/com/arcadedb/index/vector/LSMVectorIndexBuildCacheSizingTest.java

Included review availability: Your plan provides up to 8 included reviews per hour; 6 remain after this review.


📝 Walkthrough

Walkthrough

Graph-build cache sizing now uses a percentage of maximum heap, capped by 90% of available heap. The policy applies to document-backed and inline-quantized indexes. Graph builds reuse a warmed cache. Tests cover sizing, integration, and logging.

Changes

Vector graph-build cache budgeting

Layer / File(s) Summary
Heap budget calculation
engine/src/main/java/com/arcadedb/index/vector/VectorHeapBudget.java, engine/src/main/java/com/arcadedb/GlobalConfiguration.java
Graph-build budgets use the configured share of maximum heap, capped by 90% of available heap. Nonpositive percentages return zero, and percentages above 90 are clamped.
Graph-build cache integration
engine/src/main/java/com/arcadedb/index/vector/LSMVectorIndex.java, engine/src/main/java/com/arcadedb/index/vector/ArcadePageVectorValues.java
Document-backed and inline-quantized indexes use the shared budget. Validation warms VectorCache directly, and graph construction reuses the warmed cache. Logs include cache capacity and vector count.
Sizing and logging validation
engine/src/test/java/com/arcadedb/index/vector/Issue7146GraphBuildCacheBudgetTest.java, engine/src/test/java/com/arcadedb/index/vector/LSMVectorIndexBuildCacheSizingTest.java
Tests cover deployment budgets, heap caps, quantization modes, disabled budgeting, JVM bounds, and cache-capacity logging.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Merge Risk: ⚪ Minimal · up to 318b6

Graph-build cache sizing now consistently uses the JVM heap ceiling with an available-heap cap, including INT8/BINARY indexes, while preserving bounded cache warming and cache-capacity logging. No merge-blocking current-head risk remains.

Sequence Diagram(s)

sequenceDiagram
  participant LSMVectorIndex
  participant VectorHeapBudget
  participant JVM
  participant ArcadePageVectorValues
  LSMVectorIndex->>JVM: Release resident graph
  LSMVectorIndex->>VectorHeapBudget: Calculate cache budget
  VectorHeapBudget->>JVM: Read maximum and available heap
  JVM-->>VectorHeapBudget: Return heap measurements
  VectorHeapBudget-->>LSMVectorIndex: Return capped capacity
  LSMVectorIndex->>LSMVectorIndex: Warm VectorCache
  LSMVectorIndex->>ArcadePageVectorValues: Build graph with warmed cache
Loading

Suggested reviewers: robfrank

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 25 functions across 6 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: sizing the HNSW build cache from the JVM heap ceiling to align served and embedded deployments.
Description check ✅ Passed The description includes all required template sections and explains the motivation, implementation, related issue, scope, and test coverage. The build checklist item remains unchecked, but the descri…
Linked Issues check ✅ Passed The changes satisfy issue #7146 by sizing the graph-build cache from the heap ceiling, capping it by available heap, applying the percentage to INT8/BINARY indexes, and logging cache capacity with cor…
Out of Scope Changes check ✅ Passed The changes are within scope for issue #7146. Cache warming, removal of the temporary vector map, API adjustments, and regression tests directly support the requested cache-sizing and memory-use chang…
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@lvca

lvca commented Sep 4, 2026

Copy link
Copy Markdown
Member

@claude review this

@lvca
lvca self-requested a review September 4, 2026 14:50
@lvca lvca added this to the 26.10.1 milestone Sep 4, 2026
@claude

claude Bot commented Sep 4, 2026 •

Copy link
Copy Markdown

Claude finished @lvca's task in 2m 56s —— View job


Claude's review

  • Gather context (PR diff, related files)
  • Review VectorHeapBudget.java changes
  • Review LSMVectorIndex.java changes
  • Review GlobalConfiguration.java changes
  • Review new/updated tests
  • Post final review

Note: the sandbox in this session declined the approval prompt for every git fetch/mvn invocation (no interactive user to approve it), so I could not run the build or the targeted test suite myself. Everything below is from reading the diff (via git diff HEAD~1 HEAD on the checked-out branch) and the surrounding code; I'm relying on the PR author's report that the five targeted tests are green.

Summary

This is a tight, well-scoped fix. The core change: computeGraphBuildCacheCapacity() used to size the graph-build cache off VectorHeapBudget.budgetBytes() (percent of available heap) and short-circuited INT8/BINARY straight to the 100,000-entry flat default, ignoring the percent knob entirely. Now both paths go through the new VectorHeapBudget.buildCacheBudgetBytes(), which takes percent of -Xmx (the ceiling) and caps that at 90% of currently-available heap. That's exactly the served-vs-embedded discrepancy described in the PR body, and the git diff HEAD~1 HEAD confirms the if (inlineQuantization) return DEFAULT_CACHE_SIZE; short-circuit is genuinely gone, not just re-documented.

Correctness check on VectorHeapBudget.buildCacheBudgetBytes

static long buildCacheBudgetBytes(final int percent, final long maxHeap, final long availableHeap) {
  if (percent <= 0) return 0L;
  final int p = Math.min(percent, 90);
  final long fromCeiling = Math.max(0L, maxHeap) / 100 * p;
  final long fromAvailable = Math.max(0L, availableHeap) / 100 * 90;
  return Math.min(fromCeiling, fromAvailable);
}

I worked through the invariant the new buildCacheBudgetIsNeverSmallerThanTheAdmissionGateShareOfTheSameLeftover test asserts: since maxHeap >= availableHeap always, fromCeiling >= availableHeap * p / 100 == admission-gate share, and fromAvailable = availableHeap * 90/100 >= admission-gate share too (because 90 >= p). So min(fromCeiling, fromAvailable) >= admission share holds algebraically, not just for the sampled percents in the test loop. Good.

Note the fromAvailable cap is a fixed 90%, not min(percent, 90)%, of available heap — e.g. at percent=10 the cap is still 90% of leftover, not 10%. That matches the config Javadoc ("capped at 90% of the heap currently AVAILABLE") and the anOnlineRebuildWithLittleLeftoverStillCapsAtAvailableHeap test, so it's intentional, just worth flagging since it reads a little surprising next to the p used for the ceiling side.

Interaction with #6503 admission control

admitOnlineRebuild() (LSMVectorIndex.java:3981) calls computeGraphBuildCacheCapacity() to estimate the rebuild's peak heap, then compares against VectorHeapBudget.budgetBytes(percent) (still available-heap-based, unchanged). Since the build-cache capacity estimate can now be larger (ceiling-based, capped at 90% of available instead of heapPercent% of available), the admission gate becomes more conservative under heap pressure — which is correct, because the actual cache built during an online rebuild will now really claim up to that larger amount. This is internally consistent and lines up with the PR's claim that #6503 is preserved.

Tests

Issue7146GraphBuildCacheBudgetTest reconstructs the DEEP-10M numbers from the report (24 GiB -Xmx, 96-d, ~10M vectors) and pins both the old buggy formula (a third of the corpus on the served arm) and the new one (full corpus on both arms), plus the #6503 tight-leftover cap and the percent-clamping/live-JVM-consistency edges. LSMVectorIndexBuildCacheSizingTest was extended to check INT8 now tracks the same auto-sizing as fp32 instead of being pinned at 100,000, and that the new "cache enabled: size=N of M" log line fires. Good coverage of the boundary conditions; nothing obviously missing.

Minor/non-blocking observations

  • VectorHeapBudget.java:8397 Javadoc link {@link VectorHeapBudget#buildCacheBudgetBytes(int)} inside LSMVectorIndex — should resolve fine since the class is in the same package, just double check javadoc/-Xlint doesn't warn given VectorHeapBudget is package-private (final class VectorHeapBudget with no modifier) — low risk since it's already been building before this PR touched the same pattern elsewhere.
  • The affordable floor (Math.max(ArcadePageVectorValues.DEFAULT_CACHE_SIZE, heapBudget / bytesPerCachedVector)) means a graph build can still request at least 100,000 cache slots even when heap is extremely tight — but this is pre-existing behavior unchanged by this PR, not a regression it introduces.

No correctness issues found. I'd call this ready pending the author's own green test run and CI.

…nputs

Sizing the graph-build cache from the heap ceiling makes it scale with the
corpus rather than with whatever heap happened to be free, which is the point
of ArcadeData#7146 - but it also makes everything that scaled alongside the cache scale
with the corpus too.

The validation phase collected every vector it read into a
HashMap<Integer, VectorFloat<?>> and copied that into the build cache
afterwards, so both structures were live at the peak of the build: a boxed
key, a map node and a table slot per cached vector, about 50 bytes each, on
top of the cache entry that outlives them. That is ~500 MB on a ten-million
vector build, spent at the exact moment the graph itself is about to be
allocated, and it is not counted by bytesPerCachedVector() - so it was
already outside the budget that is supposed to bound the build, and the
bigger default now makes it proportional to the corpus. The cache is now
built up front and warmed in place, and the intermediate map is gone.
ArcadePageVectorValues gains a forGraphBuild() overload that takes the warmed
cache; putInCache(), which existed only for the copy loop, goes with it.

computeGraphBuildCacheCapacity() no longer reads its inlineQuantization
argument, since the percent knob now applies to INT8/BINARY as well, so the
argument is removed rather than left for a caller to believe in. How a miss
is resolved is a property of the reader, not of the capacity.

Two tests were pinned to figures that only hold on some machines. The live
JVM overload was compared against a second reading of availableHeapBytes()
taken in the test, which disagrees whenever a collection lands between the
two - regularly, in a full-suite run; it now asserts the invariant that
matters, the share of a ceiling that cannot move. And the "capped by the
heap budget" assertions became -Xmx-dependent when the denominator changed:
at 32 dimensions, 25% of the ceiling covers the 50M-vector probe on any host
with 154 GB of RAM or more, so the cap is now made to bind explicitly rather
than by luck. Adds a regression test that an INT8 build logs the same
"cache enabled: size=N of N" line a document-backed one does, which is the
form issue ArcadeData#7146 had to work backwards from.

Issue ArcadeData#7146
@lvca
lvca merged commit 8cb8495 into ArcadeData:main Sep 4, 2026
7 of 9 checks passed
@lvca

lvca commented Sep 4, 2026

Copy link
Copy Markdown
Member

Thanks @M-Tesla !

tae898 added a commit to humemai/arcadedb-embedded-python that referenced this pull request Sep 6, 2026
…che build check

PROBE_WAIT_REBUILD=1 (bounded mode) waits for asyncRebuildInProgress to clear
after the last step and takes one more timed pass, so a record shows the
ArcadeData#6858 bound landing rather than only firing. cache_default_10m_check.py builds
DEEP-10M once per precision at the default cache and records the engine's own
'cache enabled: size=M of N' line (ArcadeData#7146/ArcadeData#7147). Both are mechanism checks
for the qCQ verification on upstream main, not page rows.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01JB6Hg77dQVqABoTJmiUnV2
tae898 added a commit to humemai/arcadedb-embedded-python that referenced this pull request Sep 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants