Skip to main content

PCA

SQL function: cuvs_pca

Official cuVS reference: C API

Principal-component analysis transform for dense vector rows.

Quickstart

The call below expects the registered relation input_vectors (the input role), passed as a parenthesized SELECT subquery. Substitute your own relations and column names.

SELECT id, pc_0, pc_1
FROM cuvs_pca(
input => (SELECT id, d0, d1 FROM input_vectors),
n_components => 2
)
ORDER BY row_ordinal;

Inputs

Each relation argument is a parenthesized SELECT subquery that the planner keeps as a real child; metadata validation resolves a registered table or view for the same role instead. See Vector Inputs for the relation identity rules and the ID, dense-vector type, null, finite-value, and runtime-dimension contract.

RoleRequiredValidation referenceDescription
inputyestableDense-vector rows consumed by this operation.

Vector element types

Element typeValid metrics
Float32Not applicable

Arguments and options

Scalar SQL arguments

ArgumentTypeRequiredDescription
n_componentsintegeryesNumber of principal-component columns emitted as pc_0 through pc_<n_components - 1>.
whitenbooleannoWhether the query-local transformed components are whitened.
solverenum ("cov_eig_dq", "cov_eig_jacobi")noCovariance eigensolver used for this fit-transform call.
tolnumbernoNon-negative eigensolver tolerance.
n_iterationsintegernoMaximum eigensolver iterations for this invocation.
flip_signs_based_on_ubooleannoWhether cuVS applies its U-based component-sign convention.

SQL value argument schemas

ArgumentRequiredLiteral shapeDefaultConstraintsDescription
flip_signs_based_on_unobooleanfalseWhether cuVS applies its U-based component-sign convention.
n_componentsyesintegerNo defaultminimum 1; maximum 2147483647Number of principal-component columns emitted as pc_0 through pc_<n_components - 1>.
n_iterationsnointeger15minimum 1; maximum 2147483647Maximum eigensolver iterations for this invocation.
solvernostring"cov_eig_dq"one of "cov_eig_dq", "cov_eig_jacobi"Covariance eigensolver used for this fit-transform call.
tolnonumber0minimum 0Non-negative eigensolver tolerance.
whitennobooleanfalseWhether the query-local transformed components are whitened.

Vector binding shapes

Each relation subquery must project a non-null id field followed by either one or more non-null feature fields of a supported element type (Float32) or one non-null list vector field named vector.

For wide vectors, the projection order defines the feature dimensions. A list vector relation must contain no feature field beside id and vector.

Output

ColumnTypeNullableDescription
row_ordinalUInt64noZero-based ordinal of the evaluated input row; it disambiguates duplicate IDs.
idsame_as_input.idnoLogical ID copied from the input relation.
pc_<index>Float32noOne transformed principal-component value; the field count is set by the literal n_components option. The output contains n_components such columns, pc_0 through pc_&lt;n_components - 1&gt;.

Concrete schemas are call-specific. Run gpu_validate_call against registered relations to inspect the output schema after the actual ID types and literal options are validated.

Limits

  • Validation resolves named tables or views and reads schemas only; it does not execute relation scans or GPU work.
  • Execution relation arguments require parenthesized subqueries; dry-run validation accepts registered named relations only.
  • Fits and transforms the evaluated input in one statement; it does not return a reusable transform, components, or explained-variance metadata.
  • The evaluated input needs at least two rows and two dimensions, and n_components must not exceed the evaluated dimension.
  • Component sign orientation is not a semantic label. The output schema changes with the literal n_components option.

To dry-run validate relation metadata, column types, and options without execution, see gpu_validate_call.