Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update pgvector loading method to use binary format #488

Merged
merged 1 commit into from
Feb 29, 2024

Conversation

jkatz
Copy link
Contributor

@jkatz jkatz commented Jan 31, 2024

Particularly on large vector types, the pgvector module was spending significant time on converting floating point values to ASCII before being transmitted to the PostgreSQL server. This changes keeps the format in binary, reducing overhead. One test demonstrated a 63% reduction in load time, which would have an impact on the overall "build" time as reported by this benchmark.

Particularly on large vector types, the pgvector module was spending
significant time on converting floating point values to ASCII before
being transmitted to the PostgreSQL server. This changes keeps the
format in binary, reducing overhead. One test demonstrated a 63%
reduction in load time, which would have an impact on the overall
"build" time as reported by this benchmark.
@jkatz
Copy link
Contributor Author

jkatz commented Feb 1, 2024

Noting that of the automated tests, the pgvector one passed, which would be the key regression to check in this PR. Using the eyeball test with a few other open PRs, it looks like the test also completed more quickly, which can also be a side-effect of this PR, but there could be other factors at play with the runtime numbers.

@maumueller maumueller merged commit c091271 into erikbern:main Feb 29, 2024
35 of 41 checks passed
@maumueller
Copy link
Collaborator

Thanks!

@jkatz jkatz deleted the pgvector-copy-binary branch March 5, 2024 14:27
jkatz added a commit to jkatz/VectorDBBench that referenced this pull request Jun 14, 2024
PostgreSQL supports two methods of passing data from client to
server: text and binary. While for many data types the difference
may not be noticeable, we can see significant performance impact
when converting a vector from binary => text => binary representation.
See previous explanation here[1].

While the pgvector loading code accounts for this, the query code
did not. This is due to the use of a list[float] type, which
the pgvector-python adapter currently doesn't support. However,
this adapter does support direct binary transfer if the data
is represent as a Numpy array[2]. Testing shows that moving to
a direct binary representation does have a significant impact on
query results - my tests are showing a 3x impact --  and provides
a more accurate representation for how this workload would execute.

[1] erikbern/ann-benchmarks#488
[2] https://github.com/pgvector/pgvector-python?tab=readme-ov-file#psycopg-3
alwayslove2013 pushed a commit to zilliztech/VectorDBBench that referenced this pull request Jun 28, 2024
PostgreSQL supports two methods of passing data from client to
server: text and binary. While for many data types the difference
may not be noticeable, we can see significant performance impact
when converting a vector from binary => text => binary representation.
See previous explanation here[1].

While the pgvector loading code accounts for this, the query code
did not. This is due to the use of a list[float] type, which
the pgvector-python adapter currently doesn't support. However,
this adapter does support direct binary transfer if the data
is represent as a Numpy array[2]. Testing shows that moving to
a direct binary representation does have a significant impact on
query results - my tests are showing a 3x impact --  and provides
a more accurate representation for how this workload would execute.

[1] erikbern/ann-benchmarks#488
[2] https://github.com/pgvector/pgvector-python?tab=readme-ov-file#psycopg-3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants