-- Oracle 26ai setup for the Python-embedding backend (port 8001)
-- Run as SYSDBA connected to FREEPDB1
--
-- Usage (from host):
--   podman exec oracle.free bash -c "sqlplus -s / as sysdba @/tmp/setup_vectors_user.sql"
--
-- Or interactively:
--   podman exec -it oracle.free sqlplus / as sysdba
--   ALTER SESSION SET CONTAINER=FREEPDB1;
--   @setup_vectors_user.sql

ALTER SESSION SET CONTAINER=FREEPDB1;

-- Create user
CREATE USER vectors_user IDENTIFIED BY Vektor;
GRANT CONNECT, RESOURCE TO vectors_user;
GRANT UNLIMITED TABLESPACE TO vectors_user;

-- Switch to vectors_user and create schema objects
-- (run the following block connected as vectors_user)

-- Table
CREATE TABLE vectors_user.images (
    id        NUMBER GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
    filename  VARCHAR2(255) NOT NULL UNIQUE,
    filepath  VARCHAR2(1000) NOT NULL,
    embedding VECTOR(512, FLOAT32)
);

-- HNSW vector index (requires vector_memory_size > 0 in SGA)
CREATE VECTOR INDEX vectors_user.images_embedding_idx
    ON vectors_user.images(embedding)
    ORGANIZATION INMEMORY NEIGHBOR GRAPH
    WITH DISTANCE COSINE
    WITH TARGET ACCURACY 95
    PARAMETERS (type HNSW, neighbors 32, efconstruction 200);

EXIT;
