Calculates the taxicab distance between numeric array expressions. It can be used to query embedding vectors that are most similar (for example, have the lowest distance) to a given vector.
vectorL1Distance(firstExpression, secondExpression)
| Parameter | Type | Description | Required |
|---|---|---|---|
firstExpression | array | The first vector between which the distance should be computed | Required |
secondExpression | array | The second vector between which the distance should be computed | Required |
The data type of the returned value is double. Returns null for arrays of different lengths and arrays of other types.
data record(a = array(1, 1, 1), b = array(1, 2, 3)),record(a = array(1.0, 1.0, 1.0), b = array(1.0, 2.0, 3.0)),record(a = array(1, 2), b = array(1, 2)),record(a = array(1, 2), b = array(1, 2, 3)),record(a = array(1, 2), b = array(1, "foo"))| fields a, b, vectorL1Distance(a, b)
Query result:
| a | b | vectorL1Distance(a, b) |
|---|---|---|
|
|
|
|
|
|
|
|
|
|
| null |
|
| null |
Calculates the Euclidean distance between numeric array expressions. It can be used to query embedding vectors that are most similar (for example, have the lowest distance) to a given vector.
vectorL2Distance(firstExpression, secondExpression)
| Parameter | Type | Description | Required |
|---|---|---|---|
firstExpression | array | The first vector between which the distance should be computed | Required |
secondExpression | array | The second vector between which the distance should be computed | Required |
The data type of the returned value is double. Returns null for arrays of different lengths and arrays of other types.
data record(a = array(1, 1, 1), b = array(1, 2, 3)),record(a = array(1.0, 1.0, 1.0), b = array(1.0, 2.0, 3.0)),record(a = array(1, 2), b = array(1, 2)),record(a = array(1, 2), b = array(1, 2, 3)),record(a = array(1, 2), b = array(1, "foo"))| fields a, b, vectorL2Distance(a, b)
Query result:
| a | b | vectorL2Distance(a, b) |
|---|---|---|
|
|
|
|
|
|
|
|
|
|
| null |
|
| null |
Calculates the cosine distance between numeric array expressions. It can be used to query embedding vectors that are most similar (for example, have the lowest distance) to a given vector.
vectorCosineDistance(firstExpression, secondExpression)
| Parameter | Type | Description | Required |
|---|---|---|---|
firstExpression | array | The first vector between which the distance should be computed | Required |
secondExpression | array | The second vector between which the distance should be computed | Required |
The data type of the returned value is double. Returns null for arrays of different lengths and arrays of other types.
data record(a = array(1, 1, 1), b = array(1, 2, 3)),record(a = array(1.0, 1.0, 1.0), b = array(1.0, 2.0, 3.0)),record(a = array(1, 2), b = array(1, 2)),record(a = array(1, 2), b = array(1, 2, 3)),record(a = array(1, 2), b = array(1, "foo"))| fields a, b, vectorCosineDistance(a, b)
Query result:
| a | b | vectorCosineDistance(a, b) |
|---|---|---|
|
|
|
|
|
|
|
|
|
|
| null |
|
| null |
Calculates the negative dot product between numeric array expressions. It can be used to query embedding vectors that are most similar to a given vector.
vectorInnerProductDistance(firstExpression, secondExpression)
| Parameter | Type | Description | Required |
|---|---|---|---|
firstExpression | array | The first vector between which the distance should be computed | Required |
secondExpression | array | The second vector between which the distance should be computed | Required |
The data type of the returned value is double. Returns null for arrays of different lengths and arrays of other types.
data record(a = array(1, 1, 1), b = array(1, 2, 3)),record(a = array(1.0, 1.0, 1.0), b = array(1.0, 2.0, 3.0)),record(a = array(1, 2), b = array(1, 2)),record(a = array(1, 2), b = array(1, 2, 3)),record(a = array(1, 2), b = array(1, "foo"))| fields a, b, vectorInnerProductDistance(a, b)
Query result:
| a | b | vectorInnerProductDistance(a, b) |
|---|---|---|
|
|
|
|
|
|
|
|
|
|
| null |
|
| null |