- Categories:
VECTOR_ AVG¶
Computes the element-wise average of vectors in an aggregate. Returns a vector where each element is the average of the corresponding elements across all input vectors. The output is always VECTOR(FLOAT, N) regardless of input type.
- See also:
VECTOR_SUM , VECTOR_MIN , VECTOR_MAX , AVG, Vector Embeddings
Syntax¶
Arguments¶
vector_columnA column containing VECTOR values. All vectors in the column must have the same element type and dimension.
Returns¶
Returns a VECTOR(FLOAT, N) value where N is the dimension of the input vectors. Each element in the result vector is the average of the corresponding elements across all input vectors.
Usage notes¶
- NULL values are ignored in the aggregation.
- If all values in the group are NULL, the function returns NULL.
- All input vectors in the column must have the same dimension and element type.
- The output is always VECTOR(FLOAT, N) regardless of the input’s type. For information on floating-point numbers in Snowflake, see Floating-point data types.
- Vector functions are optimized in a way that can reduce floating point precision. This function’s results have a margin of error up to
1e-4.
Examples¶
This example demonstrates computing the element-wise average of vectors:
This example shows scalar aggregation (no GROUP BY):
This example shows how integer vectors are converted to float output: