@@ -279,33 +279,35 @@ public static GraphIndexBuilder rescore(GraphIndexBuilder other, BuildScoreProvi
279279 other .parallelExecutor );
280280
281281 // Copy each node and its neighbors from the old graph to the new one
282- IntStream .range (0 , other .graph .getIdUpperBound ()).parallel ().forEach (i -> {
283- // Find the highest layer this node exists in
284- int maxLayer = -1 ;
285- for (int lvl = 0 ; lvl < other .graph .layers .size (); lvl ++) {
286- if (other .graph .getNeighbors (lvl , i ) == null ) {
287- break ;
282+ other .parallelExecutor .submit (() -> {
283+ IntStream .range (0 , other .graph .getIdUpperBound ()).parallel ().forEach (i -> {
284+ // Find the highest layer this node exists in
285+ int maxLayer = -1 ;
286+ for (int lvl = 0 ; lvl < other .graph .layers .size (); lvl ++) {
287+ if (other .graph .getNeighbors (lvl , i ) == null ) {
288+ break ;
289+ }
290+ maxLayer = lvl ;
291+ }
292+ if (maxLayer < 0 ) {
293+ return ;
288294 }
289- maxLayer = lvl ;
290- }
291- if (maxLayer < 0 ) {
292- return ;
293- }
294295
295- // Loop over 0..maxLayer, re-score neighbors for each layer
296- var sf = newProvider .searchProviderFor (i ).scoreFunction ();
297- for (int lvl = 0 ; lvl <= maxLayer ; lvl ++) {
298- var oldNeighbors = other .graph .getNeighbors (lvl , i );
299- // Copy edges, compute new scores
300- var newNeighbors = new NodeArray (oldNeighbors .size ());
301- for (var it = oldNeighbors .iterator (); it .hasNext ();) {
302- int neighbor = it .nextInt ();
303- // since we're using a different score provider, use insertSorted instead of addInOrder
304- newNeighbors .insertSorted (neighbor , sf .similarityTo (neighbor ));
296+ // Loop over 0..maxLayer, re-score neighbors for each layer
297+ var sf = newProvider .searchProviderFor (i ).scoreFunction ();
298+ for (int lvl = 0 ; lvl <= maxLayer ; lvl ++) {
299+ var oldNeighbors = other .graph .getNeighbors (lvl , i );
300+ // Copy edges, compute new scores
301+ var newNeighbors = new NodeArray (oldNeighbors .size ());
302+ for (var it = oldNeighbors .iterator (); it .hasNext ();) {
303+ int neighbor = it .nextInt ();
304+ // since we're using a different score provider, use insertSorted instead of addInOrder
305+ newNeighbors .insertSorted (neighbor , sf .similarityTo (neighbor ));
306+ }
307+ newBuilder .graph .addNode (lvl , i , newNeighbors );
305308 }
306- newBuilder .graph .addNode (lvl , i , newNeighbors );
307- }
308- });
309+ });
310+ }).join ();
309311
310312 // Set the entry node
311313 newBuilder .graph .updateEntryNode (other .graph .entry ());
0 commit comments