Vector Functions
This section provides reference information for vector functions in Databend. These functions enable comprehensive vector operations including distance calculations, similarity measurements, and vector analysis for machine learning applications, vector search, and AI-powered analytics.
Distance Functions
| Function | Description | Example |
|---|---|---|
| COSINE_DISTANCE | Calculates Cosine distance between vectors (range: 0-1) | COSINE_DISTANCE([1,2,3]::VECTOR(3), [4,5,6]::VECTOR(3)) |
| L1_DISTANCE | Calculates Manhattan (L1) distance between vectors | L1_DISTANCE([1,2,3]::VECTOR(3), [4,5,6]::VECTOR(3)) |
| L2_DISTANCE | Calculates Euclidean (straight-line) distance | L2_DISTANCE([1,2,3]::VECTOR(3), [4,5,6]::VECTOR(3)) |
| INNER_PRODUCT | Calculates the inner product (dot product) of two vectors | INNER_PRODUCT([1,2,3]::VECTOR(3), [4,5,6]::VECTOR(3)) |
Vector Analysis Functions
| Function | Description | Example |
|---|---|---|
| VECTOR_NORM | Calculates the L2 norm (magnitude) of a vector | VECTOR_NORM([1,2,3]::VECTOR(3)) |
| VECTOR_DIMS | Returns the dimensionality of a vector | VECTOR_DIMS([1,2,3]::VECTOR(3)) |
Distance Functions Comparison
| Function | Description | Range | Best For | Use Cases |
|---|---|---|---|---|
| COSINE_DISTANCE | Cosine distance between vectors | [0, 1] | When direction matters more than magnitude | • Document similarity • Semantic search • Recommendation systems • Text analysis |
| L1_DISTANCE | Manhattan (L1) distance between vectors | [0, ∞) | Robust to outliers | • Feature comparison • Outlier detection • Grid-based pathfinding • Clustering algorithms |
| L2_DISTANCE | Euclidean (straight-line) distance | [0, ∞) | When magnitude and absolute differences are important | • Image similarity • Geographical data • Anomaly detection • Feature-based clustering |
| INNER_PRODUCT | Dot product of two vectors | (-∞, ∞) | When both magnitude and direction are important | • Neural networks • Machine learning • Physics calculations • Vector projections |
Vector Analysis Functions Comparison
| Function | Description | Range | Best For | Use Cases |
|---|---|---|---|---|
| VECTOR_NORM | L2 norm (magnitude) of a vector | [0, ∞) | Vector normalization and magnitude | • Vector normalization • Feature scaling • Magnitude calculations • Physics applications |
| VECTOR_DIMS | Number of vector dimensions | [1, 4096] | Vector validation and processing | • Data validation • Dynamic processing • Debugging • Compatibility checks |