2026-07-18 11:21:51 +02:00
|
|
|
-- Unified Search: Embedding columns and HNSW indexes
|
2026-08-04 22:47:26 +02:00
|
|
|
-- Note: These columns are also added by Alembic migration 0104.
|
|
|
|
|
-- This migration is idempotent (IF NOT EXISTS) and skips non-existent tables.
|
2026-07-18 11:21:51 +02:00
|
|
|
|
2026-07-24 14:23:28 +02:00
|
|
|
-- Ensure pgvector extension is installed
|
|
|
|
|
CREATE EXTENSION IF NOT EXISTS vector;
|
|
|
|
|
|
2026-07-18 11:21:51 +02:00
|
|
|
-- ─── Mails ───
|
2026-08-04 22:47:26 +02:00
|
|
|
DO $$ BEGIN
|
|
|
|
|
IF EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'mails') THEN
|
|
|
|
|
ALTER TABLE mails ADD COLUMN IF NOT EXISTS embedding vector(768);
|
|
|
|
|
CREATE INDEX IF NOT EXISTS ix_mails_embedding ON mails USING hnsw(embedding vector_cosine_ops);
|
|
|
|
|
END IF;
|
|
|
|
|
END $$;
|
2026-07-18 11:21:51 +02:00
|
|
|
|
|
|
|
|
-- ─── Contacts ───
|
2026-08-04 22:47:26 +02:00
|
|
|
DO $$ BEGIN
|
|
|
|
|
IF EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'contacts') THEN
|
|
|
|
|
ALTER TABLE contacts ADD COLUMN IF NOT EXISTS embedding vector(768);
|
|
|
|
|
CREATE INDEX IF NOT EXISTS ix_contacts_embedding ON contacts USING hnsw(embedding vector_cosine_ops);
|
|
|
|
|
END IF;
|
|
|
|
|
END $$;
|
2026-07-18 11:21:51 +02:00
|
|
|
|
2026-08-04 22:47:26 +02:00
|
|
|
-- ─── Files ───
|
|
|
|
|
DO $$ BEGIN
|
|
|
|
|
IF EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'files') THEN
|
|
|
|
|
ALTER TABLE files ADD COLUMN IF NOT EXISTS embedding vector(768);
|
|
|
|
|
CREATE INDEX IF NOT EXISTS ix_files_embedding ON files USING hnsw(embedding vector_cosine_ops);
|
|
|
|
|
END IF;
|
|
|
|
|
END $$;
|
2026-07-18 11:21:51 +02:00
|
|
|
|
|
|
|
|
-- ─── Calendar Entries ───
|
2026-08-04 22:47:26 +02:00
|
|
|
DO $$ BEGIN
|
|
|
|
|
IF EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'calendar_entries') THEN
|
|
|
|
|
ALTER TABLE calendar_entries ADD COLUMN IF NOT EXISTS embedding vector(768);
|
|
|
|
|
CREATE INDEX IF NOT EXISTS ix_cal_embedding ON calendar_entries USING hnsw(embedding vector_cosine_ops);
|
|
|
|
|
END IF;
|
|
|
|
|
END $$;
|
2026-07-18 11:21:51 +02:00
|
|
|
|
|
|
|
|
-- ─── Tags (shorter dimension for short text) ───
|
2026-08-04 22:47:26 +02:00
|
|
|
DO $$ BEGIN
|
|
|
|
|
IF EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'tags') THEN
|
|
|
|
|
ALTER TABLE tags ADD COLUMN IF NOT EXISTS embedding vector(384);
|
|
|
|
|
END IF;
|
|
|
|
|
END $$;
|