pgvector / pgvector-python

pgvector support for Python
MIT License
886 stars 61 forks source link

register_vector() Fails When Only 'vector' Extension is Installed, Missing 'halfvec' and 'sparsevec #79

Closed vatsrahul1001 closed 2 months ago

vatsrahul1001 commented 2 months ago

Description:

After the 0.3.0 release, we have encountered an issue where the register_vector function throws an error if our PostgreSQL database only has the vector extension installed, and not halfvec or sparsevec.

Steps to Reproduce:

Install the pgvector extension in PostgreSQL without halfvec or sparsevec. Call the register_vector function. Error:

  File "/usr/local/lib/python3.9/site-packages/pgvector/psycopg2/register.py", line 23, in register_vector
    cur.execute('SELECT NULL::sparsevec')
psycopg2.errors.InFailedSqlTransaction: current transaction is aborted, commands ignored until end of transaction bloc

Expected Behavior:

The function should not break if halfvec or sparsevec are not present. It should work seamlessly with only the vector extension installed.

Link to Relevant Code:

register_vector

ankane commented 2 months ago

Hi @vatsrahul1001, thanks for reporting! Pushed a fix in the commit above (previous code only worked when autocommit was True).

ankane commented 2 months ago

Just released 0.3.1 with the fix.