Vector Types in NeurondB
What Are Vectors?
A vector is a mathematical object represented as an array of numbers. In AI and machine learning, vectors represent data (text, images, audio) in numerical format that computers can process and compare.
Example Vector
[0.234, -0.891, 0.456, 0.123, -0.678]This is a 5-dimensional vector where each number represents a feature.
Traditional Database vs Vector Database
Traditional Database: Stores structured data: numbers, text, dates. Searches using exact matches or patterns.
Vector Database: Stores numerical representations of data. Searches by semantic similarity and meaning.
Why Use Vectors?
Semantic Search
Find similar items based on meaning, not just keywords. Search for "laptop" and get results for "notebook computer", "portable PC".
Recommendations
Build recommendation systems that suggest related products, content, or services based on similarity.
Anomaly Detection
Identify outliers and unusual patterns in high-dimensional data.
Clustering
Group similar items together for analysis and organization.
Vector Types
vector(n)
Standard dense vector type (float32). Up to 16,000 dimensions. Storage: 4 bytes per dimension.
vector type
CREATE TABLE documents (
id SERIAL PRIMARY KEY,
embedding vector(1536)
);
INSERT INTO documents (embedding) VALUES ('[0.1, 0.2, 0.3]');vectorp
Packed vector with Product Quantization. Compressed (2x-32x smaller). Best for large-scale search and memory optimization.
halfvec
Half-precision vector (float16). 2 bytes per dimension. Best for memory-constrained environments.
sparsevec
Sparse vector representation. Up to 1,000,000 dimensions. Only non-zero values stored. Best for high-dimensional text and TF-IDF vectors.
binaryvec
Binary vector (bit-packed). 1 bit per dimension. Best for Hamming distance and binary embeddings.
Usage Examples
Complete example
-- Create table with different vector types
CREATE TABLE documents (
id SERIAL PRIMARY KEY,
dense_embedding vector(1536),
sparse_features sparsevec,
binary_fingerprint binaryvec
);
-- Insert vectors
INSERT INTO documents (dense_embedding, sparse_features, binary_fingerprint)
VALUES (
'[0.1, 0.2, ...]'::vector(1536),
sparsevec_from_map('{"0": 0.5, "100": 0.3, "500": 0.8}'),
binaryvec_from_array(ARRAY[1,0,1,1,0]::int[])
);
-- Search with different types
SELECT id FROM documents
WHERE dense_embedding <=> '[0.1, 0.2, ...]'::vector < 0.5;Next Steps
- Distance Metrics - Learn about distance functions
- Indexing - Index vectors for fast search
- Quantization - Compress vectors