Snowflake Gen AI Functions · Topic 10 of 26
VECTOR_TRUNCATE, VECTOR_NORMALIZE and Vector Aggregates - SUM, MIN, MAX, AVG
Learn the vector manipulation and aggregate functions: shorten and normalize embeddings, and combine vectors per element with VECTOR_SUM, MIN, MAX and AVG.
- 4 min
VECTOR_TRUNCATE(vector, dimension)keeps the first elements; aliasVECTOR_TRUNC; result is not normalized.VECTOR_NORMALIZEgives unit length (L2) withFLOATelements.VECTOR_SUM,MIN,MAXandAVGare aggregates that work element by element.
What it is
Besides comparing vectors, Snowflake has functions that change one vector and functions that combine many vectors.
- Manipulation (scalar):
VECTOR_TRUNCATEshortens a vector, andVECTOR_NORMALIZErescales it to unit length. Each returns a new vector. - Aggregation:
VECTOR_SUM,VECTOR_MIN,VECTOR_MAXandVECTOR_AVGwork element by element across the vectors in a group, likeSUM,MIN,MAXandAVGdo for numbers.
How it works
VECTOR_TRUNCATE
VECTOR_TRUNCATE(<vector>, <dimension>)
It keeps the first dimension elements and discards the rest. It can also be called as VECTOR_TRUNC. The element type stays the same.
SELECT VECTOR_TRUNCATE([1, 2, 3]::VECTOR(INT, 3), 2); -- [1,2]
SELECT VECTOR_TRUNCATE(
AI_EMBED('snowflake-arctic-embed-m-v1.5', 'hello'), 256);
The documentation example shortens a 768 element embedding to 256 elements. Shorter vectors use less storage and compare faster, at the cost of some detail. The dimension must not exceed the vector's own dimension, or an error is raised. A NULL input gives NULL.
Truncated vectors are not normalized. If your similarity method needs unit length vectors, call VECTOR_NORMALIZE after truncating.
VECTOR_NORMALIZE
VECTOR_NORMALIZE(<vector>)
It normalizes the vector in L2 space, giving it a magnitude of 1. The return type is a VECTOR with FLOAT elements, even when the input has INT elements.
SELECT VECTOR_NORMALIZE([1, 2, 3]::VECTOR(INT, 3));
-- [0.267261, 0.534522, 0.801784]
Normalizing helps when you want ranking by direction only. After normalization, ranking by inner product and by cosine similarity agree. A NULL input gives NULL.
The aggregates
VECTOR_SUM(<vector_column>)
VECTOR_MIN(<vector_column>)
VECTOR_MAX(<vector_column>)
VECTOR_AVG(<vector_column>)
Each takes a column of VECTOR values that share one element type and dimension, and returns one vector.
| Function | Element result |
|---|---|
VECTOR_SUM | Sum of each position across the vectors; same element type and dimension as the input |
VECTOR_MIN | Smallest value at each position |
VECTOR_MAX | Largest value at each position |
VECTOR_AVG | Average at each position; always FLOAT elements |
NULL values are ignored, and if every value in the group is NULL the result is NULL.
SELECT category,
VECTOR_AVG(embedding) AS category_centroid
FROM doc_vectors
GROUP BY category;
A typical use is a centroid: the average embedding of a group of documents. You can then compare a new document against each centroid with VECTOR_COSINE_SIMILARITY to find the nearest category.
SELECT c.category,
VECTOR_COSINE_SIMILARITY(c.category_centroid, q.vec) AS sim
FROM centroids c, query_vec q
ORDER BY sim DESC LIMIT 1;
Quick comparison
| Function | Kind | Input | Output |
|---|---|---|---|
VECTOR_TRUNCATE | Scalar | One vector and a dimension | A shorter vector |
VECTOR_NORMALIZE | Scalar | One vector | A unit length FLOAT vector |
VECTOR_SUM, MIN, MAX, AVG | Aggregate | A column of vectors | One vector |
If a question describes "one representative vector per group", the answer is VECTOR_AVG with GROUP BY. If it describes "reduce storage by using fewer dimensions", the answer is VECTOR_TRUNCATE.
Putting the functions together
A common pipeline stores one embedding per chunk, then derives other vectors from it. You might truncate the embedding to save storage, normalize it so that inner product and cosine similarity rank rows the same way, and average the vectors of each category into a centroid.
Order matters. Truncate first and normalize after, because truncation changes the length of the vector. Aggregate functions follow the same GROUP BY rules as SUM and AVG, so every non aggregate column in the select list must be in the GROUP BY.
Precision
As with the other vector functions, results can lose some floating point precision, with a margin of error up to 1e-4.
Common mistakes
Expecting truncated vectors to be normalized. They are not; normalize afterward if needed.
Truncating to a larger dimension. The target dimension cannot exceed the input dimension.
Aggregating vectors of different dimensions. All vectors in the column must share element type and dimension.
Expecting VECTOR_AVG to keep INT elements. The output is always FLOAT.
Using AVG or SUM on a VECTOR column. Use the vector aggregate functions.
What to remember for the exam
VECTOR_TRUNCATE(vector, dimension)keeps the first elements; aliasVECTOR_TRUNC; result is not normalized.VECTOR_NORMALIZEgives unit length (L2) withFLOATelements.VECTOR_SUM,MIN,MAXandAVGare aggregates that work element by element.- Aggregates ignore
NULL; allNULLgivesNULL. VECTOR_AVGoutput is alwaysFLOAT.- Margin of error is up to 1e-4.
Check yourself
Which function reduces a 768 element embedding to 256 elements?
VECTOR_TRUNCATE(vector, 256).How do you build one average embedding per category?
Use
VECTOR_AVG(embedding)withGROUP BY category.Is a truncated vector normalized?
No; apply
VECTOR_NORMALIZEif unit length is needed.
Topic 10 of 26 in Snowflake Gen AI Functions
Test yourself on Snowflake Gen AI Functions
The full Snowflake GES-C02 question bank has 585 questions, with timed practice exams and an explanation for every answer.
This study guide is independent and is not affiliated with, endorsed by, or sponsored by Snowflake. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.