Class Search

java.lang.Object
com.apple.foundationdb.async.hnsw.Search

@API(EXPERIMENTAL) public class Search extends Object
An implementation of the search operations of the hierarchical Navigable Small World (HNSW) algorithm for efficient approximate nearest neighbor (ANN) search.
  • Constructor Details

    • Search

      public Search(@Nonnull Locator locator)
      This constructor initializes a new search operations object with the necessary components for storage, execution, configuration, and event handling. All parameters are mandatory and must not be null.
      Parameters:
      locator - the Locator where the graph data is stored, which config to use, which executor to use, etc.
  • Method Details

    • getLocator

      @Nonnull public Locator getLocator()
    • getSubspace

      @Nonnull public Subspace getSubspace()
      Gets the subspace associated with this object.
      Returns:
      the non-null subspace
    • kNearestNeighborsSearch

      @Nonnull public CompletableFuture<List<? extends ResultEntry>> kNearestNeighborsSearch(@Nonnull ReadTransaction readTransaction, int k, int efSearch, boolean includeVectors, @Nonnull RealVector queryVector)
      Performs a search for the k-nearest neighbors for a given query vector.
      Parameters:
      readTransaction - the transaction to use for reading from the database
      k - the number of nearest neighbors to return
      efSearch - the size of the dynamic candidate list for the search. A larger value increases accuracy at the cost of performance.
      includeVectors - indicator if the caller would like the search to also include vectors in the result set
      queryVector - the vector to find the nearest neighbors for
      Returns:
      a CompletableFuture that will complete with a list of the k nearest neighbors, sorted by distance in ascending order.
    • kNearestNeighborsRingSearch

      @Nonnull public CompletableFuture<List<? extends ResultEntry>> kNearestNeighborsRingSearch(@Nonnull ReadTransaction readTransaction, int k, int efSearch, boolean includeVectors, @Nonnull RealVector queryVector, double radius)
      Performs a search for the k-nearest neighbors of a ring around a given query vector at a given radius.
      Parameters:
      readTransaction - the transaction to use for reading from the database
      k - the number of nearest neighbors to return
      efSearch - the size of the dynamic candidate list for the search. A larger value increases accuracy at the cost of performance.
      includeVectors - indicator if the caller would like the search to also include vectors in the result set
      queryVector - the vector to find the nearest neighbors for
      Returns:
      a CompletableFuture that will complete with a list of the k nearest neighbors, sorted by distance in ascending order.