-- Test 3: VectorChord / pgvector
\set ON_ERROR_STOP on

DROP TABLE IF EXISTS items;

CREATE TABLE items (
    id bigserial PRIMARY KEY, 
    embedding vector(3)
);

INSERT INTO items (embedding) VALUES ('[1,2,3]'), ('[4,5,6]'), ('[1.1, 2.1, 3.1]');

-- Create VectorChord Index
CREATE INDEX ON items USING vchordrq (embedding vector_l2_ops);

-- Search
DO $$
DECLARE
    closest_id int;
BEGIN
    SELECT id INTO closest_id FROM items ORDER BY embedding <-> '[1,2,3]' LIMIT 1;
    IF closest_id != 1 THEN
        RAISE EXCEPTION 'Vector search failed. Expected ID 1, got %', closest_id;
    END IF;
    RAISE NOTICE 'Vector Check: OK';
END
$$;
