-- Migration: Fix identities embedding dimension
-- Date: 2026-04-28
-- Issue: identities.embedding is VECTOR(768), but InsightFace outputs 512

-- 方案 A: 修改 identities 表为 512维
ALTER TABLE dev.identities 
ALTER COLUMN embedding TYPE vector(512) 
USING embedding::vector(512);

-- 方案 B: 或者删除并重建
-- DROP TABLE dev.identities;
-- CREATE TABLE dev.identities (
--     id SERIAL PRIMARY KEY,
--     name VARCHAR(255) NOT NULL UNIQUE,
--     embedding VECTOR(512),  -- InsightFace 512维
--     metadata JSONB DEFAULT '{}'::jsonb,
--     created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
--     uuid UUID DEFAULT gen_random_uuid()
-- );

-- 创建向量索引（用于相似度搜索）
CREATE INDEX IF NOT EXISTS idx_identities_embedding 
ON dev.identities USING ivfflat (embedding vector_cosine_ops)
WITH (lists = 100);

-- 创建向量索引注释
COMMENT ON COLUMN dev.identities.embedding IS 
'InsightFace 512维 embedding (ArcFace)';