| 177 | |
| 178 | // Register the vector OID so parameter binding works with float[] input. |
| 179 | async function registerVectorType(pool) { |
| 180 | try { |
| 181 | const { rows } = await pool.query("SELECT oid FROM pg_type WHERE typname = 'vector'"); |
| 182 | if (rows.length > 0) { |
| 183 | const oid = rows[0].oid; |
| 184 | pg.types.setTypeParser(oid, (val) => val); |
| 185 | return oid; |
| 186 | } |
| 187 | } catch (e) { |
| 188 | // Extension not yet installed — will be created by initPgvector |
| 189 | } |
| 190 | return null; |
| 191 | } |
| 192 | |
| 193 | // Format a JS number array into pgvector literal syntax: [1.2, 3.4, ...] |
| 194 | function toVectorLiteral(arr) { |