Skip to content

Fix halfvec table storage insert: wrap arrays in pgvector's HalfVector - #911

Merged
jamesgao-jpg merged 2 commits into
zilliztech:mainfrom
intel-staging:pgvector-halfvec-insert-fix
Nov 25, 2026
Merged

jamesgao-jpg merged 2 commits into
zilliztech:mainfrom
intel-staging:pgvector-halfvec-insert-fix

Conversation

@asonje

@asonje asonje commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Summary

Fix an insert failure when table_quantization_type=halfvec is used with the pgvector client. This has been broken since
table_quantization_type was introduced (#427) and has no test coverage, so it has gone unnoticed.

Root Cause

pgvector-python's HalfVectorDumper has no special case for a raw numpy.ndarray (unlike VectorDumper, which does accept one
directly). insert_embeddings's halfvec branch passes a bare np.float16(embeddings_arr[i]) into a column typed halfvec during
a binary COPY, which psycopg can't serialize:

AttributeError: 'numpy.ndarray' object has no attribute 'to_binary'

Fix

Wrap the array in pgvector.HalfVector(...) before handing it to copy.write_row, the type HalfVectorDumper actually knows how
to serialize. Same fix already applied to the pgsvs client's identical code path in #910.

Testing

Added test_insert_and_search_halfvec_table to tests/test_pgvector.py, mirroring the existing test_insert_and_search with
table_quantization_type="halfvec". Verified against pgvector/pgvector:pg17 in Docker:

  • Pre-fix: fails with the exact error above.
  • Post-fix: passes, along with the rest of the existing suite in that file (6/6).

pgvector-python's HalfVectorDumper has no special case for a raw
numpy.ndarray (unlike VectorDumper, which does), so a bare
np.float16(...) array passed into a column typed halfvec during a
binary COPY fails with "'numpy.ndarray' object has no attribute
'to_binary'". Wrap it in pgvector.HalfVector(...) first, same fix
already applied to pgsvs.py's identical code (PR zilliztech#910).

Add a regression test (test_insert_and_search_halfvec_table) mirroring
the existing test_insert_and_search, with table_quantization_type set
to halfvec. Verified against pgvector/pgvector:pg17 in Docker: fails
with the exact error above on the pre-fix code, passes after.

Signed-off-by: Olasoji <olasoji.denloye@intel.com>
@sre-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: asonje
To complete the pull request process, please assign xuanyang-cn after the PR has been reviewed.
You can assign the PR to them by writing /assign @xuanyang-cn in a comment when ready.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@asonje
asonje marked this pull request as ready for review November 20, 2026 22:02

import numpy as np
import psycopg
from pgvector import HalfVector

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for tracking down the halfvec insert failure. Could you change pgvector to pgvector>=0.4.0 in install/requirements_py3.11.txt and use the same minimum in the pgvector and test extras in pyproject.toml? I reproduced an import failure with 0.3.6 even for ordinary vector tables; 0.4.0 exports HalfVector at the package root.

We propose making VDBBench’s dependency requirements explicit one backend at a time, as changes establish which SDK versions are needed. This PR is a good first step: just declare the pgvector minimum here; no need to update unrelated dependencies.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

HalfVector moved to pgvector/__init__.py in 0.4.0; versions before
that only expose it under submodules like pgvector.utils.halfvec, so
`from pgvector import HalfVector` fails on anything older. Pin it in
install/requirements_py3.11.txt and the pgvector/test extras, the
only places that import HalfVector.

Signed-off-by: Olasoji <olasoji.denloye@intel.com>
@jamesgao-jpg
jamesgao-jpg merged commit b211bef into zilliztech:main Nov 25, 2026
4 checks passed
@asonje
asonje deleted the pgvector-halfvec-insert-fix branch November 25, 2026 13:52
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.

3 participants