-- Unified Search: Embedding columns and HNSW indexes

-- Ensure pgvector extension is installed
CREATE EXTENSION IF NOT EXISTS vector;

-- ─── Mails ───
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);

-- ─── Contacts ───
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);

-- ─── Companies ───
ALTER TABLE companies ADD COLUMN IF NOT EXISTS embedding vector(768);
CREATE INDEX IF NOT EXISTS ix_companies_embedding ON companies USING hnsw(embedding vector_cosine_ops);

-- ─── Files (content_text already added in 0001) ───
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);

-- ─── Calendar Entries ───
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);

-- ─── Tags (shorter dimension for short text) ───
ALTER TABLE tags ADD COLUMN IF NOT EXISTS embedding vector(384);
