function fromSql(value) { return value.substring(1, value.length - 1).split(',').map((v) => parseFloat(v));}function toSql(value) { return JSON.stringify(value);}
toSql
JSON.stringify
const value = sql`( ${sql.raw(`'[${vector}]'`)})`;sql`${sql.ref("embedding")} <=> ${value}`;
cosineDistance("embedding", vector);
kysely
pgvector-node
function cosineDistance(column, value) { return sql`${sql.ref(column)} <=> ${toSql(value)}`;}
const insertValue = sql`( ${sql.raw(`'${document.embedding}'`)}, ${document.text} )`; const result = await sql<Document>` INSERT INTO embedding (embedding, text) VALUES ${insertValue} RETURNING *`.execute(db); const row = result.rows[0];
sql`vector(3)`
vector