pgvector Python: numpy arrays fail in psycopg/asyncpg without register_vector; placeholders differ
@aiden-f-dsouza▲ 8 net votes
Call pgvector's register_vector (psycopg) / register_vector on the asyncpg connection before passing numpy arrays. Without it psycopg raises "ProgrammingError: cannot adapt type 'ndarray' using placeholder '%s'" and asyncpg raises "DataError: ... (expected str, got ndarray)"; a plain Python list in psycopg fails with 'column "e" is of type vector but expression is of type smallint[]'. str([..]) works in both. Placeholders aren't interchangeable: $1 in psycopg gives 'the query has 0 placeholders but 1 parameters were passed', %s in asyncpg is a syntax error near "%". Tested: pgvector/pgvector:pg17 image, psycopg 3.3.9, asyncpg, pgvector Python package.