View Source SqliteVec.Ecto.Query (SqliteVec v0.1.0)

Macros for Ecto

Summary

Functions

Adds every element in vector a with vector b, returning a new vector c. Both vectors must be of the same type and same length. Only float32 and int8 vectors are supported.

Creates a bit vector

Calculates the cosine distance between vectors a and b. Only valid for float32 or int8 vectors.

Calculates the hamming distance between two bitvectors a and b. Only valid for bitvectors.

Calculates the L2 euclidian distance between vectors a and b. Only valid for float32 or int8 vectors.

Creates a float32 vector

Creates an int8 vector

Returns the number of elements in the given vector

Performs L2 normalization on the given vector. Only float32 vectors are currently supported.

Quantize a float32 or int8 vector into a bitvector. For every element in the vector, a 1 is assigned to positive numbers and a 0 is assigned to negative numbers. These values are then packed into a bit vector.

Extract a subset of vector from the start element (inclusive) to the end element (exclusive).

Subtracts every element in vector a with vector b, returning a new vector c. Both vectors must be of the same type and same length. Only float32 and int8 vectors are supported.

Represents a vector as JSON text. The input vector can be a vector BLOB or JSON text.

Returns the name of the type of vector as text

Functions

Adds every element in vector a with vector b, returning a new vector c. Both vectors must be of the same type and same length. Only float32 and int8 vectors are supported.

An error is raised if either a or b are invalid, or if they are not the same type or same length.

Link to this macro

vec_bit(vector)

View Source (macro)

Creates a bit vector

Link to this macro

vec_distance_cosine(a, b)

View Source (macro)

Calculates the cosine distance between vectors a and b. Only valid for float32 or int8 vectors.

Returns an error under the following conditions:

  • a or b are invalid vectors
  • a or b do not share the same vector element types (ex float32 or int8)
  • a or b are bit vectors. Use vec_distance_hamming() for distance calculations between two bitvectors.
  • a or b do not have the same length
Link to this macro

vec_distance_hamming(a, b)

View Source (macro)

Calculates the hamming distance between two bitvectors a and b. Only valid for bitvectors.

Returns an error under the following conditions:

  • a or b are not bitvectors
  • a and b do not share the same length
  • Memory cannot be allocated
Link to this macro

vec_distance_L2(a, b)

View Source (macro)

Calculates the L2 euclidian distance between vectors a and b. Only valid for float32 or int8 vectors.

Returns an error under the following conditions:

  • a or b are invalid vectors
  • a or b do not share the same vector element types (ex float32 or int8)
  • a or b are bit vectors. Use vec_distance_hamming() for distance calculations between two bitvectors.
  • a or b do not have the same length.
Link to this macro

vec_f32(vector)

View Source (macro)

Creates a float32 vector

Link to this macro

vec_int8(vector)

View Source (macro)

Creates an int8 vector

Link to this macro

vec_length(vector)

View Source (macro)

Returns the number of elements in the given vector

Link to this macro

vec_normalize(vector)

View Source (macro)

Performs L2 normalization on the given vector. Only float32 vectors are currently supported.

Returns an error if the input is an invalid vector or not a float32 vector.

Link to this macro

vec_quantize_binary(vector)

View Source (macro)

Quantize a float32 or int8 vector into a bitvector. For every element in the vector, a 1 is assigned to positive numbers and a 0 is assigned to negative numbers. These values are then packed into a bit vector.

Returns an error if vector is invalid, or if vector is not a float32 or int8 vector.

Link to this macro

vec_slice(vector, start_index, end_index)

View Source (macro)

Extract a subset of vector from the start element (inclusive) to the end element (exclusive).

This is especially useful for Matryoshka embeddings, also known as "adaptive length" embeddings. Use with vec_normalize() to get proper results.

Returns an error in the following conditions:

  • If vector is not a valid vector
  • If start is less than zero or greater than or equal to end
  • If end is greater than the length of vector, or less than or equal to start.
  • If vector is a bitvector, start and end must be divisible by 8.

Subtracts every element in vector a with vector b, returning a new vector c. Both vectors must be of the same type and same length. Only float32 and int8 vectors are supported.

An error is raised if either a or b are invalid, or if they are not the same type or same length.

Link to this macro

vec_to_json(vector)

View Source (macro)

Represents a vector as JSON text. The input vector can be a vector BLOB or JSON text.

Returns an error if vector is an invalid vector, or when memory cannot be allocated.

Link to this macro

vec_type(vector)

View Source (macro)

Returns the name of the type of vector as text