Sparse Vector: `svector`
Unlike dense vectors, sparse vectors are very high-dimensional but contain few non-zero values.
Unlike dense vectors, sparse vectors are very high-dimensional but contain few non-zero values.
Typically, sparse vectors can be created from:
- Word co-occurrence matrices
- Term frequency-inverse document frequency (TF-IDF) vectors
- User-item interaction matrices
- Network adjacency matrices
Sparse vectors in pgvecto.rs are called svector.
Here’s an example of creating a table with a svector column and inserting values:
Index can be created on svector type as well.
We support three operators to calculate the distance between two svector values.
<->(svector_l2_ops): squared Euclidean distance, defined as .<#>(svector_dot_ops): negative dot product, defined as .<=>(svector_cos_ops): cosine distance, defined as .
There is also a function to_svector to create a svector. It will set the value at the specified position.