tensorchord / pgvecto.rs

Scalable, Low-latency and Hybrid-enabled Vector Search in Postgres. Revolutionize Vector Search, not Database.
https://docs.pgvecto.rs/getting-started/overview.html
Apache License 2.0
1.75k stars 71 forks source link

indexing.hnsw.quantization.scalar does not improve the performance of query the similar embeddings #572

Open janljd opened 2 months ago

janljd commented 2 months ago

Environment

docker tensorchord/pgvecto-rs:pg16-v0.3.0

Data preparation

CREATE TABLE dbpedia_3072 (
            id bigserial primary key, 
            title text,
            content text,
            embedding vector(3072)
            );

CREATE INDEX hnsw_cosine_index_dbpedia_3072 ON dbpedia_3072 USING vectors (embedding vector_cos_ops) WITH (options='[indexing.hnsw]
m = 16
ef_construction = 100
');

CREATE TABLE dbpedia_3072_scalar (
            id bigserial primary key, 
            title text,
            content text,
            embedding vector(3072)
            );

CREATE INDEX hnsw_cosine_index_dbpedia_3072_scalar ON dbpedia_3072_scalar USING vectors (embedding vector_cos_ops) WITH (options='[indexing.hnsw]
m = 16
ef_construction = 100
[indexing.hnsw.quantization.scalar]
');

dataset https://huggingface.co/datasets/Qdrant/dbpedia-entities-openai3-text-embedding-3-large-3072-100K

Test

Simulate 100 users randomly querying 3072-dimensional vectors for similar embeddings

SELECT 1 - (embedding <=> %s) AS cosine_similarity,title,content FROM dbpedia_3072 ORDER BY embedding <=> %s LIMIT 1

SELECT 1 - (embedding <=> %s) AS cosine_similarity,title,content FROM dbpedia_3072_scalar ORDER BY embedding <=> %s LIMIT 1

Result

dbpedia_3072 dbpedia_3072_scalar
avg 13.66 ms 12.46 ms
rps 732.4 765.5
max cpu / memory max cpu 330% / 1033MB max cpu 270% / 1300MB

index stat

SELECT tablename,idx_status,idx_size,idx_options FROM pg_vector_index_stat

tablename idx_status idx_size idx_options
dbpedia_3072 NORMAL 1,236,929,603 {"vector":{"dimensions":3072,"vector":"Vecf32","distance":"Cos"},"segment":{"max_growing_segment_size":20000,"max_sealed_segment_size":1000000},"indexing":{"hnsw":{"m":16,"ef_construction":100,"quantization":{"trivial":{}}}}}
dbpedia_3072_scalar NORMAL 1,547,237,503 {"vector":{"dimensions":3072,"vector":"Vecf32","distance":"Cos"},"segment":{"max_growing_segment_size":20000,"max_sealed_segment_size":1000000},"indexing":{"hnsw":{"m":16,"ef_construction":100,"quantization":{"scalar":{}}}}}