Add pgvector embeddings on cards, server-side cohere/embed-v4.0 via AI Gateway, kNN identify route, and L0→L1→L2 client orchestration with empty-index fast escalate and id-cursor backfill job. Co-authored-by: Cursor <cursoragent@cursor.com>
33 lines
896 B
JavaScript
33 lines
896 B
JavaScript
/**
|
|
* pgvector + cards.embedding for Layer-0 visual catalog search.
|
|
*
|
|
* @type {import('node-pg-migrate').ColumnDefinitions | undefined}
|
|
*/
|
|
export const shorthands = undefined;
|
|
|
|
/** Must match lib/card-embed.js EMBED_DIMENSION. */
|
|
const EMBED_DIMENSION = 1024;
|
|
|
|
/**
|
|
* @param {import('node-pg-migrate').MigrationBuilder} pgm
|
|
*/
|
|
export const up = (pgm) => {
|
|
pgm.sql(`
|
|
CREATE EXTENSION IF NOT EXISTS vector;
|
|
|
|
ALTER TABLE cards
|
|
ADD COLUMN IF NOT EXISTS embedding vector(${EMBED_DIMENSION}),
|
|
ADD COLUMN IF NOT EXISTS embedded_at TIMESTAMP;
|
|
|
|
CREATE INDEX IF NOT EXISTS idx_cards_embedding_hnsw
|
|
ON cards USING hnsw (embedding vector_cosine_ops)
|
|
WHERE embedding IS NOT NULL;
|
|
`);
|
|
};
|
|
|
|
/**
|
|
* @param {import('node-pg-migrate').MigrationBuilder} pgm
|
|
*/
|
|
export const down = (pgm) => {
|
|
throw new Error('Down migration not supported for add-card-embeddings');
|
|
};
|