Skip to content
This documentation is sourced from a third-party project and is not maintained by pgEdge.

Reference

Vector Type

Each vector takes 4 * dimensions + 8 bytes of storage. Each element is a single-precision floating-point number (like the real type in Postgres), and all elements must be finite (no NaN, Infinity or -Infinity). Vectors can have up to 16,000 dimensions.

Vector Operators

Operator Description Added
+ element-wise addition
- element-wise subtraction
* element-wise multiplication 0.5.0
|| concatenate 0.7.0
<-> Euclidean distance
<#> negative inner product
<=> cosine distance
<+> taxicab distance 0.7.0

Vector Functions

Function Description Added
binary_quantize(vector) → bit binary quantize 0.7.0
cosine_distance(vector, vector) → double precision cosine distance
inner_product(vector, vector) → double precision inner product
l1_distance(vector, vector) → double precision taxicab distance 0.5.0
l2_distance(vector, vector) → double precision Euclidean distance
l2_normalize(vector) → vector Normalize with Euclidean norm 0.7.0
subvector(vector, integer, integer) → vector subvector 0.7.0
vector_dims(vector) → integer number of dimensions
vector_norm(vector) → double precision Euclidean norm

Vector Aggregate Functions

Function Description Added
avg(vector) → vector average
sum(vector) → vector sum 0.5.0

Halfvec Type

Each half vector takes 2 * dimensions + 8 bytes of storage. Each element is a half-precision floating-point number, and all elements must be finite (no NaN, Infinity or -Infinity). Half vectors can have up to 16,000 dimensions.

Halfvec Operators

Operator Description Added
+ element-wise addition 0.7.0
- element-wise subtraction 0.7.0
* element-wise multiplication 0.7.0
|| concatenate 0.7.0
<-> Euclidean distance 0.7.0
<#> negative inner product 0.7.0
<=> cosine distance 0.7.0
<+> taxicab distance 0.7.0

Halfvec Functions

Function Description Added
binary_quantize(halfvec) → bit binary quantize 0.7.0
cosine_distance(halfvec, halfvec) → double precision cosine distance 0.7.0
inner_product(halfvec, halfvec) → double precision inner product 0.7.0
l1_distance(halfvec, halfvec) → double precision taxicab distance 0.7.0
l2_distance(halfvec, halfvec) → double precision Euclidean distance 0.7.0
l2_norm(halfvec) → double precision Euclidean norm 0.7.0
l2_normalize(halfvec) → halfvec Normalize with Euclidean norm 0.7.0
subvector(halfvec, integer, integer) → halfvec subvector 0.7.0
vector_dims(halfvec) → integer number of dimensions 0.7.0

Halfvec Aggregate Functions

Function Description Added
avg(halfvec) → halfvec average 0.7.0
sum(halfvec) → halfvec sum 0.7.0

Bit Type

Each bit vector takes dimensions / 8 + 8 bytes of storage. See the Postgres docs for more info.

Bit Operators

Operator Description Added
<~> Hamming distance 0.7.0
<%> Jaccard distance 0.7.0

Bit Functions

Function Description Added
hamming_distance(bit, bit) → double precision Hamming distance 0.7.0
jaccard_distance(bit, bit) → double precision Jaccard distance 0.7.0

Sparsevec Type

Each sparse vector takes 8 * non-zero elements + 16 bytes of storage. Each element is a single-precision floating-point number, and all elements must be finite (no NaN, Infinity or -Infinity). Sparse vectors can have up to 16,000 non-zero elements.

Sparsevec Operators

Operator Description Added
<-> Euclidean distance 0.7.0
<#> negative inner product 0.7.0
<=> cosine distance 0.7.0
<+> taxicab distance 0.7.0

Sparsevec Functions

Function Description Added
cosine_distance(sparsevec, sparsevec) → double precision cosine distance 0.7.0
inner_product(sparsevec, sparsevec) → double precision inner product 0.7.0
l1_distance(sparsevec, sparsevec) → double precision taxicab distance 0.7.0
l2_distance(sparsevec, sparsevec) → double precision Euclidean distance 0.7.0
l2_norm(sparsevec) → double precision Euclidean norm 0.7.0
l2_normalize(sparsevec) → sparsevec Normalize with Euclidean norm 0.7.0