NORMALIZE_L2()
Function description
The NORMALIZE_L2() function performs Euclidean normalization on the vector.
The L2 norm is the square root of the sum of squares of vector elements, so the purpose of L2 normalization is to make the length (or norm) of the vector to 1, which is usually called a unit vector. This normalization method is particularly useful in machine learning, especially when dealing with feature vectors, which can help standardize the scale of features, thereby improving the performance of the algorithm.
Function Syntax
> SELECT NORMALIZE_L2(vector_column) FROM tbl;
Example
drop table if exists vec_table;
create table vec_table(a int, b vecf32(3), c vecf64(3));
insert into vec_table values(1, "[1,2,3]", "[4,5,6]");
mysql> select * from vec_table;
+-------+--------------------------+
| a | b | c |
+-------+--------------------------+
| 1 | [1, 2, 3] | [4, 5, 6] |
+-------+--------------------------+
1 row in set (0.00 sec)
mysql> select normalize_l2(b) from vec_table;
+-------------------------------------------+
| normalize_l2(b) |
+-------------------------------------------+
| [0.26726124, 0.5345225, 0.80178374] |
+-------------------------------------------+
1 row in set (0.00 sec)