TD_VectorDistance Function | VectorDistance | Teradata Vantage - TD_VectorDistance - Analytics Database

Database Analytic Functions

Deployment
VantageCloud
VantageCore
Edition
VMware
Enterprise
IntelliFlex
Product
Analytics Database
Release Number
17.20
Published
June 2022
ft:locale
en-US
ft:lastEdition
2025-11-06
dita:mapPath
gjn1627595495337.ditamap
dita:ditavalPath
qkf1628213546010.ditaval
dita:id
jmh1512506877710
Product Category
Teradata Vantageā„¢

TD_VectorDistance computes similarity or dissimilarity between two vectors in multi-dimensional space. The distance between vectors is usually calculated using a distance metric, such as Euclidean, Manhattan, or Cosine. It takes a table of target vectors, and a table of reference vectors and returns a table that contains the distance between target-reference pairs. The function computes the distance between the target pair and the reference pair from the same table if you provide only one table as the input.

The algorithm used in this function is of the order of N2 (where N is the number of rows). The query runs significantly longer as the number of rows increases in either the target table or the reference table. Because the reference table is a DIMENSION input, it is copied to the spool for each AMP before running the query. The user spool limits the size and scalability of the input.

Euclidean distance is the common distance metric used in machine learning algorithms, and it measures the straight-line distance between two points in a multidimensional space.



It is calculated by taking the square root of the sum of the squared differences between each corresponding dimension of the two vectors.

""

Manhattan distance measures the distance between two points by summing the absolute differences between their corresponding dimensions. It is useful when the dimensions have different scales or units.

""

Cosine similarity measures the angle between two vectors and is commonly used in natural language processing and information retrieval. It measures the cosine of the angle between two vectors, and its value ranges from -1 to 1, with 1 indicating that the vectors are identical and -1 indicating that they are completely dissimilar.

""