Cloud SQL functions
This pages describes Cloud SQL functions.
Vector conversion functions
This following table lists the functions that you can use to manipulate vectorinformation in aSELECT statement.
| Function | Description | |
| vector_to_string | Input:VECTOR Output:STRING | Converts an argument to a string in a human-readable vector format. Input: one argument of type Output: a string Syntax:
|
| string_to_vector | Input:STRING Output:VECTOR | Converts a string to a human-readable vector format. This lets you write the values you want represented in a vector. Input: a string Syntax:
Output: one value of type vector. |
Search functions
This section describes Cloud SQL search functions.
KNN functions
This following table lists the functions that you can use to calculate theKNN vector distance.
| Function | Data type | Description |
| vector_distance | Input:VECTOR Output:REAL | Calculates the vector distance between twoVECTORs. The twoVECTORs must have the same dimensions.Input: required. Takes two vector values, An optional third string argument indicates the distance measure. Default is `l2_squared_distance. Other options include `cosine_distance` and `dot_product`. Output: the distance between the two vectors. For example:
|
| cosine_distance | Input:VECTOR Output:REAL | Algorithm to calculate the cosine of the angle between two vectors. A smaller value indicates greater similarity between the vectors. Input: takes two vector values. These can be column names or constants. Output: the cosine distance between the two vectors. For example:
|
| dot_product | Input:VECTOR Output:REAL | Algorithm that performs the dot product operation between two input vectors to calculate and output a single scalar value. Input: takes two vector values. These can be column names or constants. Output: the dot product of the two vectors. For example:
|
| l2_squared_distance | Input:VECTOR Output:REAL | Algorithm that adds the squared distance on each dimension between two input vectors to measure the Euclidean distance between them. Input: takes two vector values. These can be column names or constants. Output: the L2 squared distance between the two vectors. For example:
|
ANN function
This following table lists the function that you can use to calculate vectordistance.
| Function | Data Type | Description |
| approx_distance | Input:VECTOR Output:REAL | Finds the top K closest rows that satisfy the distance measure using the selected algorithm. This function queries the approximate nearest neighbors from a vector column to a constant value. The two embedding column'sVECTOR type and the constantVECTOR must have the same dimensions. There are some cases when this function falls back to a KNN (exact search) search instead of ANN search. You must include a limit with queries that use this function.Syntax:
Inputs:
|
What's next
- Read theoverview about vector search on Cloud SQL.
- Learn how toenable and disable vector embeddings on your instance.
- Learn how togenerate vector embeddings.
- Learn how tocreate vector indexes.
- Learn how toperform searches on vector embeddings.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-11-24 UTC.