pg.ddx.io  pgvector/pgvector GitHub issues and pull requests  
help / color / mirror / Atom feed
From: idobenamram (@idobenamram) <noreply+idobenamram@github.com>
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Subject: [pgvector/pgvector] issue #821: avg_width for Vector is 18 and for HalfVec is 1544
Date: Mon, 14 Apr 2025 11:39:11 +0000
Message-ID: <gh-pgvector-pgvector-821@github.com> (raw)

Hey guys I am seeing something weird. 

I was migrating one of our tables that had an embedding column with type vector(768) to halfvec(768). same hnsw index same everything, the only difference is the halfvec.

I notices that my knn query was a little bit slower which was weird considering it should be doing less work on halfvec, and when i ran analyze on the query it looked like it wasn't using the hnsw index at all but doing a seq scan instead.

i have no idea why as there is no difference, but i saw that when i query pg_stat i see something weird:
```
SELECT *
FROM pg_stats
WHERE (tablename = 'embeddings_table_half' or tablename = 'embeddings_table')
```
i see 

---------------------------------------------------------------------------------

| schemaname | tablename             | attname  | inherited | null_frac | avg_width | n_distinct |
|----------|----------------------|-----------|----------|----------|----------|----------|
| public   | embeddings_table     | embedding | false    | 0.0      | 18       | -1.0     | 
| public   | embeddings_table_half| embedding | false    | 0.0      | 1544     | -1.0    | 

for some reason the avg_width of the columns are very different. the halfvec size makes sense (768 * 2 + overhead) but the vector size makes no sense... i was wondering if this might be the reason the planner is choosing not to use the hnsw index on the halfvec column. 

here is how i create the index:
```
CREATE INDEX idx_embeddings_table_half_embeddings ON embeddings_table_half USING hnsw (embedding halfvec_ip_ops) WITH (m = 16, ef_construction = 64);

CREATE INDEX idx_embeddings_table_embeddings ON embeddings_table USING hnsw (embedding vector_ip_ops) WITH (m = 16, ef_construction = 64);
```
is this ok? does it matter at all?

versions
PostgreSQL 17.4 on x86_64-pc-linux-gnu, compiled by Debian clang version 12.0.1, 64-bit
pgvector 0.8.0


view thread (7+ messages)  latest in thread

Message-ID: <gh-pgvector-pgvector-821@github.com>
Permalink:  ../gh-pgvector-pgvector-821@github.com/

 · 


This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox