pg.ddx.io  pgvector/pgvector GitHub issues and pull requests  
help / color / mirror / Atom feed
[pgvector/pgvector] PR #849: increase maximum dimension size for HNSW index
3+ messages / 3 participants
[nested] [flat]

* [pgvector/pgvector] PR #849: increase maximum dimension size for HNSW index
@ 2025-06-04 09:50  "fshabashev (@fshabashev)" <noreply+fshabashev@github.com>
  0 siblings, 0 replies; 3+ messages in thread

From: fshabashev (@fshabashev) @ 2025-06-04 09:50 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

Some popular embedding models, such as OpenAI's `text-embedding-3-large` have more than 2,000 dimensions. 
I propose increasing the `HNSW_MAX_DIM` from 2,000 to 4,000 to support larger embedding models. 

inline patch 1: src/hnsw.h (+1/-1 lines) download inline-1.patchdiff --git a/src/hnsw.h b/src/hnsw.h index 5102bfb5a..8a6c64803 100644 --- a/src/hnsw.h +++ b/src/hnsw.h @@ -12,7 +12,7 @@ #include "utils/sampling.h" #include "vector.h" -#define HNSW_MAX_DIM 2000 +#define HNSW_MAX_DIM 4000 #define HNSW_MAX_NNZ 1000 /* Support functions */
^ permalink raw [nested|flat] 3+ messages in thread

* Re: [pgvector/pgvector] PR #849: increase maximum dimension size for HNSW index
@ 2025-06-04 14:44  "jkatz (@jkatz)" <noreply+jkatz@github.com>
  1 sibling, 0 replies; 3+ messages in thread

From: jkatz (@jkatz) @ 2025-06-04 14:44 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

This won't work as expected, as the tuple will exceed the page boundary. The technique to use for this is cast the indexed vector to `halfvec`. There's an [example here](https://jkatz05.com/post/postgres/pgvector-scalar-binary-quantization/), using the cosine distance:

```sql
CREATE TABLE documents (
    id bigint GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
    content text,
    embedding vector(3072)
);

CREATE INDEX ON documents
    USING hnsw ((embedding::halfvec(3072)) halfvec_cosine_ops);
```

^ permalink  raw  [nested|flat] 3+ messages in thread

* Re: [pgvector/pgvector] PR #849: increase maximum dimension size for HNSW index
@ 2025-06-04 17:11  "ankane (@ankane)" <noreply+ankane@github.com>
  1 sibling, 0 replies; 3+ messages in thread

From: ankane (@ankane) @ 2025-06-04 17:11 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

@ankane closed this.

^ permalink  raw  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2025-06-04 17:11 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2025-06-04 09:50 [pgvector/pgvector] PR #849: increase maximum dimension size for HNSW index "fshabashev (@fshabashev)" <noreply+fshabashev@github.com>
2025-06-04 14:44 ` "jkatz (@jkatz)" <noreply+jkatz@github.com>
2025-06-04 17:11 ` "ankane (@ankane)" <noreply+ankane@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