-- DBMS_VECTOR: CREATE_CREDENTIAL / DROP_CREDENTIAL. -- Oracle-faithful: params carry the secret directly (username+password, -- access_token, or the OCI user_ocid/tenancy_ocid/private_key/fingerprint -- form; Oracle if/elsif precedence, pls:1290-1362); they are stored verbatim -- in SYS.vector_credentials and redacted at the SQL boundary. \! mkdir -p /tmp/kilo/dbms_vector -- happy path: access_token plus free-form passthrough params CALL dbms_vector_create_credential('openai_cred', '{"access_token": "sk-test-0600", "provider": "openai", "comment": "main credential"}'); SELECT credential_name, params FROM "SYS".all_vector_credentials ORDER BY credential_name; SELECT dbms_vector_get_credential('openai_cred') ->> 'access_token' AS access_token; SELECT dbms_vector_get_credential('openai_cred') ->> 'provider' AS provider; -- the table itself keeps the raw secret (superuser only) SELECT params ->> 'access_token' AS raw_access_token FROM "SYS".vector_credentials WHERE credential_name = 'openai_cred'; -- username/password and OCI forms are stored the same way CALL dbms_vector_create_credential('userpass', '{"username": "u", "password": "p"}'); CALL dbms_vector_create_credential('oci', '{"user_ocid": "ocid1.user..x", "tenancy_ocid": "ocid1.tenancy..x", "private_key": "k", "fingerprint": "aa:bb", "compartment_ocid": "ocid1.comp..x"}'); SELECT credential_name, params ->> 'username' AS username, params ->> 'password' AS password, params ->> 'private_key' AS private_key, params ->> 'fingerprint' AS fingerprint FROM "SYS".all_vector_credentials WHERE credential_name IN ('userpass', 'oci') ORDER BY credential_name; -- duplicate name CALL dbms_vector_create_credential('openai_cred', '{"access_token": "sk-test-0600"}'); -- params validation CALL dbms_vector_create_credential('null_params', NULL); CALL dbms_vector_create_credential('non_object', '["not", "an", "object"]'); CALL dbms_vector_create_credential('empty_token', '{"access_token": ""}'); CALL dbms_vector_create_credential('non_string_token', '{"access_token": 42}'); CALL dbms_vector_create_credential('empty_password', '{"username": "u", "password": ""}'); CALL dbms_vector_create_credential('non_string_fingerprint', '{"user_ocid": "ocid1.user..x", "tenancy_ocid": "ocid1.tenancy..x", "private_key": "k", "fingerprint": 42}'); CALL dbms_vector_create_credential('no_form', '{"provider": "openai"}'); CALL dbms_vector_create_credential('no_form_empty', '{}'); CALL dbms_vector_create_credential('half_userpass', '{"username": "u"}'); CALL dbms_vector_create_credential('partial_oci', '{"user_ocid": "ocid1.user..x", "tenancy_ocid": "ocid1.tenancy..x", "private_key": "k"}'); -- name validation CALL dbms_vector_create_credential('bad"name', '{"access_token": "sk-test-0600"}'); CALL dbms_vector_create_credential(NULL, NULL); CALL dbms_vector_drop_credential(NULL); -- qualified names: a superuser may manage a foreign owner CALL dbms_vector_create_credential('other_user.shared_cred', '{"access_token": "sk-test-0600"}'); SELECT dbms_vector_get_credential('other_user.shared_cred') ->> 'access_token' AS access_token; CALL dbms_vector_drop_credential('other_user.shared_cred'); -- a non-superuser cannot touch the credential catalog at all CREATE ROLE dbms_vector_user LOGIN; \set VERBOSITY sqlstate SET ROLE dbms_vector_user; CALL dbms_vector_create_credential('own_cred', '{"access_token": "sk-test-0600"}'); SELECT dbms_vector_get_credential('openai_cred'); \set VERBOSITY default RESET ROLE; DROP ROLE dbms_vector_user; -- get_credential of a missing credential SELECT dbms_vector_get_credential('no_such_cred'); -- drop CALL dbms_vector_drop_credential('userpass'); CALL dbms_vector_drop_credential('oci'); CALL dbms_vector_drop_credential('openai_cred'); CALL dbms_vector_drop_credential('openai_cred'); CALL dbms_vector_drop_credential('never_existed'); SELECT credential_name FROM "SYS".all_vector_credentials ORDER BY 1; -- =========================================================================== -- LOAD_ONNX_MODEL / DROP_ONNX_MODEL (catalog storage; on builds with the -- ONNX runtime the model bytes are validated at LOAD time, so the fake -- blobs below are then rejected - the tests assert flavor-consistent -- behavior through outcome tables instead of absolute messages). -- Flavor probe: 1 on --with-onnxruntime builds, 0 otherwise (not printed). SELECT dbms_vector_onnx_enabled()::int AS onnx \gset \! mkdir -p /tmp/kilo/dbms_vector/models \! printf '\010\006\022\004test' > /tmp/kilo/dbms_vector/models/model.onnx \! printf '\010\006' > /tmp/rudb_dbms_vector_smoke.onnx -- Load/drop outcomes per flavor: 'loaded'/'dropped' without the runtime, -- 'rejected' with it (real protobuf validation at LOAD). CREATE TEMP TABLE dbms_vector_outcomes(op text, outcome text); CREATE TEMP TABLE dbms_vector_expected(op text, want text); INSERT INTO dbms_vector_expected VALUES ('load_doc_model', CASE WHEN :'onnx'::int = 1 THEN 'rejected' ELSE 'loaded' END), ('load_defmeta_model', CASE WHEN :'onnx'::int = 1 THEN 'rejected' ELSE 'loaded' END), ('duplicate_doc_model', 'rejected'), ('load_dir_model', CASE WHEN :'onnx'::int = 1 THEN 'rejected' ELSE 'loaded' END), ('load_tempdir_model', CASE WHEN :'onnx'::int = 1 THEN 'rejected' ELSE 'loaded' END), ('drop_doc_model', CASE WHEN :'onnx'::int = 1 THEN 'rejected' ELSE 'dropped' END), ('drop_defmeta_model', CASE WHEN :'onnx'::int = 1 THEN 'rejected' ELSE 'dropped' END), ('drop_dir_model', CASE WHEN :'onnx'::int = 1 THEN 'rejected' ELSE 'dropped' END), ('drop_tempdir_model', CASE WHEN :'onnx'::int = 1 THEN 'rejected' ELSE 'dropped' END), ('superuser_foreign_owner', CASE WHEN :'onnx'::int = 1 THEN 'rejected' ELSE 'managed' END); -- BLOB overload: explicit metadata DO $$ BEGIN CALL dbms_vector_load_onnx_model('doc_model', '\x0806120474657374'::bytea, '{"function": "embedding", "source": "unit-test"}'); INSERT INTO dbms_vector_outcomes VALUES ('load_doc_model', 'loaded'); EXCEPTION WHEN OTHERS THEN INSERT INTO dbms_vector_outcomes VALUES ('load_doc_model', 'rejected'); END $$; -- BLOB overload: default metadata (NULL) DO $$ BEGIN CALL dbms_vector_load_onnx_model('defmeta_model', '\x0806'::bytea, NULL); INSERT INTO dbms_vector_outcomes VALUES ('load_defmeta_model', 'loaded'); EXCEPTION WHEN OTHERS THEN INSERT INTO dbms_vector_outcomes VALUES ('load_defmeta_model', 'rejected'); END $$; SELECT count(*) = CASE WHEN :'onnx'::int = 1 THEN 0 ELSE 2 END AS stored_models FROM "SYS".all_vector_models; SELECT count(*) = CASE WHEN :'onnx'::int = 1 THEN 0 ELSE 1 END AS doc_model_metadata FROM "SYS".all_vector_models WHERE model_name = 'doc_model' AND metadata ->> 'source' = 'unit-test'; -- duplicate model: rejected on both flavors (duplicate error without the -- runtime, validation error with it) DO $$ BEGIN CALL dbms_vector_load_onnx_model('doc_model', '\x0806'::bytea, NULL); INSERT INTO dbms_vector_outcomes VALUES ('duplicate_doc_model', 'loaded'); EXCEPTION WHEN OTHERS THEN INSERT INTO dbms_vector_outcomes VALUES ('duplicate_doc_model', 'rejected'); END $$; -- model data validation CALL dbms_vector_load_onnx_model('empty_model', '\x'::bytea, NULL); CALL dbms_vector_load_onnx_model('null_model', NULL, NULL); CALL dbms_vector_load_onnx_model(NULL, '\x0806'::bytea, NULL); -- metadata must be a JSON object CALL dbms_vector_load_onnx_model('badmeta_model', '\x0806'::bytea, '[1, 2]'); -- name validation CALL dbms_vector_load_onnx_model('bad"name', '\x0806'::bytea, NULL); CALL dbms_vector_drop_onnx_model(NULL, false); -- directory overload: absolute path DO $$ BEGIN CALL dbms_vector_load_onnx_model_dir('/tmp/kilo/dbms_vector/models', 'model.onnx', 'dir_model', '{"source": "directory"}'); INSERT INTO dbms_vector_outcomes VALUES ('load_dir_model', 'loaded'); EXCEPTION WHEN OTHERS THEN INSERT INTO dbms_vector_outcomes VALUES ('load_dir_model', 'rejected'); END $$; SELECT count(*) = CASE WHEN :'onnx'::int = 1 THEN 0 ELSE 1 END AS dir_model_metadata FROM "SYS".all_vector_models WHERE model_name = 'dir_model' AND metadata ->> 'source' = 'directory'; -- directory overload: TEMP_DIR alias (BFILE manager resolution) DO $$ BEGIN CALL dbms_vector_load_onnx_model_dir('TEMP_DIR', 'rudb_dbms_vector_smoke.onnx', 'tempdir_model', NULL); INSERT INTO dbms_vector_outcomes VALUES ('load_tempdir_model', 'loaded'); EXCEPTION WHEN OTHERS THEN INSERT INTO dbms_vector_outcomes VALUES ('load_tempdir_model', 'rejected'); END $$; SELECT count(*) = CASE WHEN :'onnx'::int = 1 THEN 0 ELSE 1 END AS tempdir_model_bytes FROM "SYS".all_vector_models WHERE model_name = 'tempdir_model' AND octet_length(model_data) = 2; -- qualified name: a superuser may manage a foreign owner (the load itself -- is rejected by validation on runtime builds) DO $$ BEGIN CALL dbms_vector_load_onnx_model('other_user.shared_model', '\x0806'::bytea, NULL); CALL dbms_vector_drop_onnx_model('other_user.shared_model', false); INSERT INTO dbms_vector_outcomes VALUES ('superuser_foreign_owner', 'managed'); EXCEPTION WHEN OTHERS THEN INSERT INTO dbms_vector_outcomes VALUES ('superuser_foreign_owner', 'rejected'); END $$; -- directory overload errors CALL dbms_vector_load_onnx_model_dir('/tmp/kilo/dbms_vector/models', 'no_such.onnx', 'missing_model', NULL); CALL dbms_vector_load_onnx_model_dir('/tmp/kilo/dbms_vector/../models', 'model.onnx', 'dotdot_model', NULL); CALL dbms_vector_load_onnx_model_dir('TEMP_DIR', '../secret.onnx', 'esc_model', NULL); CALL dbms_vector_load_onnx_model_dir('NO_SUCH_DIR', 'model.onnx', 'alias_model', NULL); CALL dbms_vector_load_onnx_model_dir(NULL, 'model.onnx', 'nulldir_model', NULL); CALL dbms_vector_load_onnx_model_dir('/tmp/kilo/dbms_vector/models', NULL, 'nullfile_model', NULL); CALL dbms_vector_load_onnx_model_dir('/tmp/kilo/dbms_vector', 'models', 'notfile_model', NULL); -- drop (doc_model was either loaded or rejected by validation above, so the -- second drop misses it on both flavors) DO $$ BEGIN CALL dbms_vector_drop_onnx_model('doc_model', false); INSERT INTO dbms_vector_outcomes VALUES ('drop_doc_model', 'dropped'); EXCEPTION WHEN OTHERS THEN INSERT INTO dbms_vector_outcomes VALUES ('drop_doc_model', 'rejected'); END $$; CALL dbms_vector_drop_onnx_model('doc_model', false); CALL dbms_vector_drop_onnx_model('never_existed', true); -- the internal helper is not exposed in pg_catalog; the flavor probe is SELECT count(*) FROM pg_proc WHERE proname = 'dbms_vector_get_onnx_model'; SELECT count(*) FROM pg_proc WHERE proname = 'dbms_vector_onnx_enabled'; SELECT dbms_vector_onnx_enabled() = (:'onnx'::int = 1) AS probe_consistent; DO $$ BEGIN CALL dbms_vector_drop_onnx_model('defmeta_model', false); INSERT INTO dbms_vector_outcomes VALUES ('drop_defmeta_model', 'dropped'); EXCEPTION WHEN OTHERS THEN INSERT INTO dbms_vector_outcomes VALUES ('drop_defmeta_model', 'rejected'); END $$; DO $$ BEGIN CALL dbms_vector_drop_onnx_model('dir_model', false); INSERT INTO dbms_vector_outcomes VALUES ('drop_dir_model', 'dropped'); EXCEPTION WHEN OTHERS THEN INSERT INTO dbms_vector_outcomes VALUES ('drop_dir_model', 'rejected'); END $$; DO $$ BEGIN CALL dbms_vector_drop_onnx_model('tempdir_model', false); INSERT INTO dbms_vector_outcomes VALUES ('drop_tempdir_model', 'dropped'); EXCEPTION WHEN OTHERS THEN INSERT INTO dbms_vector_outcomes VALUES ('drop_tempdir_model', 'rejected'); END $$; SELECT model_name FROM "SYS".all_vector_models ORDER BY 1; SELECT count(*) = 10 AND bool_and(o.outcome = e.want) AS outcomes_match_flavor FROM dbms_vector_outcomes o JOIN dbms_vector_expected e USING (op); -- =========================================================================== -- UTL_TO_EMBEDDING (REST core, OpenAI-compatible provider). \! rm -f /tmp/dbms_vector_fixture.pid /tmp/dbms_vector_fixture.log /tmp/kilo/dbms_vector/fixture_requests.log \! python3 "$PG_ABS_SRCDIR/dbms_vector_fixture.py" > /tmp/dbms_vector_fixture.log 2>&1 & echo $! > /tmp/dbms_vector_fixture.pid \! for attempt in $(seq 1 50); do python3 -c "import socket; s = socket.create_connection(('127.0.0.1', 18180), 1); s.close()" >/dev/null 2>&1 && exit 0; sleep 0.1; done; echo "DBMS_VECTOR fixture startup failed" >&2; exit 1 CALL dbms_vector_create_credential('openai_cred', '{"access_token": "sk-test-0600"}'); CALL dbms_vector_create_credential('wrongkey_cred', '{"access_token": "wrong-key"}'); CALL dbms_vector_create_credential('userpass_cred', '{"username": "u", "password": "p"}'); CALL dbms_vector_create_credential('oci_cred', '{"user_ocid": "ocid1.user..x", "tenancy_ocid": "ocid1.tenancy..x", "private_key": "k", "fingerprint": "aa:bb"}'); CALL dbms_vector_create_credential('mixed_cred', '{"username": "u", "password": "p", "access_token": "sk-test-0600"}'); -- happy path: passthrough keys (encoding_format, user) travel to the provider SELECT dbms_vector_utl_to_embedding('hello'::clob, '{"provider":"openai","url":"http://127.0.0.1:18180/v1/embeddings","model":"text-embedding-test","credential_name":"openai_cred","encoding_format":"float","user":"tester"}'); -- provider name is case-insensitive; oracle keys are not forwarded SELECT dbms_vector_utl_to_embedding('hi'::clob, '{"provider":"OPENAI","url":"http://127.0.0.1:18180/v1/embeddings","model":"text-embedding-test","credential_name":"openai_cred"}'); -- the result is a genuine vector SELECT '[5,1,0.25]'::vector <-> dbms_vector_utl_to_embedding('hello'::clob, '{"provider":"openai","url":"http://127.0.0.1:18180/v1/embeddings","model":"text-embedding-test","credential_name":"openai_cred"}'); -- the fixture saw the api key from the stored credential and the exact body keys \! cat /tmp/kilo/dbms_vector/fixture_requests.log -- provider 'database' (the default): errors on both flavors - the -- deferred-inference error without the runtime, the missing MODEL parameter -- (or the missing model row) with it CREATE TEMP TABLE dbms_vector_db_provider(op text, outcome text); DO $$ BEGIN PERFORM dbms_vector_utl_to_embedding('hello'::clob, NULL); INSERT INTO dbms_vector_db_provider VALUES ('embedding_default', 'succeeded'); EXCEPTION WHEN OTHERS THEN INSERT INTO dbms_vector_db_provider VALUES ('embedding_default', 'rejected'); END $$; DO $$ BEGIN PERFORM dbms_vector_utl_to_embedding('hello'::clob, '{"provider":"database"}'); INSERT INTO dbms_vector_db_provider VALUES ('embedding_database', 'succeeded'); EXCEPTION WHEN OTHERS THEN INSERT INTO dbms_vector_db_provider VALUES ('embedding_database', 'rejected'); END $$; -- with a model name the call reaches the model catalog and misses it on -- both flavors (deferred inference / model does not exist) DO $$ BEGIN PERFORM dbms_vector_utl_to_embedding('hello'::clob, '{"provider":"database","model":"no_such_model"}'); INSERT INTO dbms_vector_db_provider VALUES ('embedding_db_model', 'succeeded'); EXCEPTION WHEN OTHERS THEN INSERT INTO dbms_vector_db_provider VALUES ('embedding_db_model', 'rejected'); END $$; SELECT bool_and(outcome = 'rejected') AS db_provider_rejected FROM dbms_vector_db_provider; -- unknown / invalid provider SELECT dbms_vector_utl_to_embedding('hello'::clob, '{"provider":"cohere"}'); SELECT dbms_vector_utl_to_embedding('hello'::clob, '{"provider":42}'); SELECT dbms_vector_utl_to_embedding('hello'::clob, '["not", "an", "object"]'); -- data is required SELECT dbms_vector_utl_to_embedding(NULL, NULL); -- CHECK_REST_PARAMS parity: url / model / credential_name are required SELECT dbms_vector_utl_to_embedding('hello'::clob, '{"provider":"openai","model":"text-embedding-test","credential_name":"openai_cred"}'); SELECT dbms_vector_utl_to_embedding('hello'::clob, '{"provider":"openai","url":"http://127.0.0.1:18180/v1/embeddings","credential_name":"openai_cred"}'); SELECT dbms_vector_utl_to_embedding('hello'::clob, '{"provider":"openai","url":"http://127.0.0.1:18180/v1/embeddings","model":"text-embedding-test"}'); -- an empty value counts as missing (Oracle '' IS NULL) SELECT dbms_vector_utl_to_embedding('hello'::clob, '{"provider":"openai","url":"","model":"text-embedding-test","credential_name":"openai_cred"}'); -- unknown credential SELECT dbms_vector_utl_to_embedding('hello'::clob, '{"provider":"openai","url":"http://127.0.0.1:18180/v1/embeddings","model":"text-embedding-test","credential_name":"no_such_cred"}'); -- transfer_timeout validation SELECT dbms_vector_utl_to_embedding('hello'::clob, '{"provider":"openai","url":"http://127.0.0.1:18180/v1/embeddings","model":"text-embedding-test","credential_name":"openai_cred","transfer_timeout":-1}'); SELECT dbms_vector_utl_to_embedding('hello'::clob, '{"provider":"openai","url":"http://127.0.0.1:18180/v1/embeddings","model":"text-embedding-test","credential_name":"openai_cred","transfer_timeout":"ten"}'); -- wrong api key: provider answers 401, $.error.message is extracted SELECT dbms_vector_utl_to_embedding('hello'::clob, '{"provider":"openai","url":"http://127.0.0.1:18180/v1/embeddings","model":"text-embedding-test","credential_name":"wrongkey_cred"}'); -- username/password credentials have no bearer key (Oracle providers always -- send 'Bearer ' || KEY, pls:2253; this port raises a clear error instead) SELECT dbms_vector_utl_to_embedding('hello'::clob, '{"provider":"openai","url":"http://127.0.0.1:18180/v1/embeddings","model":"text-embedding-test","credential_name":"userpass_cred"}'); -- mixed params: userpass wins (Oracle if/elsif precedence, pls:1290) SELECT dbms_vector_utl_to_embedding('hello'::clob, '{"provider":"openai","url":"http://127.0.0.1:18180/v1/embeddings","model":"text-embedding-test","credential_name":"mixed_cred"}'); -- OCI credentials require request signing (deferred, pls:2529-2594) SELECT dbms_vector_utl_to_embedding('hello'::clob, '{"provider":"openai","url":"http://127.0.0.1:18180/v1/embeddings","model":"text-embedding-test","credential_name":"oci_cred"}'); -- HTTP 400 with $.error.message SELECT dbms_vector_utl_to_embedding('hello'::clob, '{"provider":"openai","url":"http://127.0.0.1:18180/v1/bad_request","model":"text-embedding-test","credential_name":"openai_cred"}'); -- HTTP 500 with a non-JSON body: the raw body is the message SELECT dbms_vector_utl_to_embedding('hello'::clob, '{"provider":"openai","url":"http://127.0.0.1:18180/v1/server_error","model":"text-embedding-test","credential_name":"openai_cred"}'); -- 200 without data: $.message / $.error / $.error[0] extraction SELECT dbms_vector_utl_to_embedding('hello'::clob, '{"provider":"openai","url":"http://127.0.0.1:18180/v1/message_error","model":"text-embedding-test","credential_name":"openai_cred"}'); SELECT dbms_vector_utl_to_embedding('hello'::clob, '{"provider":"openai","url":"http://127.0.0.1:18180/v1/plain_error","model":"text-embedding-test","credential_name":"openai_cred"}'); SELECT dbms_vector_utl_to_embedding('hello'::clob, '{"provider":"openai","url":"http://127.0.0.1:18180/v1/array_error","model":"text-embedding-test","credential_name":"openai_cred"}'); -- transfer_timeout applies to the whole request (fixture endpoint sleeps 3 s) SELECT dbms_vector_utl_to_embedding('hello'::clob, '{"provider":"openai","url":"http://127.0.0.1:18180/v1/slow","model":"text-embedding-test","credential_name":"openai_cred","transfer_timeout":1}'); -- =========================================================================== -- UTL_TO_EMBEDDINGS (CLOB and VECTOR_ARRAY_T overloads). \! rm -f /tmp/kilo/dbms_vector/fixture_requests.log -- CLOB overload: wrapped as the single chunk {"chunk_id":"1","chunk_data":...} SELECT dbms_vector_utl_to_embeddings('hello'::clob, '{"provider":"openai","url":"http://127.0.0.1:18180/v1/embeddings","model":"text-embedding-test","credential_name":"openai_cred"}'); -- the envelope carries embed_id / embed_data / embed_vector SELECT (dbms_vector_utl_to_embeddings('hello'::clob, '{"provider":"openai","url":"http://127.0.0.1:18180/v1/embeddings","model":"text-embedding-test","credential_name":"openai_cred"}'))[1]::jsonb ->> 'embed_id'; SELECT (dbms_vector_utl_to_embeddings('hello'::clob, '{"provider":"openai","url":"http://127.0.0.1:18180/v1/embeddings","model":"text-embedding-test","credential_name":"openai_cred"}'))[1]::jsonb ->> 'embed_data'; -- embed_vector is castable to vector SELECT ((dbms_vector_utl_to_embeddings('hello'::clob, '{"provider":"openai","url":"http://127.0.0.1:18180/v1/embeddings","model":"text-embedding-test","credential_name":"openai_cred"}'))[1]::jsonb ->> 'embed_vector')::vector <-> '[5,1,0.25]'::vector; -- array overload: batch_size 2 splits 3 chunks into 2 requests (fixture log) SELECT dbms_vector_utl_to_embeddings(array['{"chunk_id":"1","chunk_data":"aaaa"}','{"chunk_id":"2","chunk_data":"b"}','{"chunk_id":"3","chunk_data":"cc"}']::text[], '{"provider":"openai","url":"http://127.0.0.1:18180/v1/embeddings","model":"text-embedding-test","credential_name":"openai_cred","batch_size":2}'); \! cat /tmp/kilo/dbms_vector/fixture_requests.log -- batch_size 1: one request per chunk \! rm -f /tmp/kilo/dbms_vector/fixture_requests.log SELECT array_length(dbms_vector_utl_to_embeddings(array['{"chunk_id":"1","chunk_data":"aaaa"}','{"chunk_id":"2","chunk_data":"b"}']::text[], '{"provider":"openai","url":"http://127.0.0.1:18180/v1/embeddings","model":"text-embedding-test","credential_name":"openai_cred","batch_size":1}'), 1); \! cat /tmp/kilo/dbms_vector/fixture_requests.log -- chunk_id is passed through verbatim (numeric stays numeric) SELECT (dbms_vector_utl_to_embeddings(array['{"chunk_id":42,"chunk_data":"b"}']::text[], '{"provider":"openai","url":"http://127.0.0.1:18180/v1/embeddings","model":"text-embedding-test","credential_name":"openai_cred"}'))[1]::jsonb -> 'embed_id'; -- missing chunk_id becomes JSON null SELECT (dbms_vector_utl_to_embeddings(array['{"chunk_data":"b"}']::text[], '{"provider":"openai","url":"http://127.0.0.1:18180/v1/embeddings","model":"text-embedding-test","credential_name":"openai_cred"}'))[1]::jsonb -> 'embed_id'; -- empty input array SELECT dbms_vector_utl_to_embeddings('{}'::text[], '{"provider":"openai","url":"http://127.0.0.1:18180/v1/embeddings","model":"text-embedding-test","credential_name":"openai_cred"}'); -- batch_size validation SELECT dbms_vector_utl_to_embeddings(array['{"chunk_id":"1","chunk_data":"b"}']::text[], '{"provider":"openai","url":"http://127.0.0.1:18180/v1/embeddings","model":"text-embedding-test","credential_name":"openai_cred","batch_size":0}'); SELECT dbms_vector_utl_to_embeddings(array['{"chunk_id":"1","chunk_data":"b"}']::text[], '{"provider":"openai","url":"http://127.0.0.1:18180/v1/embeddings","model":"text-embedding-test","credential_name":"openai_cred","batch_size":"ten"}'); -- provider dispatch parity with UTL_TO_EMBEDDING (the 'database' cases -- error on both flavors and are recorded in dbms_vector_db_provider) DO $$ BEGIN PERFORM dbms_vector_utl_to_embeddings('hello'::clob, NULL); INSERT INTO dbms_vector_db_provider VALUES ('embeddings_default', 'succeeded'); EXCEPTION WHEN OTHERS THEN INSERT INTO dbms_vector_db_provider VALUES ('embeddings_default', 'rejected'); END $$; DO $$ BEGIN PERFORM dbms_vector_utl_to_embeddings('hello'::clob, '{"provider":"database","model":"no_such_model"}'); INSERT INTO dbms_vector_db_provider VALUES ('embeddings_db_model', 'succeeded'); EXCEPTION WHEN OTHERS THEN INSERT INTO dbms_vector_db_provider VALUES ('embeddings_db_model', 'rejected'); END $$; SELECT (bool_and(outcome = 'rejected') AND count(*) = 5) AS db_provider_all_rejected FROM dbms_vector_db_provider; SELECT dbms_vector_utl_to_embeddings('hello'::clob, '{"provider":"cohere"}'); SELECT dbms_vector_utl_to_embeddings(array['{"chunk_id":"1","chunk_data":"b"}']::text[], '{"provider":"cohere"}'); -- data is required SELECT dbms_vector_utl_to_embeddings(NULL, NULL); SELECT dbms_vector_utl_to_embeddings(NULL::text[], NULL); -- element validation SELECT dbms_vector_utl_to_embeddings(array['not json']::text[], '{"provider":"openai","url":"http://127.0.0.1:18180/v1/embeddings","model":"text-embedding-test","credential_name":"openai_cred"}'); SELECT dbms_vector_utl_to_embeddings(array['[1, 2]']::text[], '{"provider":"openai","url":"http://127.0.0.1:18180/v1/embeddings","model":"text-embedding-test","credential_name":"openai_cred"}'); SELECT dbms_vector_utl_to_embeddings(array['{"chunk_id":"1"}']::text[], '{"provider":"openai","url":"http://127.0.0.1:18180/v1/embeddings","model":"text-embedding-test","credential_name":"openai_cred"}'); SELECT dbms_vector_utl_to_embeddings(array['{"chunk_data":42}']::text[], '{"provider":"openai","url":"http://127.0.0.1:18180/v1/embeddings","model":"text-embedding-test","credential_name":"openai_cred"}'); SELECT dbms_vector_utl_to_embeddings(array[NULL]::text[], '{"provider":"openai","url":"http://127.0.0.1:18180/v1/embeddings","model":"text-embedding-test","credential_name":"openai_cred"}'); -- CHECK_REST_PARAMS parity on the batch path SELECT dbms_vector_utl_to_embeddings(array['{"chunk_id":"1","chunk_data":"b"}']::text[], '{"provider":"openai","model":"text-embedding-test","credential_name":"openai_cred"}'); -- provider errors keep the UTL_TO_EMBEDDING formatting on the batch path SELECT dbms_vector_utl_to_embeddings(array['{"chunk_id":"1","chunk_data":"b"}']::text[], '{"provider":"openai","url":"http://127.0.0.1:18180/v1/bad_request","model":"text-embedding-test","credential_name":"openai_cred"}'); CALL dbms_vector_drop_credential('openai_cred'); CALL dbms_vector_drop_credential('wrongkey_cred'); CALL dbms_vector_drop_credential('userpass_cred'); CALL dbms_vector_drop_credential('oci_cred'); CALL dbms_vector_drop_credential('mixed_cred'); -- =========================================================================== -- QUERY (dynamic SQL over the in-core vector distance operators; rows are -- inserted in shuffled order so the result order comes from the distance -- ORDER BY, not from storage). CREATE TABLE dbms_vector_query_tab (id int, t text, v vector(3)); INSERT INTO dbms_vector_query_tab VALUES (3, 'c', '[1,4,0]'), (1, 'a', '[0,1,2]'), (5, 'e', '[6,1,0]'), (2, 'b', '[3,0,1]'), (4, 'd', '[2,2,4]'); CREATE INDEX dbms_vector_query_tab_id_idx ON dbms_vector_query_tab (id); -- default metric EUCLIDEAN: whole row as JSON, nearest first SELECT dbms_vector_query('dbms_vector_query_tab', 'v', '[1,1,1]'::vector, 3) = '[{"t":"a","v":"[0,1,2]","id":1},{"t":"b","v":"[3,0,1]","id":2},{"t":"c","v":"[1,4,0]","id":3}]'::jsonb AS euclidean_top3; -- the text overload shares the vector path SELECT dbms_vector_query('dbms_vector_query_tab', 'v', '[1,1,1]'::text, 5) = dbms_vector_query('dbms_vector_query_tab', 'v', '[1,1,1]'::vector, 5) AS text_overload_ok; -- metric matrix (ids aggregated in result order) SELECT string_agg(x ->> 'id', ',' ORDER BY ord) AS euclidean FROM jsonb_array_elements(dbms_vector_query('dbms_vector_query_tab', 'v', '[1,1,1]'::vector, 5)) WITH ORDINALITY AS q(x, ord); SELECT string_agg(x ->> 'id', ',' ORDER BY ord) AS cosine FROM jsonb_array_elements(dbms_vector_query('dbms_vector_query_tab', 'v', '[1,1,1]'::vector, 5, NULL, NULL, 'COSINE')) WITH ORDINALITY AS q(x, ord); SELECT string_agg(x ->> 'id', ',' ORDER BY ord) AS dot FROM jsonb_array_elements(dbms_vector_query('dbms_vector_query_tab', 'v', '[1,1,1]'::vector, 5, NULL, NULL, 'DOT')) WITH ORDINALITY AS q(x, ord); SELECT string_agg(x ->> 'id', ',' ORDER BY ord) AS manhattan FROM jsonb_array_elements(dbms_vector_query('dbms_vector_query_tab', 'v', '[1,1,1]'::vector, 5, NULL, NULL, 'MANHATTAN')) WITH ORDINALITY AS q(x, ord); SELECT string_agg(x ->> 'id', ',' ORDER BY ord) AS l2sq FROM jsonb_array_elements(dbms_vector_query('dbms_vector_query_tab', 'v', '[1,1,1]'::vector, 5, NULL, NULL, 'EUCLIDEAN_SQUARED')) WITH ORDINALITY AS q(x, ord); -- the metric name is case-insensitive SELECT string_agg(x ->> 'id', ',' ORDER BY ord) AS cos_lower FROM jsonb_array_elements(dbms_vector_query('dbms_vector_query_tab', 'v', '[1,1,1]'::vector, 5, NULL, NULL, 'cosine')) WITH ORDINALITY AS q(x, ord); -- top_k SELECT string_agg(x ->> 'id', ',' ORDER BY ord) AS top3 FROM jsonb_array_elements(dbms_vector_query('dbms_vector_query_tab', 'v', '[1,1,1]'::vector, 3)) WITH ORDINALITY AS q(x, ord); SELECT dbms_vector_query('dbms_vector_query_tab', 'v', '[1,1,1]'::vector, 0) = '[]'::jsonb AS empty; SELECT string_agg(x ->> 'id', ',' ORDER BY ord) AS top100 FROM jsonb_array_elements(dbms_vector_query('dbms_vector_query_tab', 'v', '[1,1,1]'::vector, 100)) WITH ORDINALITY AS q(x, ord); -- vec_proj_cols selects specific columns instead of the whole row SELECT dbms_vector_query('dbms_vector_query_tab', 'v', '[1,1,1]'::vector, 3, '["id", "t"]') = '[{"t":"a","id":1},{"t":"b","id":2},{"t":"c","id":3}]'::jsonb AS projected; -- an empty vec_proj_cols behaves like NULL (whole row) SELECT dbms_vector_query('dbms_vector_query_tab', 'v', '[1,1,1]'::vector, 1, '[]') = '[{"t":"a","v":"[0,1,2]","id":1}]'::jsonb AS empty_proj; -- use_index = false forces an exact scan SELECT string_agg(x ->> 'id', ',' ORDER BY ord) AS exactscan FROM jsonb_array_elements(dbms_vector_query('dbms_vector_query_tab', 'v', '[1,1,1]'::vector, 5, NULL, NULL, 'EUCLIDEAN', false)) WITH ORDINALITY AS q(x, ord); -- idx_parameters map to hnsw.ef_search / ivfflat.probes around the query SELECT string_agg(x ->> 'id', ',' ORDER BY ord) AS efsearch FROM jsonb_array_elements(dbms_vector_query('dbms_vector_query_tab', 'v', '[1,1,1]'::vector, 5, NULL, NULL, 'EUCLIDEAN', true, 95, '{"efsearch": 40}')) WITH ORDINALITY AS q(x, ord); SELECT string_agg(x ->> 'id', ',' ORDER BY ord) AS probes FROM jsonb_array_elements(dbms_vector_query('dbms_vector_query_tab', 'v', '[1,1,1]'::vector, 5, NULL, NULL, 'EUCLIDEAN', true, 95, '{"neighbor partition probes": 2}')) WITH ORDINALITY AS q(x, ord); SELECT string_agg(x ->> 'id', ',' ORDER BY ord) AS gucs_both FROM jsonb_array_elements(dbms_vector_query('dbms_vector_query_tab', 'v', '[1,1,1]'::vector, 5, NULL, NULL, 'EUCLIDEAN', true, 95, '{"efsearch": 20, "neighbor partition probes": 1}')) WITH ORDINALITY AS q(x, ord); -- accuracy is accepted (and ignored) for Oracle signature parity SELECT string_agg(x ->> 'id', ',' ORDER BY ord) AS accuracy FROM jsonb_array_elements(dbms_vector_query('dbms_vector_query_tab', 'v', '[1,1,1]'::vector, 5, NULL, NULL, 'EUCLIDEAN', true, 80)) WITH ORDINALITY AS q(x, ord); -- idx_name is validated against the table (warning only, no hint forced) SELECT string_agg(x ->> 'id', ',' ORDER BY ord) AS idx_ok FROM jsonb_array_elements(dbms_vector_query('dbms_vector_query_tab', 'v', '[1,1,1]'::vector, 5, NULL, 'dbms_vector_query_tab_id_idx')) WITH ORDINALITY AS q(x, ord); SELECT string_agg(x ->> 'id', ',' ORDER BY ord) AS idx_warn FROM jsonb_array_elements(dbms_vector_query('dbms_vector_query_tab', 'v', '[1,1,1]'::vector, 5, NULL, 'no_such_idx')) WITH ORDINALITY AS q(x, ord); -- invalid metric (message parity with pls:857-864) SELECT dbms_vector_query('dbms_vector_query_tab', 'v', '[1,1,1]'::vector, 3, NULL, NULL, 'CHEBYSHEV'); -- HAMMING exists only for bit vectors (out of scope for this port) SELECT dbms_vector_query('dbms_vector_query_tab', 'v', '[1,1,1]'::vector, 3, NULL, NULL, 'HAMMING'); -- required arguments SELECT dbms_vector_query(NULL, 'v', '[1,1,1]'::vector, 3); SELECT dbms_vector_query('dbms_vector_query_tab', NULL, '[1,1,1]'::vector, 3); SELECT dbms_vector_query('dbms_vector_query_tab', 'v', NULL::vector, 3); SELECT dbms_vector_query('dbms_vector_query_tab', 'v', NULL::text, 3); SELECT dbms_vector_query('dbms_vector_query_tab', 'v', '[1,1,1]'::vector, NULL); -- identifiers must be simple SQL names (DBMS_ASSERT.SIMPLE_SQL_NAME parity) SELECT dbms_vector_query('public.dbms_vector_query_tab', 'v', '[1,1,1]'::vector, 3); SELECT dbms_vector_query('dbms_vector_query_tab', 'bad-name', '[1,1,1]'::vector, 3); -- the text overload validates the vector text through vector_in SELECT dbms_vector_query('dbms_vector_query_tab', 'v', 'nope', 3); -- vec_proj_cols must be an array of column name strings SELECT dbms_vector_query('dbms_vector_query_tab', 'v', '[1,1,1]'::vector, 3, '{"id": 1}'); SELECT dbms_vector_query('dbms_vector_query_tab', 'v', '[1,1,1]'::vector, 3, '[42]'); SELECT dbms_vector_query('dbms_vector_query_tab', 'v', '[1,1,1]'::vector, 3, '["bad-name"]'); -- query vector dimensions must match the column SELECT dbms_vector_query('dbms_vector_query_tab', 'v', '[1,1]'::vector, 3); -- top_k must be non-negative SELECT dbms_vector_query('dbms_vector_query_tab', 'v', '[1,1,1]'::vector, -1); -- idx_parameters must be an object of numbers >= 1 SELECT dbms_vector_query('dbms_vector_query_tab', 'v', '[1,1,1]'::vector, 3, NULL, NULL, 'EUCLIDEAN', true, 95, '[]'); SELECT dbms_vector_query('dbms_vector_query_tab', 'v', '[1,1,1]'::vector, 3, NULL, NULL, 'EUCLIDEAN', true, 95, '{"efsearch": 0}'); SELECT dbms_vector_query('dbms_vector_query_tab', 'v', '[1,1,1]'::vector, 3, NULL, NULL, 'EUCLIDEAN', true, 95, '{"efsearch": "big"}'); SELECT dbms_vector_query('dbms_vector_query_tab', 'v', '[1,1,1]'::vector, 3, NULL, NULL, 'EUCLIDEAN', true, 95, '{"neighbor partition probes": "many"}'); DROP TABLE dbms_vector_query_tab; -- =========================================================================== -- UTL_TO_CHUNKS (facade over the shared chunker core in dbms_vector_text.cpp; -- the string overloads need an explicit cast: clob vs varchar2) -- default params: one chunk per document, detail fields null without extended SELECT dbms_vector_utl_to_chunks('one two three'::clob); SELECT dbms_vector_utl_to_chunks('one two three'::clob, NULL::jsonb); -- extended fills chunk_offset / chunk_length; fixed windows with overlap SELECT dbms_vector_utl_to_chunks('abcdefghijklmnopqrstuvwxyz'::clob, '{"by": "chars", "max": 10, "overlap": 3, "split": "none", "extended": true}'::jsonb); -- the varchar2 overload chunks identically SELECT dbms_vector_utl_to_chunks('aa bb cc'::varchar2, '{"by": "words", "max": 2, "overlap": 1, "split": "none", "extended": true}'::jsonb); -- by words counts words, not characters SELECT jsonb_array_length(dbms_vector_utl_to_chunks('w1 w2 w3 w4 w5 w6 w7'::clob, '{"by": "words", "max": 3, "split": "none"}'::jsonb)::jsonb); -- empty input yields an empty document SELECT dbms_vector_utl_to_chunks(''::clob); -- split by newline: segments pack while they fit max SELECT dbms_vector_utl_to_chunks(E'aaa bbb\nccc ddd\neee'::clob, '{"max": 12, "split": "newline", "extended": true}'::jsonb); -- split by blankline keeps the blank line with the preceding paragraph SELECT dbms_vector_utl_to_chunks(E'para one\npara two\n\npara three'::clob, '{"split": "blankline", "max": 20, "extended": true}'::jsonb); -- split by sentence cuts after terminator + whitespace; decimals do not cut SELECT dbms_vector_utl_to_chunks('First sentence. Second one? Third!'::clob, '{"split": "sentence", "max": 17, "extended": true}'::jsonb); SELECT jsonb_array_length(dbms_vector_utl_to_chunks('3.14 is a number'::clob, '{"split": "sentence"}'::jsonb)::jsonb); -- split by custom keeps the delimiter at the end of the segment it closes SELECT dbms_vector_utl_to_chunks('rule one:rule two;rule three'::clob, '{"split": "custom", "custom_list": [":", ";"], "max": 10, "extended": true}'::jsonb); -- recursive split (default): blank lines, then newlines, then word boundaries SELECT dbms_vector_utl_to_chunks(E'aaa bbb ccc\nddd eee\nfff ggg'::clob, '{"by": "words", "max": 2, "extended": true}'::jsonb); -- normalize all: widechar to ASCII, punctuation dropped, whitespace collapsed SELECT dbms_vector_utl_to_chunks(' Hello, world! '::clob, '{"normalize": "all", "extended": true}'::jsonb); SELECT dbms_vector_utl_to_chunks('A B C'::clob, '{"normalize": "options", "norm_options": ["widechar", "punctuation"], "extended": true}'::jsonb); -- language is accepted (single generic tokenizer) and ignored SELECT jsonb_array_length(dbms_vector_utl_to_chunks('hello brave world'::clob, '{"language": "ENGLISH"}'::jsonb)::jsonb); -- param validation (Oracle parity messages) SELECT dbms_vector_utl_to_chunks('x'::clob, '{"by": "bytes"}'::jsonb); SELECT dbms_vector_utl_to_chunks('x'::clob, '{"max": "big"}'::jsonb); SELECT dbms_vector_utl_to_chunks('x'::clob, '{"max": 0}'::jsonb); SELECT dbms_vector_utl_to_chunks('x'::clob, '{"overlap": -1}'::jsonb); SELECT dbms_vector_utl_to_chunks('x'::clob, '{"max": 5, "overlap": 5}'::jsonb); SELECT dbms_vector_utl_to_chunks('x'::clob, '{"split": "everywhere"}'::jsonb); SELECT dbms_vector_utl_to_chunks('x'::clob, '{"split": "custom"}'::jsonb); SELECT dbms_vector_utl_to_chunks('x'::clob, '{"split": "custom", "custom_list": []}'::jsonb); SELECT dbms_vector_utl_to_chunks('x'::clob, '{"split": "custom", "custom_list": [42]}'::jsonb); SELECT dbms_vector_utl_to_chunks('x'::clob, '{"by": "vocabulary"}'::jsonb); SELECT dbms_vector_utl_to_chunks('x'::clob, '{"by": "vocabulary", "vocabulary": "my_vocab"}'::jsonb); SELECT dbms_vector_utl_to_chunks('x'::clob, '{"normalize": "sometimes"}'::jsonb); SELECT dbms_vector_utl_to_chunks('x'::clob, '{"normalize": "options"}'::jsonb); SELECT dbms_vector_utl_to_chunks('x'::clob, '{"normalize": "options", "norm_options": ["shouting"]}'::jsonb); SELECT dbms_vector_utl_to_chunks('x'::clob, '{"extended": "yes"}'::jsonb); SELECT dbms_vector_utl_to_chunks('x'::clob, '[]'::jsonb); SELECT dbms_vector_utl_to_chunks(NULL::clob); -- =========================================================================== -- UTL_TO_GENERATE_TEXT (facade over the shared generate-text core in -- dbms_vector_text.cpp; the fixture speaks the OpenAI protocol) CALL dbms_vector_create_credential('openai_gen', '{"access_token": "sk-test-0600"}'); CALL dbms_vector_create_credential('wrongkey_gen', '{"access_token": "wrong-key"}'); -- start from a clean fixture log \! rm -f /tmp/kilo/dbms_vector/fixture_requests.log -- chat shape: system + user messages, answer from $.choices[0].message.content SELECT dbms_vector_utl_to_generate_text('tell me about vectors'::clob, '{"provider":"openai","url":"http://127.0.0.1:18180/v1/chat/completions","model":"gpt-test","credential_name":"openai_gen","temperature":0.7,"user":"tester"}'); -- legacy shape: url contains v1/completions, prompt body, answer from $.choices[0].text SELECT dbms_vector_utl_to_generate_text('once upon a time'::clob, '{"provider":"openai","url":"http://127.0.0.1:18180/v1/completions","model":"gpt-test","credential_name":"openai_gen"}'); -- the fixture saw the bearer key, the model, the exact body keys and the -- prompt (reserved keys stripped, passthrough keys travel) \! cat /tmp/kilo/dbms_vector/fixture_requests.log \! rm -f /tmp/kilo/dbms_vector/fixture_requests.log -- provider is required (Oracle message parity, pls:2975) SELECT dbms_vector_utl_to_generate_text('hi'::clob); SELECT dbms_vector_utl_to_generate_text('hi'::clob, NULL::jsonb); SELECT dbms_vector_utl_to_generate_text('hi'::clob, '{"provider":""}'::jsonb); -- unsupported provider (pls:2972) SELECT dbms_vector_utl_to_generate_text('hi'::clob, '{"provider":"cohere"}'::jsonb); -- params must be a JSON object SELECT dbms_vector_utl_to_generate_text('hi'::clob, '["not", "an", "object"]'::jsonb); -- data is required SELECT dbms_vector_utl_to_generate_text(NULL::clob); -- CHECK_REST_PARAMS parity: url / model / credential_name are required SELECT dbms_vector_utl_to_generate_text('hi'::clob, '{"provider":"openai","model":"gpt-test","credential_name":"openai_gen"}'); SELECT dbms_vector_utl_to_generate_text('hi'::clob, '{"provider":"openai","url":"http://127.0.0.1:18180/v1/chat/completions","credential_name":"openai_gen"}'); SELECT dbms_vector_utl_to_generate_text('hi'::clob, '{"provider":"openai","url":"http://127.0.0.1:18180/v1/chat/completions","model":"gpt-test"}'); -- unknown credential (ORA-20001 parity) SELECT dbms_vector_utl_to_generate_text('hi'::clob, '{"provider":"openai","url":"http://127.0.0.1:18180/v1/chat/completions","model":"gpt-test","credential_name":"no_such_cred"}'); -- wrong api key: provider answers 401, $.error.message is extracted SELECT dbms_vector_utl_to_generate_text('hi'::clob, '{"provider":"openai","url":"http://127.0.0.1:18180/v1/chat/completions","model":"gpt-test","credential_name":"wrongkey_gen"}'); -- HTTP 400 with $.error.message SELECT dbms_vector_utl_to_generate_text('hi'::clob, '{"provider":"openai","url":"http://127.0.0.1:18180/v1/bad_request","model":"gpt-test","credential_name":"openai_gen"}'); -- HTTP 500 with a non-JSON body: the raw body is the message SELECT dbms_vector_utl_to_generate_text('hi'::clob, '{"provider":"openai","url":"http://127.0.0.1:18180/v1/server_error","model":"gpt-test","credential_name":"openai_gen"}'); -- 200 without choices: $.message extraction SELECT dbms_vector_utl_to_generate_text('hi'::clob, '{"provider":"openai","url":"http://127.0.0.1:18180/v1/message_error","model":"gpt-test","credential_name":"openai_gen"}'); -- transfer_timeout applies to the whole request (fixture endpoint sleeps 3 s) SELECT dbms_vector_utl_to_generate_text('hi'::clob, '{"provider":"openai","url":"http://127.0.0.1:18180/v1/slow","model":"gpt-test","credential_name":"openai_gen","transfer_timeout":1}'); CALL dbms_vector_drop_credential('openai_gen'); CALL dbms_vector_drop_credential('wrongkey_gen'); -- =========================================================================== -- CREATE_INDEX (generated DDL over the shared index mapping) CREATE TABLE dbms_vector_create_index_tab (id int, v vector(3), payload text); INSERT INTO dbms_vector_create_index_tab VALUES (1, '[1,2,3]', 'one'), (2, '[3,2,1]', 'two'), (3, '[0,0,1]', 'three'); -- hnsw with reloptions; the index name is uppercased (Oracle parity) CALL dbms_vector_create_index('vec_hnsw_idx', 'dbms_vector_create_index_tab', 'v', NULL, 'LOCAL', 'INMEMORY NEIGHBOR GRAPH', 'EUCLIDEAN', 95, '{"type":"HNSW","neighbors":8,"efConstruction":48}'::jsonb, 4, NULL); SELECT a.amname, oc.opcname, c.reloptions FROM pg_class c JOIN pg_am a ON a.oid = c.relam JOIN pg_index i ON i.indexrelid = c.oid JOIN pg_opclass oc ON oc.oid = i.indclass[0] WHERE c.relname = 'vec_hnsw_idx'; -- ivfflat with lists; NULL partitioning is the LOCAL default; COSINE maps to vector_cosine_ops CALL dbms_vector_create_index('vec_ivf_idx', 'dbms_vector_create_index_tab', 'v', NULL, NULL, 'NEIGHBOR PARTITIONS', 'COSINE', 95, '{"type":"IVF","partitions":5}'::jsonb, 4, NULL); SELECT a.amname, oc.opcname, c.reloptions FROM pg_class c JOIN pg_am a ON a.oid = c.relam JOIN pg_index i ON i.indexrelid = c.oid JOIN pg_opclass oc ON oc.oid = i.indclass[0] WHERE c.relname = 'vec_ivf_idx'; -- accuracy is accepted and logged only; DOT maps to vector_ip_ops CALL dbms_vector_create_index('vec_acc_idx', 'dbms_vector_create_index_tab', 'v', NULL, 'LOCAL', 'INMEMORY NEIGHBOR GRAPH', 'DOT', 80, '{"type":"HNSW","neighbors":8}'::jsonb, 4, NULL); SELECT a.amname, oc.opcname, c.reloptions FROM pg_class c JOIN pg_am a ON a.oid = c.relam JOIN pg_index i ON i.indexrelid = c.oid JOIN pg_opclass oc ON oc.oid = i.indclass[0] WHERE c.relname = 'vec_acc_idx'; -- parameter validation (Oracle parity messages) CALL dbms_vector_create_index('bad_org_idx', 'dbms_vector_create_index_tab', 'v', NULL, 'LOCAL', 'SPATIAL', 'EUCLIDEAN', 95, '{"type":"HNSW"}'::jsonb, 4, NULL); CALL dbms_vector_create_index('bad_part_idx', 'dbms_vector_create_index_tab', 'v', NULL, 'GLOBAL', 'INMEMORY NEIGHBOR GRAPH', 'EUCLIDEAN', 95, '{"type":"HNSW"}'::jsonb, 4, NULL); CALL dbms_vector_create_index('bad_metric_idx', 'dbms_vector_create_index_tab', 'v', NULL, 'LOCAL', 'INMEMORY NEIGHBOR GRAPH', 'CHEBYSHEV', 95, '{"type":"HNSW"}'::jsonb, 4, NULL); CALL dbms_vector_create_index('hamming_idx', 'dbms_vector_create_index_tab', 'v', NULL, 'LOCAL', 'INMEMORY NEIGHBOR GRAPH', 'HAMMING', 95, '{"type":"HNSW"}'::jsonb, 4, NULL); CALL dbms_vector_create_index('bad_type_idx', 'dbms_vector_create_index_tab', 'v', NULL, 'LOCAL', 'INMEMORY NEIGHBOR GRAPH', 'EUCLIDEAN', 95, '{"type":"XYZ"}'::jsonb, 4, NULL); CALL dbms_vector_create_index('mismatch_idx', 'dbms_vector_create_index_tab', 'v', NULL, 'LOCAL', 'INMEMORY NEIGHBOR GRAPH', 'EUCLIDEAN', 95, '{"type":"IVF","partitions":5}'::jsonb, 4, NULL); CALL dbms_vector_create_index('bad_neighbors_idx', 'dbms_vector_create_index_tab', 'v', NULL, 'LOCAL', 'INMEMORY NEIGHBOR GRAPH', 'EUCLIDEAN', 95, '{"type":"HNSW","neighbors":"eight"}'::jsonb, 4, NULL); CALL dbms_vector_create_index('bad_params_idx', 'dbms_vector_create_index_tab', 'v', NULL, 'LOCAL', 'INMEMORY NEIGHBOR GRAPH', 'EUCLIDEAN', 95, '["not", "an", "object"]'::jsonb, 4, NULL); -- required parameters are enforced in the C body (the SQL defaults hide them) CALL dbms_vector_create_index('bad_null_org', 'dbms_vector_create_index_tab', 'v', NULL, 'LOCAL', NULL, 'EUCLIDEAN', 95, '{"type":"HNSW"}'::jsonb, 4, NULL); CALL dbms_vector_create_index('bad_null_params', 'dbms_vector_create_index_tab', 'v', NULL, 'LOCAL', 'INMEMORY NEIGHBOR GRAPH', 'EUCLIDEAN', 95, NULL::jsonb, 4, NULL); -- identifiers are simple SQL names (DBMS_ASSERT.SIMPLE_SQL_NAME parity) CALL dbms_vector_create_index('bad', 'public.dbms_vector_create_index_tab', 'v', NULL, 'LOCAL', 'INMEMORY NEIGHBOR GRAPH', 'EUCLIDEAN', 95, '{"type":"HNSW"}'::jsonb, 4, NULL); CALL dbms_vector_create_index('bad', 'dbms_vector_create_index_tab', 'bad-name', NULL, 'LOCAL', 'INMEMORY NEIGHBOR GRAPH', 'EUCLIDEAN', 95, '{"type":"HNSW"}'::jsonb, 4, NULL); -- generated DDL failures surface the engine error when there is no fallback CALL dbms_vector_create_index('bad', 'dbms_vector_no_tab', 'v', NULL, 'LOCAL', 'INMEMORY NEIGHBOR GRAPH', 'EUCLIDEAN', 95, '{"type":"HNSW"}'::jsonb, 4, NULL); CALL dbms_vector_create_index('bad', 'dbms_vector_create_index_tab', 'nope', NULL, 'LOCAL', 'INMEMORY NEIGHBOR GRAPH', 'EUCLIDEAN', 95, '{"type":"HNSW"}'::jsonb, 4, NULL); -- INCLUDE is not supported by the vector access methods; without a -- fallback the engine error surfaces CALL dbms_vector_create_index('vec_inc_idx', 'dbms_vector_create_index_tab', 'v', 'payload', 'LOCAL', 'INMEMORY NEIGHBOR GRAPH', 'EUCLIDEAN', 95, '{"type":"HNSW"}'::jsonb, 4, NULL); -- with idx_ddl the escape hatch takes over (Oracle pls:659-666) CALL dbms_vector_create_index('vec_inc_idx', 'dbms_vector_create_index_tab', 'nope', 'payload', 'LOCAL', 'INMEMORY NEIGHBOR GRAPH', 'EUCLIDEAN', 95, '{"type":"HNSW"}'::jsonb, 4, 'CREATE INDEX vec_inc_fallback_idx ON dbms_vector_create_index_tab USING hnsw (v vector_l2_ops)'); SELECT count(*) AS fallback_created FROM pg_class WHERE relname = 'vec_inc_fallback_idx'; DROP INDEX vec_hnsw_idx; DROP INDEX vec_ivf_idx; DROP INDEX vec_acc_idx; DROP INDEX vec_inc_fallback_idx; DROP TABLE dbms_vector_create_index_tab; -- =========================================================================== -- REBUILD_INDEX (three-branch parity) CREATE TABLE dbms_vector_rebuild_tab (id int, v vector(3)); INSERT INTO dbms_vector_rebuild_tab VALUES (1, '[1,2,3]'), (2, '[3,2,1]'); CALL dbms_vector_create_index('vec_rebuild_idx', 'dbms_vector_rebuild_tab', 'v', NULL, 'LOCAL', 'INMEMORY NEIGHBOR GRAPH', 'EUCLIDEAN', 95, '{"type":"HNSW","neighbors":8,"efConstruction":48}'::jsonb, 4, NULL); -- branch (c): no overrides re-executes the stored DDL verbatim CALL dbms_vector_rebuild_index('vec_rebuild_idx'); SELECT a.amname, oc.opcname, c.reloptions, i.indisvalid FROM pg_class c JOIN pg_am a ON a.oid = c.relam JOIN pg_index i ON i.indexrelid = c.oid JOIN pg_opclass oc ON oc.oid = i.indclass[0] WHERE c.relname = 'vec_rebuild_idx'; -- branch (b) parameters override: patched reloptions are visible CALL dbms_vector_rebuild_index('vec_rebuild_idx', NULL, NULL, NULL, 'LOCAL', NULL, 'EUCLIDEAN', 95, '{"type":"HNSW","neighbors":16,"efConstruction":64}'::jsonb, 4); SELECT a.amname, oc.opcname, c.reloptions, i.indisvalid FROM pg_class c JOIN pg_am a ON a.oid = c.relam JOIN pg_index i ON i.indexrelid = c.oid JOIN pg_opclass oc ON oc.oid = i.indclass[0] WHERE c.relname = 'vec_rebuild_idx'; -- branch (b) metric override rewrites the operator class, keeping the keys CALL dbms_vector_rebuild_index('vec_rebuild_idx', NULL, NULL, NULL, 'LOCAL', NULL, 'COSINE', 95, NULL::jsonb, 4); SELECT a.amname, oc.opcname, c.reloptions, i.indisvalid FROM pg_class c JOIN pg_am a ON a.oid = c.relam JOIN pg_index i ON i.indexrelid = c.oid JOIN pg_opclass oc ON oc.oid = i.indclass[0] WHERE c.relname = 'vec_rebuild_idx'; -- branch (b) organization override switches the engine (hnsw -> ivfflat) CALL dbms_vector_rebuild_index('vec_rebuild_idx', NULL, NULL, NULL, 'LOCAL', 'NEIGHBOR PARTITIONS', 'EUCLIDEAN', 95, '{"type":"IVF","partitions":4}'::jsonb, 4); SELECT a.amname, oc.opcname, c.reloptions, i.indisvalid FROM pg_class c JOIN pg_am a ON a.oid = c.relam JOIN pg_index i ON i.indexrelid = c.oid JOIN pg_opclass oc ON oc.oid = i.indclass[0] WHERE c.relname = 'vec_rebuild_idx'; -- branch (b) parallel_creation alone still triggers the rebuild CALL dbms_vector_rebuild_index('vec_rebuild_idx', NULL, NULL, NULL, 'LOCAL', NULL, 'EUCLIDEAN', 95, NULL::jsonb, 8); SELECT a.amname, oc.opcname, c.reloptions, i.indisvalid FROM pg_class c JOIN pg_am a ON a.oid = c.relam JOIN pg_index i ON i.indexrelid = c.oid JOIN pg_opclass oc ON oc.oid = i.indclass[0] WHERE c.relname = 'vec_rebuild_idx'; -- branch (a): full parameters drop + re-run the CREATE_INDEX core CALL dbms_vector_rebuild_index('vec_rebuild_idx', 'dbms_vector_rebuild_tab', 'v', NULL, 'LOCAL', 'INMEMORY NEIGHBOR GRAPH', 'DOT', 90, '{"type":"HNSW","neighbors":12}'::jsonb, 4); SELECT a.amname, oc.opcname, c.reloptions, i.indisvalid FROM pg_class c JOIN pg_am a ON a.oid = c.relam JOIN pg_index i ON i.indexrelid = c.oid JOIN pg_opclass oc ON oc.oid = i.indclass[0] WHERE c.relname = 'vec_rebuild_idx'; -- branch (a) with a failing generated DDL: the stored-DDL fallback of the -- CREATE_INDEX core recreates the previous state CALL dbms_vector_rebuild_index('vec_rebuild_idx', 'dbms_vector_rebuild_tab', 'nope', NULL, 'LOCAL', 'INMEMORY NEIGHBOR GRAPH', 'DOT', 95, '{"type":"HNSW","neighbors":12}'::jsonb, 4); SELECT a.amname, oc.opcname, c.reloptions, i.indisvalid FROM pg_class c JOIN pg_am a ON a.oid = c.relam JOIN pg_index i ON i.indexrelid = c.oid JOIN pg_opclass oc ON oc.oid = i.indclass[0] WHERE c.relname = 'vec_rebuild_idx'; -- nonexistent index CALL dbms_vector_rebuild_index('no_such_rebuild_idx'); -- non-vector index CREATE INDEX vec_rebuild_btree ON dbms_vector_rebuild_tab (id); CALL dbms_vector_rebuild_index('vec_rebuild_btree'); -- validation parity on the overrides (nothing is dropped on failure) CALL dbms_vector_rebuild_index('vec_rebuild_idx', NULL, NULL, NULL, 'LOCAL', 'NEIGHBOR PARTITIONS', 'HAMMING', 95, '{"type":"IVF","partitions":4}'::jsonb, 4); SELECT i.indisvalid FROM pg_index i JOIN pg_class c ON c.oid = i.indexrelid WHERE c.relname = 'vec_rebuild_idx'; DROP INDEX vec_rebuild_idx; DROP INDEX vec_rebuild_btree; DROP TABLE dbms_vector_rebuild_tab; -- =========================================================================== -- GET_INDEX_STATUS (state derivation + lookup errors) CREATE TABLE dbms_vector_status_tab (id int, v vector(3)); INSERT INTO dbms_vector_status_tab VALUES (1, '[1,2,3]'), (2, '[3,2,1]'); CALL dbms_vector_create_index('vec_status_idx', 'dbms_vector_status_tab', 'v', NULL, 'LOCAL', 'INMEMORY NEIGHBOR GRAPH', 'EUCLIDEAN', 95, '{"type":"HNSW","neighbors":8}'::jsonb, 4, NULL); -- valid index reports COMPLETED; the name folds case-insensitively SELECT dbms_vector_get_index_status('vec_status_idx'); SELECT dbms_vector_get_index_status('VEC_STATUS_IDX'); -- !indisvalid reports FAILED (direct catalog poke as superuser) UPDATE pg_index SET indisvalid = false WHERE indexrelid = 'vec_status_idx'::regclass; SELECT dbms_vector_get_index_status('vec_status_idx'); UPDATE pg_index SET indisvalid = true WHERE indexrelid = 'vec_status_idx'::regclass; -- missing index / non-vector index / NULL name SELECT dbms_vector_get_index_status('no_such_status_idx'); CREATE INDEX vec_status_btree ON dbms_vector_status_tab (id); SELECT dbms_vector_get_index_status('vec_status_btree'); SELECT dbms_vector_get_index_status(NULL); DROP INDEX vec_status_idx; DROP INDEX vec_status_btree; DROP TABLE dbms_vector_status_tab; -- =========================================================================== -- INDEX_VECTOR_MEMORY_ADVISOR (estimate formulas; before-create mode) CREATE TABLE dbms_vector_adv_tab (id int, v vector(3)); INSERT INTO dbms_vector_adv_tab VALUES (1, '[1,2,3]'), (2, '[3,2,1]'); ANALYZE dbms_vector_adv_tab; -- hnsw m=8 over dim 3: per row 3*8 + 8*24 = 216 bytes; 2 rows CALL dbms_vector_create_index('vec_adv_idx', 'dbms_vector_adv_tab', 'v', NULL, 'LOCAL', 'INMEMORY NEIGHBOR GRAPH', 'EUCLIDEAN', 95, '{"type":"HNSW","neighbors":8}'::jsonb, 4, NULL); SELECT dbms_vector_index_vector_memory_advisor('vec_adv_idx', NULL); -- the estimate is monotonic in m (neighbors 16 doubles the link layer) CALL dbms_vector_create_index('vec_adv2_idx', 'dbms_vector_adv_tab', 'v', NULL, 'LOCAL', 'INMEMORY NEIGHBOR GRAPH', 'EUCLIDEAN', 95, '{"type":"HNSW","neighbors":16}'::jsonb, 4, NULL); SELECT dbms_vector_index_vector_memory_advisor('vec_adv2_idx', NULL); -- ivfflat lists=4: vectors (12/row) plus 4 centroids of 12 bytes CALL dbms_vector_create_index('vec_adv_ivf_idx', 'dbms_vector_adv_tab', 'v', NULL, 'LOCAL', 'NEIGHBOR PARTITIONS', 'EUCLIDEAN', 95, '{"type":"IVF","partitions":4}'::jsonb, 4, NULL); SELECT dbms_vector_index_vector_memory_advisor('vec_adv_ivf_idx', NULL); -- before-create mode: table without an index, hnsw with the default m=16 CREATE TABLE dbms_vector_adv2_tab (id int, v vector(3)); INSERT INTO dbms_vector_adv2_tab VALUES (1, '[1,1,1]'), (2, '[2,2,2]'), (3, '[3,3,3]'); ANALYZE dbms_vector_adv2_tab; SELECT dbms_vector_index_vector_memory_advisor(NULL, 'dbms_vector_adv2_tab'); -- an unresolved idx_name with a table is also the before-create mode SELECT dbms_vector_index_vector_memory_advisor('never_created_idx', 'dbms_vector_adv2_tab'); -- error paths SELECT dbms_vector_index_vector_memory_advisor('never_created_idx', NULL); CREATE TABLE dbms_vector_adv_plain (id int, payload text); SELECT dbms_vector_index_vector_memory_advisor(NULL, 'dbms_vector_adv_plain'); SELECT dbms_vector_index_vector_memory_advisor(NULL, 'dbms_vector_no_tab'); SELECT dbms_vector_index_vector_memory_advisor(NULL, NULL); DROP INDEX vec_adv_idx; DROP INDEX vec_adv2_idx; DROP INDEX vec_adv_ivf_idx; DROP TABLE dbms_vector_adv_tab; DROP TABLE dbms_vector_adv2_tab; DROP TABLE dbms_vector_adv_plain; -- =========================================================================== -- ENABLE/DISABLE_CHECKPOINT (stage 1: persisted state, no AM behavior) CREATE TABLE dbms_vector_ckpt_tab (id int, v vector(3)); INSERT INTO dbms_vector_ckpt_tab VALUES (1, '[1,2,3]'), (2, '[3,2,1]'); CALL dbms_vector_create_index('vec_ckpt_idx', 'dbms_vector_ckpt_tab', 'v', NULL, 'LOCAL', 'INMEMORY NEIGHBOR GRAPH', 'EUCLIDEAN', 95, '{"type":"HNSW","neighbors":8}'::jsonb, 4, NULL); -- per-index disable: SYS row plus the reloption mirror CALL dbms_vector_disable_checkpoint('vec_ckpt_idx'); SELECT idx_schema, idx_name, enabled FROM "SYS".vector_index_checkpointing WHERE idx_name = 'vec_ckpt_idx'; SELECT reloptions FROM pg_class WHERE relname = 'vec_ckpt_idx'; -- enable back CALL dbms_vector_enable_checkpoint('vec_ckpt_idx'); SELECT idx_schema, idx_name, enabled FROM "SYS".vector_index_checkpointing WHERE idx_name = 'vec_ckpt_idx'; SELECT reloptions FROM pg_class WHERE relname = 'vec_ckpt_idx'; -- an invalid index must not crash the toggle UPDATE pg_index SET indisvalid = false WHERE indexrelid = 'vec_ckpt_idx'::regclass; CALL dbms_vector_disable_checkpoint('vec_ckpt_idx'); SELECT idx_name, enabled FROM "SYS".vector_index_checkpointing WHERE idx_name = 'vec_ckpt_idx'; UPDATE pg_index SET indisvalid = true WHERE indexrelid = 'vec_ckpt_idx'::regclass; CALL dbms_vector_enable_checkpoint('vec_ckpt_idx'); -- cluster-wide toggle: the sentinel row CALL dbms_vector_disable_checkpoint(NULL); SELECT idx_schema, idx_name, enabled FROM "SYS".vector_index_checkpointing WHERE idx_schema = '*'; CALL dbms_vector_enable_checkpoint(NULL); SELECT idx_schema, idx_name, enabled FROM "SYS".vector_index_checkpointing WHERE idx_schema = '*'; -- unknown index CALL dbms_vector_enable_checkpoint('no_such_ckpt_idx'); -- permission checks: a non-owner non-superuser is rejected CREATE ROLE dbms_vector_ckpt_stranger; SET ROLE dbms_vector_ckpt_stranger; CALL dbms_vector_enable_checkpoint('vec_ckpt_idx'); CALL dbms_vector_disable_checkpoint(NULL); RESET ROLE; -- the build still completes with checkpointing disabled (stage 1 is a -- behavioral no-op beyond state) CALL dbms_vector_disable_checkpoint('vec_ckpt_idx'); INSERT INTO dbms_vector_ckpt_tab VALUES (3, '[0,1,0]'); DROP INDEX vec_ckpt_idx; CALL dbms_vector_create_index('vec_ckpt_idx', 'dbms_vector_ckpt_tab', 'v', NULL, 'LOCAL', 'INMEMORY NEIGHBOR GRAPH', 'EUCLIDEAN', 95, '{"type":"HNSW","neighbors":8}'::jsonb, 4, NULL); SELECT i.indisvalid FROM pg_index i JOIN pg_class c ON c.oid = i.indexrelid WHERE c.relname = 'vec_ckpt_idx'; DROP INDEX vec_ckpt_idx; DROP TABLE dbms_vector_ckpt_tab; DELETE FROM "SYS".vector_index_checkpointing; DROP ROLE dbms_vector_ckpt_stranger; -- =========================================================================== -- INMEMORY_ONNX_MODEL (per-backend ONNX session cache pin; flavor-gated -- outcomes like the LOAD/DROP section above) -- missing model: flavor-independent (the catalog lookup raises first) CALL dbms_vector_inmemory_onnx_model('never_loaded_pin_model'); CALL dbms_vector_inmemory_onnx_model(NULL); CREATE TEMP TABLE dbms_vector_pin_outcomes(op text, outcome text); CREATE TEMP TABLE dbms_vector_pin_expected(op text, want text); INSERT INTO dbms_vector_pin_expected VALUES ('load_pin_model', CASE WHEN :'onnx'::int = 1 THEN 'rejected' ELSE 'loaded' END), ('pin_pin_model', 'rejected'), ('pin_pin_model_params', 'rejected'), ('stranger_pin_model', 'rejected'), ('cleanup_drop_model', CASE WHEN :'onnx'::int = 1 THEN 'rejected' ELSE 'dropped' END); DO $$ BEGIN CALL dbms_vector_load_onnx_model('pin_model', '\x0806'::bytea, NULL); INSERT INTO dbms_vector_pin_outcomes VALUES ('load_pin_model', 'loaded'); EXCEPTION WHEN OTHERS THEN INSERT INTO dbms_vector_pin_outcomes VALUES ('load_pin_model', 'rejected'); END $$; -- pin: rejected on both flavors (no runtime vs no stored model) DO $$ BEGIN CALL dbms_vector_inmemory_onnx_model('pin_model'); INSERT INTO dbms_vector_pin_outcomes VALUES ('pin_pin_model', 'pinned'); EXCEPTION WHEN OTHERS THEN INSERT INTO dbms_vector_pin_outcomes VALUES ('pin_pin_model', 'rejected'); END $$; -- the params argument is accepted and ignored (same outcome) DO $$ BEGIN CALL dbms_vector_inmemory_onnx_model('pin_model', '{"anything": 1}'::jsonb); INSERT INTO dbms_vector_pin_outcomes VALUES ('pin_pin_model_params', 'pinned'); EXCEPTION WHEN OTHERS THEN INSERT INTO dbms_vector_pin_outcomes VALUES ('pin_pin_model_params', 'rejected'); END $$; -- a non-owner is rejected by the catalog lookup on both flavors CREATE ROLE dbms_vector_pin_stranger; GRANT INSERT, SELECT ON dbms_vector_pin_outcomes TO dbms_vector_pin_stranger; SET ROLE dbms_vector_pin_stranger; DO $$ BEGIN CALL dbms_vector_inmemory_onnx_model('pin_model'); INSERT INTO dbms_vector_pin_outcomes VALUES ('stranger_pin_model', 'pinned'); EXCEPTION WHEN OTHERS THEN INSERT INTO dbms_vector_pin_outcomes VALUES ('stranger_pin_model', 'rejected'); END $$; RESET ROLE; REVOKE INSERT, SELECT ON dbms_vector_pin_outcomes FROM dbms_vector_pin_stranger; DROP ROLE dbms_vector_pin_stranger; DO $$ BEGIN CALL dbms_vector_drop_onnx_model('pin_model', false); INSERT INTO dbms_vector_pin_outcomes VALUES ('cleanup_drop_model', 'dropped'); EXCEPTION WHEN OTHERS THEN INSERT INTO dbms_vector_pin_outcomes VALUES ('cleanup_drop_model', 'rejected'); END $$; SELECT bool_and(o.outcome = e.want) AS pin_matrix_ok FROM dbms_vector_pin_outcomes o JOIN dbms_vector_pin_expected e USING (op); -- =========================================================================== -- Index lifecycle: create -> status -> advisor -> rebuild -> checkpoint CREATE TABLE dbms_vector_lifecycle_tab (id int, v vector(3), payload text); INSERT INTO dbms_vector_lifecycle_tab VALUES (1, '[1,2,3]', 'one'), (2, '[3,2,1]', 'two'), (3, '[0,0,1]', 'three'); ANALYZE dbms_vector_lifecycle_tab; CALL dbms_vector_create_index('vec_lifecycle_idx', 'dbms_vector_lifecycle_tab', 'v', NULL, 'LOCAL', 'INMEMORY NEIGHBOR GRAPH', 'EUCLIDEAN', 95, '{"type":"HNSW","neighbors":8,"efConstruction":48}'::jsonb, 4, NULL); SELECT a.amname, oc.opcname, c.reloptions, (dbms_vector_get_index_status('vec_lifecycle_idx') ->> 'state') AS state, (dbms_vector_index_vector_memory_advisor('vec_lifecycle_idx') ->> 'estimated_bytes') AS est_bytes FROM pg_class c JOIN pg_am a ON a.oid = c.relam JOIN pg_index i ON i.indexrelid = c.oid JOIN pg_opclass oc ON oc.oid = i.indclass[0] WHERE c.relname = 'vec_lifecycle_idx'; CALL dbms_vector_rebuild_index('vec_lifecycle_idx', NULL, NULL, NULL, 'LOCAL', 'NEIGHBOR PARTITIONS', 'EUCLIDEAN', 95, '{"type":"IVF","partitions":4}'::jsonb, 4); SELECT a.amname, oc.opcname, c.reloptions, (dbms_vector_get_index_status('vec_lifecycle_idx') ->> 'state') AS state, (dbms_vector_index_vector_memory_advisor('vec_lifecycle_idx') ->> 'estimated_bytes') AS est_bytes FROM pg_class c JOIN pg_am a ON a.oid = c.relam JOIN pg_index i ON i.indexrelid = c.oid JOIN pg_opclass oc ON oc.oid = i.indclass[0] WHERE c.relname = 'vec_lifecycle_idx'; CALL dbms_vector_disable_checkpoint('vec_lifecycle_idx'); CALL dbms_vector_rebuild_index('vec_lifecycle_idx'); SELECT (dbms_vector_get_index_status('vec_lifecycle_idx') ->> 'state') AS state, c.reloptions FROM pg_class c WHERE c.relname = 'vec_lifecycle_idx'; CALL dbms_vector_enable_checkpoint('vec_lifecycle_idx'); SELECT enabled FROM "SYS".vector_index_checkpointing WHERE idx_name = 'vec_lifecycle_idx'; DROP INDEX vec_lifecycle_idx; DROP TABLE dbms_vector_lifecycle_tab; DELETE FROM "SYS".vector_index_checkpointing; \! test ! -f /tmp/dbms_vector_fixture.pid || kill "$(cat /tmp/dbms_vector_fixture.pid)" 2>/dev/null || true; rm -f /tmp/dbms_vector_fixture.pid /tmp/dbms_vector_fixture.log \! rm -rf /tmp/kilo/dbms_vector \! rm -f /tmp/rudb_dbms_vector_smoke.onnx