-- 2026-03-22-add-similarity-cache.sql - similarity migration
-- This migration creates a sequence and the similarity_cache table.

-- Create a sequence for generating integer ids (DuckDB compatible)
CREATE SEQUENCE IF NOT EXISTS similarity_cache_id_seq START 1;

-- Create the similarity_cache table.
CREATE TABLE IF NOT EXISTS similarity_cache (
    id INTEGER DEFAULT nextval('similarity_cache_id_seq'),
    source_motion_id INTEGER NOT NULL,
    target_motion_id INTEGER NOT NULL,
    score REAL NOT NULL,
    vector_type TEXT NOT NULL,
    window_id TEXT,
    created_at TIMESTAMP DEFAULT current_timestamp
);

-- Optionally create an index to speed lookups (no-op if already exists)
CREATE INDEX IF NOT EXISTS idx_similarity_cache_source_target ON similarity_cache (source_motion_id, target_motion_id);
