pg.ddx.io pgvector/pgvector GitHub issues and pull requests
help / color / mirror / Atom feed[pgvector/pgvector] issue #704: Discussion: understanding pgvector
9+ messages / 3 participants
[nested] [flat]
* [pgvector/pgvector] issue #704: Discussion: understanding pgvector
@ 2024-10-29 01:02 "ivanstepanovftw (@ivanstepanovftw)" <noreply+ivanstepanovftw@github.com>
0 siblings, 0 replies; 9+ messages in thread
From: ivanstepanovftw (@ivanstepanovftw) @ 2024-10-29 01:02 UTC (permalink / raw)
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
pgvector stores embeddings in binary or text format? Is it normal that vector-to-compare is a plain text both in the SQL query and response? Is GPU utilized to perform dot product, or computation is not bottleneck, but memory bandwidth?
Thank you!
^ permalink raw [nested|flat] 9+ messages in thread
* Re: [pgvector/pgvector] issue #704: Discussion: understanding pgvector
@ 2024-10-29 02:09 "ankane (@ankane)" <noreply+ankane@github.com>
7 siblings, 0 replies; 9+ messages in thread
From: ankane (@ankane) @ 2024-10-29 02:09 UTC (permalink / raw)
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Hi @ivanstepanovftw,
1. Vectors are stored in a binary format ([docs](https://github.com/pgvector/pgvector?tab=readme-ov-file#vector-type))
2. You can pass the vector to compare and get results as text or binary (the Postgres protocol supports both)
3. GPU isn't supported #291 (most database servers don't have a GPU)
^ permalink raw [nested|flat] 9+ messages in thread
* Re: [pgvector/pgvector] issue #704: Discussion: understanding pgvector
@ 2024-10-29 02:09 "ankane (@ankane)" <noreply+ankane@github.com>
7 siblings, 0 replies; 9+ messages in thread
From: ankane (@ankane) @ 2024-10-29 02:09 UTC (permalink / raw)
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
@ankane closed this.
^ permalink raw [nested|flat] 9+ messages in thread
* Re: [pgvector/pgvector] issue #704: Discussion: understanding pgvector
@ 2024-10-30 13:46 "ivanstepanovftw (@ivanstepanovftw)" <noreply+ivanstepanovftw@github.com>
7 siblings, 0 replies; 9+ messages in thread
From: ivanstepanovftw (@ivanstepanovftw) @ 2024-10-30 13:46 UTC (permalink / raw)
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
And what is the best way to dump the database to restore it at another machine? With `pg_dump -F p > dump.sql` I see that vectors are just a string representation, which may cause loss in precision and consume more disk space than required.
It is known that IEEE-754 32-bit float consumes 4 bytes, but in text format in decimal representation it loses precision and takes more memory, around 13 bytes per float including separation "," character.
^ permalink raw [nested|flat] 9+ messages in thread
* Re: [pgvector/pgvector] issue #704: Discussion: understanding pgvector
@ 2024-10-30 13:58 "ivanstepanovftw (@ivanstepanovftw)" <noreply+ivanstepanovftw@github.com>
7 siblings, 0 replies; 9+ messages in thread
From: ivanstepanovftw (@ivanstepanovftw) @ 2024-10-30 13:58 UTC (permalink / raw)
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
`-F t` gives text representation too.
^ permalink raw [nested|flat] 9+ messages in thread
* Re: [pgvector/pgvector] issue #704: Discussion: understanding pgvector
@ 2024-10-30 19:16 "ankane (@ankane)" <noreply+ankane@github.com>
7 siblings, 0 replies; 9+ messages in thread
From: ankane (@ankane) @ 2024-10-30 19:16 UTC (permalink / raw)
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
The text format shouldn't lose precision, but `pg_dump` also supports the binary format (please see other resources for how to use it).
^ permalink raw [nested|flat] 9+ messages in thread
* Re: [pgvector/pgvector] issue #704: Discussion: understanding pgvector
@ 2024-10-31 15:15 "ivanstepanovftw (@ivanstepanovftw)" <noreply+ivanstepanovftw@github.com>
7 siblings, 0 replies; 9+ messages in thread
From: ivanstepanovftw (@ivanstepanovftw) @ 2024-10-31 15:15 UTC (permalink / raw)
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
I managed to rsync old database directory to the new server and run it.
As I inspect in hexdump, `pg_dump` with all "plain", "tar", "custop" and "directory" formats, dumps floats in vectors that are written as a **decimal** representation of IEEE 754 floating point, i.e. 0.1234 or 1.234e-1, and **not** in hexadecimal formats like 0x1.9p+6 or something like that. The rest "binary" formats are just gzipped, like "custom" and "directory". IEEE 754 32-bit floating point is not using decimal numbers, so not all floats may be represented in decimal base as a string because of math.
With "custom" format issue comes quickly - it gzips vectors, while they are not compressible with gzip. I got around 6 MiB/sec at peak, while db is like 100+ GB of embeddings.
You can try yourself that "custom" binary format and see that vectors are decimal string representation:
```shell
pg_dump -U user -p port -d database -h address -F custom --compress=none
```
However, I found that there is [`pg_dumpbinary`](https://www.postgresql.org/about/news/pg_dumpbinary-v27-2422/), but I did not found that command on Ubuntu 24.04 and decided just to rsync postgres folders to a new server.
---
Summary:
pg_dump loses precision, takes more memory or CPU, and is not optimal to use with pgvector.
pd_dumpbinary is a possible alternative, but untested.
^ permalink raw [nested|flat] 9+ messages in thread
* Re: [pgvector/pgvector] issue #704: Discussion: understanding pgvector
@ 2024-10-31 20:48 "hlinnaka (@hlinnaka)" <noreply+hlinnaka@github.com>
7 siblings, 0 replies; 9+ messages in thread
From: hlinnaka (@hlinnaka) @ 2024-10-31 20:48 UTC (permalink / raw)
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
> IEEE 754 32-bit floating point is not using decimal numbers, so not all floats may be represented in decimal base as a string because of math.
> ...
> pg_dump loses precision, takes more memory or CPU, and is not optimal to use with pgvector.
This is incorrect. You're right that not every IEEE 754 number can be accurately represented as a decimal. But it's still possible to have non-lossy round-trip conversion, IEEE754 -> decimal -> IEEE754.
The trick is that for any 32-bit floating point number, you can construct a decimal number that is closer to the the original 32-bit floating point number than any other 32-bit floating point number. That's sufficient. See "Ryƫ algorithm". That's what the PostgreSQL float datatype and pgvector's vector datatype uses. It converts a float to the "shortest decimal" that represents the original floating point number in a non-lossy way.
The text representation does not lose precision.
You're probably right that you'd get better performance without that conversion. I haven't tried measuring it, but the conversion to decimal and back is not free.
^ permalink raw [nested|flat] 9+ messages in thread
* Re: [pgvector/pgvector] issue #704: Discussion: understanding pgvector
@ 2024-11-01 23:37 "ivanstepanovftw (@ivanstepanovftw)" <noreply+ivanstepanovftw@github.com>
7 siblings, 0 replies; 9+ messages in thread
From: ivanstepanovftw (@ivanstepanovftw) @ 2024-11-01 23:37 UTC (permalink / raw)
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Thank you, I was indeed wrong. By the way, someone tried pg_dumpbinary? Cause pg_dump takes a lot more space without compression or very slow with compression.
^ permalink raw [nested|flat] 9+ messages in thread
end of thread, other threads:[~2024-11-01 23:37 UTC | newest]
Thread overview: 9+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2024-10-29 01:02 [pgvector/pgvector] issue #704: Discussion: understanding pgvector "ivanstepanovftw (@ivanstepanovftw)" <noreply+ivanstepanovftw@github.com>
2024-10-29 02:09 ` "ankane (@ankane)" <noreply+ankane@github.com>
2024-10-29 02:09 ` "ankane (@ankane)" <noreply+ankane@github.com>
2024-10-30 13:46 ` "ivanstepanovftw (@ivanstepanovftw)" <noreply+ivanstepanovftw@github.com>
2024-10-30 13:58 ` "ivanstepanovftw (@ivanstepanovftw)" <noreply+ivanstepanovftw@github.com>
2024-10-30 19:16 ` "ankane (@ankane)" <noreply+ankane@github.com>
2024-10-31 15:15 ` "ivanstepanovftw (@ivanstepanovftw)" <noreply+ivanstepanovftw@github.com>
2024-10-31 20:48 ` "hlinnaka (@hlinnaka)" <noreply+hlinnaka@github.com>
2024-11-01 23:37 ` "ivanstepanovftw (@ivanstepanovftw)" <noreply+ivanstepanovftw@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