Skip to content

Commit cb89b84

Browse files
committed
Add buildVectorGraphNow API for LSMVectorIndex
1 parent bd034f5 commit cb89b84

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

engine/src/main/java/com/arcadedb/index/vector/LSMVectorIndex.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,37 @@ private void ensureGraphAvailable() {
712712
buildGraphFromScratch();
713713
}
714714

715+
/**
716+
* Build (or rebuild) the vector graph immediately instead of waiting for the next search-triggered lazy build.
717+
* Useful after bulk inserts/updates when callers want the graph to be ready right away.
718+
*/
719+
public void buildVectorGraphNow() {
720+
buildVectorGraphNow(null);
721+
}
722+
723+
/**
724+
* Build (or rebuild) the vector graph immediately with an optional progress callback.
725+
* This forces a full rebuild even if the mutation threshold has not been reached yet.
726+
*
727+
* @param graphCallback optional progress callback invoked during graph construction/persistence
728+
*/
729+
public void buildVectorGraphNow(final GraphBuildCallback graphCallback) {
730+
checkIsValid();
731+
732+
// Prevent concurrent graph rebuilds and signal callers to retry if the index is busy.
733+
if (!status.compareAndSet(INDEX_STATUS.AVAILABLE, INDEX_STATUS.UNAVAILABLE))
734+
throw new NeedRetryException("Vector index '" + indexName + "' is not available for rebuild");
735+
736+
try {
737+
// Force rebuild from on-disk pages, bypassing mutation thresholds and lazy-load behavior.
738+
graphState = GraphState.LOADING;
739+
mutationsSinceSerialize.set(0);
740+
buildGraphFromScratchWithRetry(graphCallback);
741+
} finally {
742+
status.set(INDEX_STATUS.AVAILABLE);
743+
}
744+
}
745+
715746
/**
716747
* Build graph from scratch by reading all active vectors and constructing the graph index.
717748
* After building, persists the graph to disk and transitions to IMMUTABLE state.

0 commit comments

Comments
 (0)