deckhearth/migrations/1782000000001_add-card-embeddings.js
varutasu 8f09ed1ef6
feat(scanner): Layer-0 visual catalog search (Phase 3) (#160)
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>
2026-08-14 21:46:39 -05:00

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');
};