From: hlinnaka (@hlinnaka) <noreply+hlinnaka@github.com>
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Subject: Re: [pgvector/pgvector] issue #704: Discussion: understanding pgvector
Date: Thu, 31 Oct 2024 20:48:46 +0000
Message-ID: <gh-pgvector-pgvector-704-c2450790491@github.com> (raw)
In-Reply-To: <gh-pgvector-pgvector-704@github.com>
References: <gh-pgvector-pgvector-704@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.