Vector Types
Turso supports dense, sparse, quantized, and binary vector representations, each suited to different workloads.Dense Vectors
Dense vectors store a value for every dimension. Turso provides two precision levels:Sparse Vectors
Sparse vectors only store non-zero values and their indices, making them memory-efficient for high-dimensional data with many zero values.Quantized Vectors
Values are linearly quantized to the 0-255 range using min/max scaling. Dequantization:
f_i = alpha * q_i + shift.
Binary Vectors
Positive values become 1, non-positive values become 0. Extracted values are displayed as +1/-1.
For most applications,
vector32 is a good starting point. Explore more compact types if your table has a large number of rows.Storing Vectors
Create a table with a BLOB column to store embeddings alongside your relational data:Similarity Search
Use distance functions to find the most similar vectors. All distance functions require both vectors to have the same type and dimensionality. Lower values indicate greater similarity.Cosine Distance
Measures the angle between vectors, ignoring magnitude. Returns a value between 0 (identical direction) and 2 (opposite direction).Euclidean (L2) Distance
Measures straight-line distance in n-dimensional space. Not supported forvector1bit vectors.
Dot Product Distance
Computes the negative dot product:-sum(v1[i] * v2[i]). Lower (more negative) values indicate higher similarity.
Jaccard Distance
Computes weighted Jaccard distance based on the ratio of minimum to maximum values across dimensions. Forvector1bit vectors, computes binary Jaccard distance.
vector1bit.
Utility Functions
vector_extract
Convert a vector BLOB back to a readable JSON representation:vector_concat
Concatenate two vectors into one:vector_slice
Extract a contiguous portion of a vector (zero-based, end exclusive):Limitations
- Euclidean distance is not supported for
vector1bitvectors - Maximum vector dimensionality is 65,536
vector1bitcosine distance returns Hamming distance (number of differing bits) instead of standard cosine distance
Example: Semantic Search
A complete end-to-end example combining vector storage and similarity search:Similarity searches use a linear scan over the table. For large datasets, consider limiting the search to a subset of rows with a
WHERE clause.See Also
- Vector Functions — full SQL reference for all vector functions
- Data Types — how BLOBs are handled in Turso