@@ -508,8 +508,9 @@ public AsyncIterator<ItemSlot> scan(@Nonnull final ReadTransaction readTransacti
508508 */
509509 @ SuppressWarnings ("checkstyle:MethodName" ) // method name introduced by paper
510510 @ Nonnull
511- private CompletableFuture <GreedyState > kNearestNeighborsSearch (@ Nonnull final ReadTransaction readTransaction ,
512- @ Nonnull final Vector <Half > queryVector ) {
511+ private CompletableFuture <SearchResult <NodeReference >> kNearestNeighborsSearch (@ Nonnull final ReadTransaction readTransaction ,
512+ final int efSearch ,
513+ @ Nonnull final Vector <Half > queryVector ) {
513514 return storageAdapter .fetchEntryNodeKey (readTransaction )
514515 .thenCompose (entryPointAndLayer -> {
515516 if (entryPointAndLayer == null ) {
@@ -521,7 +522,7 @@ private CompletableFuture<GreedyState> kNearestNeighborsSearch(@Nonnull final Re
521522 final var entryState = new GreedyState (entryPointAndLayer .getLayer (),
522523 entryPointAndLayer .getPrimaryKey (),
523524 Vector .comparativeDistance (metric , entryPointAndLayer .getVector (), queryVector ));
524- final AtomicReference <GreedyState > greedyResultReference =
525+ final AtomicReference <GreedyState > greedyStateReference =
525526 new AtomicReference <>(entryState );
526527
527528 if (entryPointAndLayer .getLayer () == 0 ) {
@@ -530,14 +531,22 @@ private CompletableFuture<GreedyState> kNearestNeighborsSearch(@Nonnull final Re
530531 }
531532
532533 return AsyncUtil .whileTrue (() -> {
533- final var greedyIn = greedyResultReference .get ();
534+ final var greedyIn = greedyStateReference .get ();
534535 return greedySearchLayer (readTransaction , greedyIn .toNodeReferenceWithDistance (),
535536 greedyIn .getLayer (), queryVector )
536537 .thenApply (greedyState -> {
537- greedyResultReference .set (greedyState );
538+ greedyStateReference .set (greedyState );
538539 return greedyState .getLayer () > 0 ;
539540 });
540- }, executor ).thenApply (ignored -> greedyResultReference .get ());
541+ }, executor ).thenApply (ignored -> greedyStateReference .get ());
542+ }).thenCompose (greedyState -> {
543+ if (greedyState == null ) {
544+ return CompletableFuture .completedFuture (null );
545+ }
546+
547+ return searchLayer (DataNode ::creator , readTransaction ,
548+ ImmutableList .of (greedyState .toNodeReferenceWithDistance ()), 0 , efSearch ,
549+ queryVector );
541550 });
542551 }
543552
0 commit comments