Categories:

Vector functions

VECTOR_TRUNCATE

Truncates a VECTOR to a smaller dimension.

This function can also be called through the alias VECTOR_TRUNC.

See also:

Vector Embeddings, VECTOR_NORMALIZE

Syntax

VECTOR_TRUNCATE( <vector>, <dimension> )
Copy

Arguments

vector

A single VECTOR value to truncate.

dimension

The number of elements that should be in the returned vector.

Returns

Returns a VECTOR value with the same values and types for the first dimension entries, with the remainder discarded.

Usage notes

  • Returns NULL when any input is NULL.

  • Using a dimension larger than the number of dimensions in the vector causes an error.

  • Truncated vectors are not normalized.

Examples

This example demonstrates truncating a 3-dimensional vector into a 2-dimensional vector:

SELECT VECTOR_TRUNCATE([1, 2, 3]::VECTOR(INT, 3), 2);
Copy
[1,2]

This example demonstrates truncating a vector produced by EMBED_TEXT_768 for the text “Analytical databases are typically column-oriented rather than row-oriented” with the snowflake-arctic-embed-m-v1.5 model from 768 elements to 256 elements:

SELECT VECTOR_TRUNCATE(
    SNOWFLAKE.CORTEX.EMBED_TEXT_768(
        'snowflake-arctic-embed-m-v1.5',
        'Analytical databases are typically column-oriented rather than row-oriented'
    ),
    256)
;
Copy