Skip to contents

umap() is a small convenience wrapper. If data is already a list of KNN indices and distances, it calls umap_knn() directly. Otherwise it preprocesses the data, computes KNN once with the selected backend, and embeds from that KNN graph.

Usage

umap(
  data,
  n_neighbors = NULL,
  n_components = 2L,
  standardize = FALSE,
  pca_dims = NULL,
  metric = c("euclidean", "cosine", "correlation"),
  nn = NULL,
  seed = 4L,
  backend = NULL,
  n.cores = NULL,
  keep_knn = FALSE,
  graph_mode = c("fuzzy", "binary"),
  verbose = FALSE,
  landmarks = FALSE,
  transform_k = NULL,
  massive = "off",
  output = NULL,
  chunk_rows = NULL,
  memory_limit = "available",
  refinement_epochs = 0L,
  local_refine = FALSE,
  local_neighbors = 15L,
  overlap_rows = 500L,
  devices = NULL,
  landmark_method = "reservoir",
  init = NULL,
  layout_storage = "memory",
  checkpoint = FALSE,
  resume = FALSE,
  cpu_update = "sgd",
  ef_search = 0L,
  storage = NULL,
  target_recall = NULL
)

Arguments

data

Numeric matrix/data frame, float::float32 matrix, massive_matrix() descriptor, prepared file-backed fuzzy graph, or a list containing KNN indices and distances.

n_neighbors

Number of non-self neighbors. NULL chooses the package default for the data size.

n_components

Output dimensionality. The CPU backend supports positive dimensions. Metal and CUDA support two- and three-dimensional embeddings.

standardize

Center and scale columns before KNN when data is a matrix. Defaults to FALSE so one-call results match a KNN object computed from the supplied matrix.

pca_dims

Optional PCA dimension before KNN.

metric

KNN distance metric for one-call matrix input: "euclidean", "cosine", or "correlation".

nn

Optional precomputed KNN result for resident matrix input, with one row per observation. By default all non-self neighbors are used. Explicit n_neighbors selects the first requested host KNN columns and must not exceed the available width. GPU-resident KNN requires an exact width match. In EXPERIMENTAL massive = "landmark" mode, a previous massive landmark embedding reuses its saved selection and query-to-landmark KNN. Its source, reference, neighbor count, and backend must match.

seed

Random seed.

backend

Execution backend: "cpu", "cuda", or "metal". CPU KNN uses faissR Flat exact search below 5,000 rows, FAISS HNSW for larger Euclidean searches, and faissR HNSW for other supported metrics. For Metal and CUDA, faissR selects native Flat or IVF-Flat as described in precompute_knn(). Resident CUDA fits can request multiple devices. Resident 2D Metal fits with at least 100,000 rows and integer CSR offsets optimize a compact edge list on Metal for all epochs. Smaller 2D fits with ordinary CSR rows use one CPU thread for the first half of the epochs, then Metal for the remaining epochs. Stage counts are recorded in fit$parameters. Resident 3D Metal UMAP runs its optimizer on Metal. Other GPU requests must resolve to a native backend; the package does not relabel CPU work as GPU. File-backed full-graph Metal UMAP runs its main optimizer on Metal, followed by a bounded one-thread CPU refinement: 25 epochs in 2D or 50 epochs in 3D. Both stages and their times are recorded in the fit. Its one-call file-backed route prepares neighbors with faissR's native Metal search. fit$pipeline$stage_backend and knn_method record the KNN and optimizer stages separately.

n.cores

Requested CPU core count. For matrix input, the value is passed to CPU PCA preprocessing, KNN, and UMAP. UMAP accepts up to 32 workers and records both requested and configured values; individual stages may use fewer workers when their inputs are small. With NULL, PCA uses options(n.cores) (one by default); KNN and UMAP use their stage defaults. The ordered CPU warm-up, when used by a 2D Metal fit, uses one thread. Native GPU stages ignore this argument.

keep_knn

Keep KNN matrices or file-backed KNN files in the returned pipeline. One-call file-backed fits release KNN files after graph construction when this is FALSE.

graph_mode

Graph weighting mode. "fuzzy" (the default) uses the standard UMAP fuzzy graph. "binary" uses a symmetric unit-weight graph as an adjacency-only sensitivity approximation; it is not standard UMAP or necessarily faster.

verbose

Print progress.

landmarks

FALSE (the default) embeds all observations. A fraction in (0, 1), a positive landmark count, or explicit row indices enables landmark embedding followed by fixed-reference projection of the remaining rows. File-backed landmark mode currently accepts a count only; fractions and explicit row indices require resident input.

transform_k

Number of landmark neighbors used to project non-landmark observations. Used only when landmarks enables landmarking and defaults to n_neighbors.

massive

"off" (default), experimental "landmark", or "out_of_core_graph". When omitted, a prepared file-backed graph selects full-graph mode; a file-backed matrix selects a full fit unless landmarks are supplied. A prepared graph needs file-backed init. Build the graph with massive_umap_fuzzy_graph(). The experimental CUDA full-graph route requires a device-resident 2D layout.

output

New .f32 path for experimental file-backed coordinates. A one-call full fit writes KNN, fuzzy graph, and spectral initialization. Initialization has separate timing and backend records. On a single CUDA GPU, it caches the graph when the graph and the spectral workspace fit the budgets. Larger graphs use streamed CPU initialization.

chunk_rows

Maximum experimental query rows per batch.

memory_limit

Conservative experimental RAM budget. When omitted for file-backed input, uses options(memory_limit = ...), or detected available RAM.

refinement_epochs

Fixed-reference UMAP projection epochs. In resident landmark mode, the default is 50 and an explicit zero disables refinement. In experimental file-backed mode, the default is zero on CPU and CUDA; CUDA currently rejects positive values.

local_refine

Enable EXPERIMENTAL bounded query-to-query graph refinement in massive landmark mode. Requires CPU and positive epochs.

local_neighbors

Non-self neighbors in each local query window.

overlap_rows

Extra rows on each side of a local query window; at least local_neighbors.

devices

Optional CUDA device indices. In resident full-data mode, eligible Euclidean self-KNN with multiple CUDA devices uses faissR CAGRA reference shards and returns host neighbors. Other eligible shapes use the existing FAISS GPU Flat or IVF routes. In experimental landmark mode, devices distribute query projection while reference fitting and KNN use the first device. Resident landmark mode coordinates the reference fit and shards query projection across the selected devices. Query KNN is materialized in host RAM before sharding. Sharded refinement samples negative examples from the fixed reference rows.

landmark_method

Sampling method for experimental landmark mode: "reservoir" (default) or "random" for fast random-access storage. Auto mode uses ordinary UMAP when its conservative memory estimate fits; otherwise it reports and runs approximate landmark UMAP. The landmark route requires a file-backed massive_matrix() and a new .f32 output.

init

File-backed 2D or 3D initial coordinates for experimental full-graph UMAP. Other routes do not accept this argument.

layout_storage

"memory" (default), "mmap" for a writable CPU mapping, or "managed" for CUDA managed-memory coordinates in experimental full-graph UMAP. CUDA rejects "mmap".

checkpoint

Save file-backed workflow stages and completed batches. Resident fits, including wide CSR fits, cannot checkpoint or resume. An interrupted resident fit must restart from the beginning. A one-call file-backed fit records source-identified stages and uses the restartable global graph sort, which needs more SSD space than the default bucketed sort.

resume

Continue a matching interrupted file-backed workflow. Changed input, backend, or fit controls fail without recomputation. One-call recovery requires a committed stage or native checkpoint; an incomplete stage with no valid checkpoint fails closed, except that an incomplete owned spectral output is rebuilt from the verified graph. Reusing a prepared resident graph starts a new fit; it does not resume completed optimizer epochs.

cpu_update

"sgd" (default) uses ordered single-worker updates. "synchronized" enables deterministic multicore CPU updates for full-graph UMAP. Other modes and backends reject this choice.

CPU HNSW search effort for experimental massive landmark UMAP. Zero uses the faissR preset. A positive value requires CPU HNSW and does not guarantee recall; audit the resulting graph separately.

storage

"auto", "resident", or "file_backed". When omitted, uses options(storage = ...). Explicit "resident" on a massive_matrix() file descriptor loads float32 input after a RAM and memory_limit check; the limit does not bound the subsequent fit.

target_recall

Requested KNN tuning tier: 0.9, 0.95, or 0.99. NULL uses options(fastEmbedR.target_recall = ...), then 0.99. Non-default tiers require resident or full file-backed input without landmarks or supplied KNN. An exact KNN route remains exact.

Value

Resident fits return a fastEmbedR_embedding; landmark fits also contain model for project_landmark_model(). File-backed full fits return a massive_matrix() descriptor with output and stage metadata. File-backed landmark projection may return a fastEmbedR_massive_projection. Use massive_read_rows() to inspect bounded output rows without loading the full result.

Details

umap() is an opinionated high-throughput UMAP implementation rather than a drop-in interface for every UMAP hyperparameter. The public matrix-input API exposes neighborhood size, distance metric, graph weighting, output dimension, preprocessing, backend, seed, and CPU thread count. In the current release, epochs, minimum distance, spread, learning rate, repulsion strength, negative-sample rate, spectral iteration count, and asynchronous update mode are selected internally. The resolved values and rule names are stored in fit$parameters.

The default policy uses 500 epochs below 10,000 observations and 200 epochs for larger inputs, increasing to 300 for high-variability distance profiles; five negative samples, spread 1, and repulsion strength 1 are fixed. Minimum distance is normally 0.01 and becomes 0.1 only under the documented wide-shell profile; learning rate is correspondingly 1 or 1.25. Use umap_init() to precompute and reuse package-native initial coordinates, or umap_knn() to supply an externally controlled KNN graph. These controls are scientifically consequential; fixing them is a scope decision made to keep one tested objective and update schedule aligned across CPU, Metal, and CUDA. Their update order can differ. These settings are not a claim that the values are universally optimal. Arbitrary min_dist, spread, epoch, learning-rate, negative-sampling, or optimizer-mode sweeps should use a general-purpose UMAP implementation; fastEmbedR does not claim API or parameter interchangeability with those packages.

Landmark mode fits the requested fuzzy or binary UMAP graph on the landmark rows, projects the remaining rows with query-to-reference KNN, and optionally refines only projected rows while landmark coordinates remain fixed. CUDA and Metal landmark refinement support 2D or 3D output. Resident precomputed KNN input cannot be combined with landmarking. The returned model retains the fitted preprocessing transform so new data can be supplied in the same original feature space.

Examples

x <- scale(as.matrix(iris[, 1:4]))
fit <- umap(x, n_neighbors = 15, seed = 1)
plot(fit)