pg.ddx.io pgvector/pgvector GitHub issues and pull requests
help / color / mirror / Atom feed[pgvector/pgvector] issue #442: OpenAI's text-embedding-3-large model not compatible with pgvector 5.1
14+ messages / 6 participants
[nested] [flat]
* [pgvector/pgvector] issue #442: OpenAI's text-embedding-3-large model not compatible with pgvector 5.1
@ 2024-01-26 15:46 "wmwsagara (@wmwsagara)" <noreply+wmwsagara@github.com>
0 siblings, 0 replies; 14+ messages in thread
From: wmwsagara (@wmwsagara) @ 2024-01-26 15:46 UTC (permalink / raw)
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
OpenAI says its new "text-embedding-3-large" embedding model with 3072 dimensions is the "new best performing model" with significantly higher score than "ada v2".
See: https://openai.com/blog/new-embedding-models-and-api-updates
I use only HNSW indexing with cosine distance.
I gave it a try by modifying the src/hnsw.h as follows:
-#define HNSW_MAX_DIM 2000
+#define HNSW_MAX_DIM 8192
But when insert records, it gives following error:
Database error: failed to add index item to "xyz_cosine_idx"
The "failed to add index item to" are only referenced in following files:
./src/ivfbuild.c
./src/ivfinsert.c
./src/hnswinsert.c
./src/hnswvacuum.c
./src/hnswbuild.c
They point to BlockNumber and OffsetNumber based functions which I'm not familiar with.
If someone could develop a patch against pgvector 5.1, I can give it a try and update here.
Best regards
Sagara
^ permalink raw [nested|flat] 14+ messages in thread
* Re: [pgvector/pgvector] issue #442: OpenAI's text-embedding-3-large model not compatible with pgvector 5.1
@ 2024-01-26 18:38 ` "jkatz (@jkatz)" <noreply+jkatz@github.com>
12 siblings, 0 replies; 14+ messages in thread
From: jkatz (@jkatz) @ 2024-01-26 18:38 UTC (permalink / raw)
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Noting that `text-embedding-3-small` is 1536 dimensions and fits within current indexing. The OpenAI docs also mention you can reduce the dimensions for `text-embedding-3-large` if you pass in the dimensions parameter (options of 256 and 1024).
I'm not quickly finding this in the docs, but is `text-embedding-3-large` using 4-byte or 2-byte floats? I wonder if releasing the `half` patch would help with the indexing issue.
^ permalink raw [nested|flat] 14+ messages in thread
* Re: [pgvector/pgvector] issue #442: OpenAI's text-embedding-3-large model not compatible with pgvector 5.1
@ 2024-01-26 22:03 ` "ankane (@ankane)" <noreply+ankane@github.com>
12 siblings, 0 replies; 14+ messages in thread
From: ankane (@ankane) @ 2024-01-26 22:03 UTC (permalink / raw)
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
@ankane closed this.
^ permalink raw [nested|flat] 14+ messages in thread
* Re: [pgvector/pgvector] issue #442: OpenAI's text-embedding-3-large model not compatible with pgvector 5.1
@ 2024-01-26 22:03 ` "ankane (@ankane)" <noreply+ankane@github.com>
12 siblings, 0 replies; 14+ messages in thread
From: ankane (@ankane) @ 2024-01-26 22:03 UTC (permalink / raw)
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
@wmwsagara You can pass any `dimensions` parameter that's 2000 or less to generate vectors that can be indexed. From the announcement post, 1024 dimensions gets a lot of the benefit of the new model.
@jkatz It uses 4-byte floats looking at the API response. The `half` type may be included in 0.7.0, but also want to look at other approaches.
^ permalink raw [nested|flat] 14+ messages in thread
* Re: [pgvector/pgvector] issue #442: OpenAI's text-embedding-3-large model not compatible with pgvector 5.1
@ 2024-01-28 08:04 ` "wmwsagara (@wmwsagara)" <noreply+wmwsagara@github.com>
12 siblings, 0 replies; 14+ messages in thread
From: wmwsagara (@wmwsagara) @ 2024-01-28 08:04 UTC (permalink / raw)
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Andrew (@ankane) please let me ask to reopen this issue for the benefit of wider pgvector user community.
1. Which embedding model is suitable for a specific application?
text-embedding-3-small:
"text-embedding-3-small is our new highly efficient embedding model and provides a significant upgrade over its predecessor..."
NOTE: "new highly efficient embedding model"
Comparing text-embedding-ada-002 to text-embedding-3-small, ... the average score on a commonly used benchmark for English tasks (MTEB) has increased from 61.0% to 62.3%.
text-embedding-3-large:
"text-embedding-3-large is our new next generation larger embedding model and creates embeddings with up to 3072 dimensions."
NOTE: "new next generation larger embedding model"
text-embedding-3-large is our new best performing model. Comparing text-embedding-ada-002 to text-embedding-3-large: ... while on MTEB, the average score has increased from 61.0% to 64.6%.
Other models:
voyage-lite-02-instruct:
MTEB the average score: 67.13 (Best performer on MTEB leaderboard)
https://docs.voyageai.com/embeddings/
Note, "But More advanced and specialized models are coming soon:
voyage-finance-2: coming soon
voyage-law-2: coming soon
voyage-multilingual-2: coming soon
voyage-healthcare-2: coming soon"
This means, voyage-lite-02-instruct may not be good enough for finance, law, healthcare.
Therefore, text-embedding-3-large (MTEB 64.6%) may be better for finance, law, healthcare than voyage-lite-02-instruct (MTEB 67.13%) unless tests prove otherwise.
Similarly, text-embedding-3-large (MTEB 64.6%) may be better for finance, law, healthcare than text-embedding-3-small (MTEB 62.3%) unless tests prove otherwise.
Of course, from the text-embedding-3-small one may retrieve 1024 dimensions, or may use a lower dimension model and save storage and RAM but what's the point, if real world tests shows for a user a significant loss of accuracy?
See: https://huggingface.co/spaces/mteb/leaderboard
Is MTEB average score 64.6% (text-embedding-3-large) good enough? How about a future model proves to be over 95%?
Please note, I'm not saying higher dimensions are always better, but I'm stressing is, users must have the ability to test which model is suitable for them.
2. Why two different maximum dimensions?
src/vector.h
#define VECTOR_MAX_DIM 16000
src/hnsw.h
#define HNSW_MAX_DIM 2000
Is there a technical reason that HNSW index cannot support VECTOR_MAX_DIM?
^ permalink raw [nested|flat] 14+ messages in thread
* Re: [pgvector/pgvector] issue #442: OpenAI's text-embedding-3-large model not compatible with pgvector 5.1
@ 2024-01-28 08:12 ` "wmwsagara (@wmwsagara)" <noreply+wmwsagara@github.com>
12 siblings, 0 replies; 14+ messages in thread
From: wmwsagara (@wmwsagara) @ 2024-01-28 08:12 UTC (permalink / raw)
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Jonathan (@jkatz), please note the above comment. Thanks.
^ permalink raw [nested|flat] 14+ messages in thread
* Re: [pgvector/pgvector] issue #442: OpenAI's text-embedding-3-large model not compatible with pgvector 5.1
@ 2024-01-31 11:48 ` "mateusmirandaalmeida (@mateusmirandaalmeida)" <noreply+mateusmirandaalmeida@github.com>
12 siblings, 0 replies; 14+ messages in thread
From: mateusmirandaalmeida (@mateusmirandaalmeida) @ 2024-01-31 11:48 UTC (permalink / raw)
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
I don't understand why the issue was closed, the problem doesn't seem resolved, the indices don't accept dimensions above 2,000, is that right?
^ permalink raw [nested|flat] 14+ messages in thread
* Re: [pgvector/pgvector] issue #442: OpenAI's text-embedding-3-large model not compatible with pgvector 5.1
@ 2024-01-31 15:04 ` "wmwsagara (@wmwsagara)" <noreply+wmwsagara@github.com>
12 siblings, 0 replies; 14+ messages in thread
From: wmwsagara (@wmwsagara) @ 2024-01-31 15:04 UTC (permalink / raw)
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Yes, dimensions above 2,000 is still not supported yet.
The decision to ignore the elephant in the room (OpenAI's text-embedding-3-large) is puzzling.
^ permalink raw [nested|flat] 14+ messages in thread
* Re: [pgvector/pgvector] issue #442: OpenAI's text-embedding-3-large model not compatible with pgvector 5.1
@ 2024-01-31 17:12 ` "jkatz (@jkatz)" <noreply+jkatz@github.com>
12 siblings, 0 replies; 14+ messages in thread
From: jkatz (@jkatz) @ 2024-01-31 17:12 UTC (permalink / raw)
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
@wmwsagara The 2K indexing limit is not being ignored. There have been numerous discussions about this topic both within the pgvector project and at events. At PGCon 2023, I gave a lightning talk discussing this exact point, as well as various strategies we can use in PostgreSQL to work beyond the limit. Also as mentioned, there are several open branches that can help address it.
That said, @ankane did provide an alternative approach to using the `text-embedding-3-large`. Additionally, you could considering doing some prefiltering of the data with PCA or other information to store it. You can also store it without an index and perform an exact nearest neighbor search. It all depends on your application, which I'm not sure you've provided information about.
The stats you provided showed a 2-4% gain in using the larger dimensionality. I'm many years removed from my machine learning studies, so that could be quite a significant gain. With my database hat on, I read it as having to store 3x the amount of information for a small gain, whereas I could store less and increasing some of my indexing tuning parameters to get better relevancy.
pgvector is open source, and ideas for how to support indexing larger vectors while still utilizing PostgreSQL's storage system (i.e. maintaining ACID compliance) are welcome.
^ permalink raw [nested|flat] 14+ messages in thread
* Re: [pgvector/pgvector] issue #442: OpenAI's text-embedding-3-large model not compatible with pgvector 5.1
@ 2024-01-31 20:27 ` "xfalcox (@xfalcox)" <noreply+xfalcox@github.com>
12 siblings, 0 replies; 14+ messages in thread
From: xfalcox (@xfalcox) @ 2024-01-31 20:27 UTC (permalink / raw)
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
We are already using `text-embedding-3-large` with pgvector in production by simply passing the dimensions parameter with `2000` as the value.
^ permalink raw [nested|flat] 14+ messages in thread
* Re: [pgvector/pgvector] issue #442: OpenAI's text-embedding-3-large model not compatible with pgvector 5.1
@ 2024-09-11 11:57 ` "touhi99 (@touhi99)" <noreply+touhi99@github.com>
12 siblings, 0 replies; 14+ messages in thread
From: touhi99 (@touhi99) @ 2024-09-11 11:57 UTC (permalink / raw)
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
does hnsw work with halfvec or its still a blocker?
^ permalink raw [nested|flat] 14+ messages in thread
* Re: [pgvector/pgvector] issue #442: OpenAI's text-embedding-3-large model not compatible with pgvector 5.1
@ 2024-09-11 14:00 ` "jkatz (@jkatz)" <noreply+jkatz@github.com>
12 siblings, 0 replies; 14+ messages in thread
From: jkatz (@jkatz) @ 2024-09-11 14:00 UTC (permalink / raw)
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
> does hnsw work with halfvec or its still a blocker?
HNSW has supported `halfvec` [since v0.7.0](https://github.com/pgvector/pgvector/blob/master/CHANGELOG.md#070-2024-04-29).
^ permalink raw [nested|flat] 14+ messages in thread
* Re: [pgvector/pgvector] issue #442: OpenAI's text-embedding-3-large model not compatible with pgvector 5.1
@ 2024-09-11 15:29 ` "touhi99 (@touhi99)" <noreply+touhi99@github.com>
12 siblings, 0 replies; 14+ messages in thread
From: touhi99 (@touhi99) @ 2024-09-11 15:29 UTC (permalink / raw)
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
im quite new to the topic. sorry to ask, how do i convert my OpenAI's text-embedding-3-large vector to halfvec or is this part done in pgvector side?
^ permalink raw [nested|flat] 14+ messages in thread
* Re: [pgvector/pgvector] issue #442: OpenAI's text-embedding-3-large model not compatible with pgvector 5.1
@ 2024-09-11 15:51 ` "jkatz (@jkatz)" <noreply+jkatz@github.com>
12 siblings, 0 replies; 14+ messages in thread
From: jkatz (@jkatz) @ 2024-09-11 15:51 UTC (permalink / raw)
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
@touhi99 I have some examples in this blog post on [scalar and binary quantization](https://jkatz05.com/post/postgres/pgvector-scalar-binary-quantization/), e.g.:
```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);
```
Note that this example stores the full vector in the table, and the `halfvec` in the index. You can also opt to store the `halfvec` only in the table, though you may lose some precision by storing the reduced-size vector in the table.
^ permalink raw [nested|flat] 14+ messages in thread
end of thread, other threads:[~2024-09-11 15:51 UTC | newest]
Thread overview: 14+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2024-01-26 15:46 [pgvector/pgvector] issue #442: OpenAI's text-embedding-3-large model not compatible with pgvector 5.1 "wmwsagara (@wmwsagara)" <noreply+wmwsagara@github.com>
2024-01-26 18:38 ` "jkatz (@jkatz)" <noreply+jkatz@github.com>
2024-01-26 22:03 ` "ankane (@ankane)" <noreply+ankane@github.com>
2024-01-26 22:03 ` "ankane (@ankane)" <noreply+ankane@github.com>
2024-01-28 08:04 ` "wmwsagara (@wmwsagara)" <noreply+wmwsagara@github.com>
2024-01-28 08:12 ` "wmwsagara (@wmwsagara)" <noreply+wmwsagara@github.com>
2024-01-31 11:48 ` "mateusmirandaalmeida (@mateusmirandaalmeida)" <noreply+mateusmirandaalmeida@github.com>
2024-01-31 15:04 ` "wmwsagara (@wmwsagara)" <noreply+wmwsagara@github.com>
2024-01-31 17:12 ` "jkatz (@jkatz)" <noreply+jkatz@github.com>
2024-01-31 20:27 ` "xfalcox (@xfalcox)" <noreply+xfalcox@github.com>
2024-09-11 11:57 ` "touhi99 (@touhi99)" <noreply+touhi99@github.com>
2024-09-11 14:00 ` "jkatz (@jkatz)" <noreply+jkatz@github.com>
2024-09-11 15:29 ` "touhi99 (@touhi99)" <noreply+touhi99@github.com>
2024-09-11 15:51 ` "jkatz (@jkatz)" <noreply+jkatz@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