Basic Usage

Creating a sparse HNSW index over a table can significantly improve query times.

-- Create a table with a sparse vector column
CREATE TABLE items (id bigserial PRIMARY KEY, embedding sparsevec(5));

-- Insert sparse vectors
INSERT INTO items (embedding) VALUES ('{1:1,3:2,5:3}/5'), ('{1:4,3:5,5:6}/5');

Sparse vectors can be searched using L2 distance, cosine distance, or inner product.

-- L2 distance
SELECT * FROM mock_items ORDER BY embedding <-> '{1:3,3:1,5:2}/5' LIMIT 5;

-- Cosine distance
SELECT * FROM mock_items ORDER BY embedding <=> '{1:3,3:1,5:2}/5' LIMIT 5;

-- Inner product
SELECT * FROM mock_items ORDER BY embedding <#> '{1:3,3:1,5:2}/5' LIMIT 5;

Under the hood, ParadeDB uses pgvector for sparse vector search. Please refer to the pgvector documentation for more details.