-- 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;
|
credential_name | params
|
-----------------+-----------------------------------------------------------------------------
|
openai_cred | {"comment": "main credential", "provider": "openai", "access_token": "***"}
|
(1 row)
|
|
SELECT dbms_vector_get_credential('openai_cred') ->> 'access_token' AS access_token;
|
access_token
|
--------------
|
***
|
(1 row)
|
|
SELECT dbms_vector_get_credential('openai_cred') ->> 'provider' AS provider;
|
provider
|
----------
|
openai
|
(1 row)
|
|
-- 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';
|
raw_access_token
|
------------------
|
sk-test-0600
|
(1 row)
|
|
-- 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;
|
credential_name | username | password | private_key | fingerprint
|
-----------------+----------+----------+-------------+-------------
|
oci | | | *** | aa:bb
|
userpass | u | *** | |
|
(2 rows)
|
|
-- duplicate name
|
CALL dbms_vector_create_credential('openai_cred', '{"access_token": "sk-test-0600"}');
|
ERROR: credential openai_cred already exists
|
-- params validation
|
CALL dbms_vector_create_credential('null_params', NULL);
|
ERROR: params must be a JSON object with authentication parameters
|
CALL dbms_vector_create_credential('non_object', '["not", "an", "object"]');
|
ERROR: params must be a JSON object
|
CALL dbms_vector_create_credential('empty_token', '{"access_token": ""}');
|
ERROR: invalid value for ACCESS_TOKEN parameter
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
CALL dbms_vector_create_credential('non_string_token', '{"access_token": 42}');
|
ERROR: invalid value for ACCESS_TOKEN parameter
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
CALL dbms_vector_create_credential('empty_password', '{"username": "u", "password": ""}');
|
ERROR: invalid value for PASSWORD parameter
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
CALL dbms_vector_create_credential('non_string_fingerprint', '{"user_ocid": "ocid1.user..x", "tenancy_ocid": "ocid1.tenancy..x", "private_key": "k", "fingerprint": 42}');
|
ERROR: invalid value for FINGERPRINT parameter
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
CALL dbms_vector_create_credential('no_form', '{"provider": "openai"}');
|
ERROR: params must specify one of: username+password, access_token, or user_ocid+tenancy_ocid+private_key+fingerprint
|
CALL dbms_vector_create_credential('no_form_empty', '{}');
|
ERROR: params must specify one of: username+password, access_token, or user_ocid+tenancy_ocid+private_key+fingerprint
|
CALL dbms_vector_create_credential('half_userpass', '{"username": "u"}');
|
ERROR: username and password must be specified together
|
CALL dbms_vector_create_credential('partial_oci', '{"user_ocid": "ocid1.user..x", "tenancy_ocid": "ocid1.tenancy..x", "private_key": "k"}');
|
ERROR: params must specify one of: username+password, access_token, or user_ocid+tenancy_ocid+private_key+fingerprint
|
-- name validation
|
CALL dbms_vector_create_credential('bad"name', '{"access_token": "sk-test-0600"}');
|
ERROR: invalid credential name: bad"name
|
CALL dbms_vector_create_credential(NULL, NULL);
|
ERROR: credential name must be specified
|
CALL dbms_vector_drop_credential(NULL);
|
ERROR: credential name must be specified
|
-- 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;
|
access_token
|
--------------
|
***
|
(1 row)
|
|
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"}');
|
ERROR: 42501
|
SELECT dbms_vector_get_credential('openai_cred');
|
ERROR: 42501
|
\set VERBOSITY default
|
RESET ROLE;
|
DROP ROLE dbms_vector_user;
|
-- get_credential of a missing credential
|
SELECT dbms_vector_get_credential('no_such_cred');
|
ERROR: credential no_such_cred does not exist
|
DETAIL: Oracle error: ORA-20001 (EXCP_CRED_NOT_EXIST).
|
-- 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');
|
ERROR: credential openai_cred does not exist
|
DETAIL: Oracle error: ORA-20001 (EXCP_CRED_NOT_EXIST).
|
CALL dbms_vector_drop_credential('never_existed');
|
ERROR: credential never_existed does not exist
|
DETAIL: Oracle error: ORA-20001 (EXCP_CRED_NOT_EXIST).
|
SELECT credential_name FROM "SYS".all_vector_credentials ORDER BY 1;
|
credential_name
|
-----------------
|
(0 rows)
|
|
-- ===========================================================================
|
-- 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;
|
stored_models
|
---------------
|
t
|
(1 row)
|
|
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';
|
doc_model_metadata
|
--------------------
|
t
|
(1 row)
|
|
-- 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);
|
ERROR: ONNX model data must not be empty
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
CALL dbms_vector_load_onnx_model('null_model', NULL, NULL);
|
ERROR: ONNX model data must be specified
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
CALL dbms_vector_load_onnx_model(NULL, '\x0806'::bytea, NULL);
|
ERROR: model name must be specified
|
-- metadata must be a JSON object
|
CALL dbms_vector_load_onnx_model('badmeta_model', '\x0806'::bytea, '[1, 2]');
|
ERROR: metadata must be a JSON object
|
-- name validation
|
CALL dbms_vector_load_onnx_model('bad"name', '\x0806'::bytea, NULL);
|
ERROR: invalid model name: bad"name
|
CALL dbms_vector_drop_onnx_model(NULL, false);
|
ERROR: model name must be specified
|
-- 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';
|
dir_model_metadata
|
--------------------
|
t
|
(1 row)
|
|
-- 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;
|
tempdir_model_bytes
|
---------------------
|
t
|
(1 row)
|
|
-- 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);
|
ERROR: model file not found on the server: /tmp/kilo/dbms_vector/models/no_such.onnx
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
CALL dbms_vector_load_onnx_model_dir('/tmp/kilo/dbms_vector/../models', 'model.onnx', 'dotdot_model', NULL);
|
ERROR: model file path must not be empty or contain '..': /tmp/kilo/dbms_vector/../models/model.onnx
|
CALL dbms_vector_load_onnx_model_dir('TEMP_DIR', '../secret.onnx', 'esc_model', NULL);
|
ERROR: invalid file name: ../secret.onnx
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
CALL dbms_vector_load_onnx_model_dir('NO_SUCH_DIR', 'model.onnx', 'alias_model', NULL);
|
ERROR: non-existent directory or file
|
DETAIL: ORA-22285: non-existent directory or file for FILEOPEN operation
|
CALL dbms_vector_load_onnx_model_dir(NULL, 'model.onnx', 'nulldir_model', NULL);
|
ERROR: directory must be specified
|
CALL dbms_vector_load_onnx_model_dir('/tmp/kilo/dbms_vector/models', NULL, 'nullfile_model', NULL);
|
ERROR: file name must be specified
|
CALL dbms_vector_load_onnx_model_dir('/tmp/kilo/dbms_vector', 'models', 'notfile_model', NULL);
|
ERROR: model file is not a regular file: /tmp/kilo/dbms_vector/models
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
-- 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);
|
ERROR: model doc_model does not exist
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
CALL dbms_vector_drop_onnx_model('never_existed', true);
|
ERROR: model never_existed does not exist
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
-- 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';
|
count
|
-------
|
0
|
(1 row)
|
|
SELECT count(*) FROM pg_proc WHERE proname = 'dbms_vector_onnx_enabled';
|
count
|
-------
|
1
|
(1 row)
|
|
SELECT dbms_vector_onnx_enabled() = (:'onnx'::int = 1) AS probe_consistent;
|
probe_consistent
|
------------------
|
t
|
(1 row)
|
|
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;
|
model_name
|
------------
|
(0 rows)
|
|
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);
|
outcomes_match_flavor
|
-----------------------
|
t
|
(1 row)
|
|
-- ===========================================================================
|
-- 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"}');
|
dbms_vector_utl_to_embedding
|
------------------------------
|
[5,1,0.25]
|
(1 row)
|
|
-- 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"}');
|
dbms_vector_utl_to_embedding
|
------------------------------
|
[2,1,0.25]
|
(1 row)
|
|
-- 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"}');
|
?column?
|
----------
|
0
|
(1 row)
|
|
-- the fixture saw the api key from the stored credential and the exact body keys
|
\! cat /tmp/kilo/dbms_vector/fixture_requests.log
|
embeddings key=sk-test-0600 model=text-embedding-test keys=encoding_format,input,model,user
|
embeddings key=sk-test-0600 model=text-embedding-test keys=input,model
|
embeddings key=sk-test-0600 model=text-embedding-test keys=input,model
|
-- 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;
|
db_provider_rejected
|
----------------------
|
t
|
(1 row)
|
|
-- unknown / invalid provider
|
SELECT dbms_vector_utl_to_embedding('hello'::clob, '{"provider":"cohere"}');
|
ERROR: An unsupported provider was specified: cohere
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
HINT: Supported providers: database (local ONNX), openai.
|
SELECT dbms_vector_utl_to_embedding('hello'::clob, '{"provider":42}');
|
ERROR: invalid value for PROVIDER parameter
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
SELECT dbms_vector_utl_to_embedding('hello'::clob, '["not", "an", "object"]');
|
ERROR: params must be a JSON object
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
-- data is required
|
SELECT dbms_vector_utl_to_embedding(NULL, NULL);
|
ERROR: data must be specified
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
-- 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"}');
|
ERROR: missing URL parameter
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
SELECT dbms_vector_utl_to_embedding('hello'::clob, '{"provider":"openai","url":"http://127.0.0.1:18180/v1/embeddings","credential_name":"openai_cred"}');
|
ERROR: missing MODEL parameter
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
SELECT dbms_vector_utl_to_embedding('hello'::clob, '{"provider":"openai","url":"http://127.0.0.1:18180/v1/embeddings","model":"text-embedding-test"}');
|
ERROR: missing CREDENTIAL_NAME parameter
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
-- 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"}');
|
ERROR: missing URL parameter
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
-- 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"}');
|
ERROR: credential no_such_cred does not exist
|
DETAIL: Oracle error: ORA-20001 (EXCP_CRED_NOT_EXIST).
|
-- 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}');
|
ERROR: invalid value for transfer_timeout parameter
|
DETAIL: Oracle error: ORA-29225.
|
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"}');
|
ERROR: invalid value for transfer_timeout parameter
|
DETAIL: Oracle error: ORA-29225.
|
-- 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"}');
|
ERROR: provider returned an error: Invalid API key provided
|
DETAIL: Oracle error: ORA-20002 (EXCP_PROVIDER_ERR).
|
-- 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"}');
|
ERROR: username/password credentials cannot be used with the openai provider
|
DETAIL: Oracle providers always send the stored key as a bearer token (pls:2253); a username/password credential has no key.
|
-- 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"}');
|
ERROR: username/password credentials cannot be used with the openai provider
|
DETAIL: Oracle providers always send the stored key as a bearer token (pls:2253); a username/password credential has no key.
|
-- 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"}');
|
ERROR: OCI request signing credentials are not supported by the REST provider
|
HINT: Use an access_token credential with provider 'openai'.
|
-- 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"}');
|
ERROR: provider returned an error: Invalid request: unknown model
|
DETAIL: Oracle error: ORA-20002 (EXCP_PROVIDER_ERR).
|
-- 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"}');
|
ERROR: provider returned an error: upstream exploded
|
DETAIL: Oracle error: ORA-20002 (EXCP_PROVIDER_ERR).
|
-- 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"}');
|
ERROR: provider returned an error: model overloaded, retry later
|
DETAIL: Oracle error: ORA-20002 (EXCP_PROVIDER_ERR).
|
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"}');
|
ERROR: provider returned an error: quota exceeded for this key
|
DETAIL: Oracle error: ORA-20002 (EXCP_PROVIDER_ERR).
|
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"}');
|
ERROR: provider returned an error: bad input
|
DETAIL: Oracle error: ORA-20002 (EXCP_PROVIDER_ERR).
|
-- 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}');
|
ERROR: provider request failed: Timeout was reached
|
-- ===========================================================================
|
-- 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"}');
|
dbms_vector_utl_to_embeddings
|
----------------------------------------------------------------------------------------
|
{"{\"embed_id\": \"1\", \"embed_data\": \"hello\", \"embed_vector\": \"[5,1,0.25]\"}"}
|
(1 row)
|
|
-- 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';
|
?column?
|
----------
|
1
|
(1 row)
|
|
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';
|
?column?
|
----------
|
hello
|
(1 row)
|
|
-- 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;
|
?column?
|
----------
|
0
|
(1 row)
|
|
-- 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}');
|
dbms_vector_utl_to_embeddings
|
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
{"{\"embed_id\": \"1\", \"embed_data\": \"aaaa\", \"embed_vector\": \"[4,1,0.25]\"}","{\"embed_id\": \"2\", \"embed_data\": \"b\", \"embed_vector\": \"[1,2,0.25]\"}","{\"embed_id\": \"3\", \"embed_data\": \"cc\", \"embed_vector\": \"[2,1,0.25]\"}"}
|
(1 row)
|
|
\! cat /tmp/kilo/dbms_vector/fixture_requests.log
|
embeddings key=sk-test-0600 model=text-embedding-test keys=input,model
|
embeddings key=sk-test-0600 model=text-embedding-test keys=input,model
|
embeddings key=sk-test-0600 model=text-embedding-test keys=input,model
|
embeddings key=sk-test-0600 model=text-embedding-test keys=input,model
|
embeddings key=sk-test-0600 model=text-embedding-test keys=input,model
|
embeddings key=sk-test-0600 model=text-embedding-test keys=input,model
|
-- 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);
|
array_length
|
--------------
|
2
|
(1 row)
|
|
\! cat /tmp/kilo/dbms_vector/fixture_requests.log
|
embeddings key=sk-test-0600 model=text-embedding-test keys=input,model
|
embeddings key=sk-test-0600 model=text-embedding-test keys=input,model
|
-- 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';
|
?column?
|
----------
|
42
|
(1 row)
|
|
-- 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';
|
?column?
|
----------
|
null
|
(1 row)
|
|
-- 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"}');
|
dbms_vector_utl_to_embeddings
|
-------------------------------
|
{}
|
(1 row)
|
|
-- 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}');
|
ERROR: invalid value for BATCH_SIZE parameter
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
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"}');
|
ERROR: invalid value for BATCH_SIZE parameter
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
-- 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;
|
db_provider_all_rejected
|
--------------------------
|
t
|
(1 row)
|
|
SELECT dbms_vector_utl_to_embeddings('hello'::clob, '{"provider":"cohere"}');
|
ERROR: An unsupported provider was specified: cohere
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
HINT: Supported providers: database (local ONNX), openai.
|
SELECT dbms_vector_utl_to_embeddings(array['{"chunk_id":"1","chunk_data":"b"}']::text[], '{"provider":"cohere"}');
|
ERROR: An unsupported provider was specified: cohere
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
HINT: Supported providers: database (local ONNX), openai.
|
-- data is required
|
SELECT dbms_vector_utl_to_embeddings(NULL, NULL);
|
ERROR: data must be specified
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
SELECT dbms_vector_utl_to_embeddings(NULL::text[], NULL);
|
ERROR: data must be specified
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
-- 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"}');
|
ERROR: data(1) is not a valid JSON document
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
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"}');
|
ERROR: data(1) must be a JSON object with chunk_data
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
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"}');
|
ERROR: data(1) is missing a string chunk_data
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
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"}');
|
ERROR: data(1) is missing a string chunk_data
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
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"}');
|
ERROR: data(1) must not be NULL
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
-- 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"}');
|
ERROR: missing URL parameter
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
-- 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"}');
|
ERROR: provider returned an error: Invalid request: unknown model
|
DETAIL: Oracle error: ORA-20002 (EXCP_PROVIDER_ERR).
|
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;
|
euclidean_top3
|
----------------
|
t
|
(1 row)
|
|
-- 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;
|
text_overload_ok
|
------------------
|
t
|
(1 row)
|
|
-- 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);
|
euclidean
|
-----------
|
1,2,3,4,5
|
(1 row)
|
|
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);
|
cosine
|
-----------
|
4,1,2,3,5
|
(1 row)
|
|
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);
|
dot
|
-----------
|
4,5,3,2,1
|
(1 row)
|
|
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);
|
manhattan
|
-----------
|
1,2,3,4,5
|
(1 row)
|
|
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);
|
l2sq
|
-----------
|
1,2,3,4,5
|
(1 row)
|
|
-- 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);
|
cos_lower
|
-----------
|
4,1,2,3,5
|
(1 row)
|
|
-- 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);
|
top3
|
-------
|
1,2,3
|
(1 row)
|
|
SELECT dbms_vector_query('dbms_vector_query_tab', 'v', '[1,1,1]'::vector, 0) = '[]'::jsonb AS empty;
|
empty
|
-------
|
t
|
(1 row)
|
|
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);
|
top100
|
-----------
|
1,2,3,4,5
|
(1 row)
|
|
-- 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;
|
projected
|
-----------
|
t
|
(1 row)
|
|
-- 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;
|
empty_proj
|
------------
|
t
|
(1 row)
|
|
-- 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);
|
exactscan
|
-----------
|
1,2,3,4,5
|
(1 row)
|
|
-- 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);
|
efsearch
|
-----------
|
1,2,3,4,5
|
(1 row)
|
|
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);
|
probes
|
-----------
|
1,2,3,4,5
|
(1 row)
|
|
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);
|
gucs_both
|
-----------
|
1,2,3,4,5
|
(1 row)
|
|
-- 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);
|
accuracy
|
-----------
|
1,2,3,4,5
|
(1 row)
|
|
-- 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);
|
idx_ok
|
-----------
|
1,2,3,4,5
|
(1 row)
|
|
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);
|
WARNING: index no_such_idx does not exist on table dbms_vector_query_tab
|
idx_warn
|
-----------
|
1,2,3,4,5
|
(1 row)
|
|
-- 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');
|
ERROR: Distance metric - CHEBYSHEV - is not a valid option
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
-- 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');
|
ERROR: Distance metric - HAMMING - is supported only for bit vectors
|
HINT: Bit vector distances are outside the scope of this port.
|
-- required arguments
|
SELECT dbms_vector_query(NULL, 'v', '[1,1,1]'::vector, 3);
|
ERROR: table name must be specified
|
SELECT dbms_vector_query('dbms_vector_query_tab', NULL, '[1,1,1]'::vector, 3);
|
ERROR: vector column name must be specified
|
SELECT dbms_vector_query('dbms_vector_query_tab', 'v', NULL::vector, 3);
|
ERROR: query vector must be specified
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
SELECT dbms_vector_query('dbms_vector_query_tab', 'v', NULL::text, 3);
|
ERROR: query vector must be specified
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
SELECT dbms_vector_query('dbms_vector_query_tab', 'v', '[1,1,1]'::vector, NULL);
|
ERROR: top_k must be specified
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
-- 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);
|
ERROR: invalid table name: public.dbms_vector_query_tab
|
SELECT dbms_vector_query('dbms_vector_query_tab', 'bad-name', '[1,1,1]'::vector, 3);
|
ERROR: invalid vector column name: bad-name
|
-- the text overload validates the vector text through vector_in
|
SELECT dbms_vector_query('dbms_vector_query_tab', 'v', 'nope', 3);
|
ERROR: invalid input syntax for type vector: "nope"
|
DETAIL: Vector contents must start with "[".
|
-- 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}');
|
ERROR: vec_proj_cols must be a JSON array of column names
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
SELECT dbms_vector_query('dbms_vector_query_tab', 'v', '[1,1,1]'::vector, 3, '[42]');
|
ERROR: vec_proj_cols(1) must be a column name string
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
SELECT dbms_vector_query('dbms_vector_query_tab', 'v', '[1,1,1]'::vector, 3, '["bad-name"]');
|
ERROR: invalid projection column name: bad-name
|
-- query vector dimensions must match the column
|
SELECT dbms_vector_query('dbms_vector_query_tab', 'v', '[1,1]'::vector, 3);
|
ERROR: different vector dimensions 3 and 2
|
CONTEXT: SQL statement "SELECT to_jsonb(t.*) FROM dbms_vector_query_tab t ORDER BY t.v <-> $1 LIMIT $2"
|
-- top_k must be non-negative
|
SELECT dbms_vector_query('dbms_vector_query_tab', 'v', '[1,1,1]'::vector, -1);
|
ERROR: LIMIT must not be negative
|
CONTEXT: SQL statement "SELECT to_jsonb(t.*) FROM dbms_vector_query_tab t ORDER BY t.v <-> $1 LIMIT $2"
|
-- 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, '[]');
|
ERROR: idx_parameters must be a JSON object
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
SELECT dbms_vector_query('dbms_vector_query_tab', 'v', '[1,1,1]'::vector, 3, NULL, NULL, 'EUCLIDEAN', true, 95, '{"efsearch": 0}');
|
ERROR: invalid value for EFSEARCH parameter
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
SELECT dbms_vector_query('dbms_vector_query_tab', 'v', '[1,1,1]'::vector, 3, NULL, NULL, 'EUCLIDEAN', true, 95, '{"efsearch": "big"}');
|
ERROR: invalid value for EFSEARCH parameter
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
SELECT dbms_vector_query('dbms_vector_query_tab', 'v', '[1,1,1]'::vector, 3, NULL, NULL, 'EUCLIDEAN', true, 95, '{"neighbor partition probes": "many"}');
|
ERROR: invalid value for NEIGHBOR PARTITION PROBES parameter
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
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);
|
dbms_vector_utl_to_chunks
|
----------------------------------------------------------------------------------------------
|
[{"chunk_id": 1, "chunk_data": "one two three", "chunk_length": null, "chunk_offset": null}]
|
(1 row)
|
|
SELECT dbms_vector_utl_to_chunks('one two three'::clob, NULL::jsonb);
|
dbms_vector_utl_to_chunks
|
----------------------------------------------------------------------------------------------
|
[{"chunk_id": 1, "chunk_data": "one two three", "chunk_length": null, "chunk_offset": null}]
|
(1 row)
|
|
-- 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);
|
dbms_vector_utl_to_chunks
|
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
[{"chunk_id": 1, "chunk_data": "abcdefghij", "chunk_length": 10, "chunk_offset": 1}, {"chunk_id": 2, "chunk_data": "hijklmnopq", "chunk_length": 10, "chunk_offset": 8}, {"chunk_id": 3, "chunk_data": "opqrstuvwx", "chunk_length": 10, "chunk_offset": 15}, {"chunk_id": 4, "chunk_data": "vwxyz", "chunk_length": 5, "chunk_offset": 22}]
|
(1 row)
|
|
-- 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);
|
dbms_vector_utl_to_chunks
|
---------------------------------------------------------------------------------------------------------------------------------------------------------------
|
[{"chunk_id": 1, "chunk_data": "aa bb ", "chunk_length": 6, "chunk_offset": 1}, {"chunk_id": 2, "chunk_data": "bb cc", "chunk_length": 5, "chunk_offset": 4}]
|
(1 row)
|
|
-- 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);
|
jsonb_array_length
|
--------------------
|
3
|
(1 row)
|
|
-- empty input yields an empty document
|
SELECT dbms_vector_utl_to_chunks(''::clob);
|
dbms_vector_utl_to_chunks
|
---------------------------
|
[]
|
(1 row)
|
|
-- 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);
|
dbms_vector_utl_to_chunks
|
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
[{"chunk_id": 1, "chunk_data": "aaa bbb\n", "chunk_length": 8, "chunk_offset": 1}, {"chunk_id": 2, "chunk_data": "ccc ddd\neee", "chunk_length": 11, "chunk_offset": 9}]
|
(1 row)
|
|
-- 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);
|
dbms_vector_utl_to_chunks
|
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
[{"chunk_id": 1, "chunk_data": "para one\npara two\n\n", "chunk_length": 19, "chunk_offset": 1}, {"chunk_id": 2, "chunk_data": "para three", "chunk_length": 10, "chunk_offset": 20}]
|
(1 row)
|
|
-- 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);
|
dbms_vector_utl_to_chunks
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
[{"chunk_id": 1, "chunk_data": "First sentence. ", "chunk_length": 16, "chunk_offset": 1}, {"chunk_id": 2, "chunk_data": "Second one? ", "chunk_length": 12, "chunk_offset": 17}, {"chunk_id": 3, "chunk_data": "Third!", "chunk_length": 6, "chunk_offset": 29}]
|
(1 row)
|
|
SELECT jsonb_array_length(dbms_vector_utl_to_chunks('3.14 is a number'::clob,
|
'{"split": "sentence"}'::jsonb)::jsonb);
|
jsonb_array_length
|
--------------------
|
1
|
(1 row)
|
|
-- 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);
|
dbms_vector_utl_to_chunks
|
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
[{"chunk_id": 1, "chunk_data": "rule one:", "chunk_length": 9, "chunk_offset": 1}, {"chunk_id": 2, "chunk_data": "rule two;", "chunk_length": 9, "chunk_offset": 10}, {"chunk_id": 3, "chunk_data": "rule three", "chunk_length": 10, "chunk_offset": 19}]
|
(1 row)
|
|
-- 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);
|
dbms_vector_utl_to_chunks
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
[{"chunk_id": 1, "chunk_data": "aaa bbb ", "chunk_length": 8, "chunk_offset": 1}, {"chunk_id": 2, "chunk_data": "ccc\n", "chunk_length": 4, "chunk_offset": 9}, {"chunk_id": 3, "chunk_data": "ddd eee\n", "chunk_length": 8, "chunk_offset": 13}, {"chunk_id": 4, "chunk_data": "fff ggg", "chunk_length": 7, "chunk_offset": 21}]
|
(1 row)
|
|
-- normalize all: widechar to ASCII, punctuation dropped, whitespace collapsed
|
SELECT dbms_vector_utl_to_chunks(' Hello, world! '::clob,
|
'{"normalize": "all", "extended": true}'::jsonb);
|
dbms_vector_utl_to_chunks
|
---------------------------------------------------------------------------------------
|
[{"chunk_id": 1, "chunk_data": "Hello world", "chunk_length": 11, "chunk_offset": 1}]
|
(1 row)
|
|
SELECT dbms_vector_utl_to_chunks('A B C'::clob,
|
'{"normalize": "options", "norm_options": ["widechar", "punctuation"], "extended": true}'::jsonb);
|
dbms_vector_utl_to_chunks
|
--------------------------------------------------------------------------------
|
[{"chunk_id": 1, "chunk_data": "A B C", "chunk_length": 5, "chunk_offset": 1}]
|
(1 row)
|
|
-- 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);
|
jsonb_array_length
|
--------------------
|
1
|
(1 row)
|
|
-- param validation (Oracle parity messages)
|
SELECT dbms_vector_utl_to_chunks('x'::clob, '{"by": "bytes"}'::jsonb);
|
ERROR: invalid value bytes for BY parameter
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
SELECT dbms_vector_utl_to_chunks('x'::clob, '{"max": "big"}'::jsonb);
|
ERROR: invalid value for MAX parameter
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
SELECT dbms_vector_utl_to_chunks('x'::clob, '{"max": 0}'::jsonb);
|
ERROR: invalid value for MAX parameter
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
SELECT dbms_vector_utl_to_chunks('x'::clob, '{"overlap": -1}'::jsonb);
|
ERROR: invalid value for OVERLAP parameter
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
SELECT dbms_vector_utl_to_chunks('x'::clob, '{"max": 5, "overlap": 5}'::jsonb);
|
ERROR: invalid value for OVERLAP parameter
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
SELECT dbms_vector_utl_to_chunks('x'::clob, '{"split": "everywhere"}'::jsonb);
|
ERROR: invalid value everywhere for SPLIT parameter
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
SELECT dbms_vector_utl_to_chunks('x'::clob, '{"split": "custom"}'::jsonb);
|
ERROR: missing CUSTOM_LIST parameter
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
SELECT dbms_vector_utl_to_chunks('x'::clob, '{"split": "custom", "custom_list": []}'::jsonb);
|
ERROR: missing CUSTOM_LIST parameter
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
SELECT dbms_vector_utl_to_chunks('x'::clob, '{"split": "custom", "custom_list": [42]}'::jsonb);
|
ERROR: invalid value for CUSTOM_LIST parameter
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
SELECT dbms_vector_utl_to_chunks('x'::clob, '{"by": "vocabulary"}'::jsonb);
|
ERROR: missing VOCABULARY parameter
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
SELECT dbms_vector_utl_to_chunks('x'::clob, '{"by": "vocabulary", "vocabulary": "my_vocab"}'::jsonb);
|
ERROR: chunking by vocabulary is not supported in this port
|
DETAIL: Vocabulary storage is not ported; use "by": "chars" or "by": "words".
|
SELECT dbms_vector_utl_to_chunks('x'::clob, '{"normalize": "sometimes"}'::jsonb);
|
ERROR: invalid value sometimes for NORMALIZE parameter
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
SELECT dbms_vector_utl_to_chunks('x'::clob, '{"normalize": "options"}'::jsonb);
|
ERROR: missing NORM_OPTIONS parameter
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
SELECT dbms_vector_utl_to_chunks('x'::clob, '{"normalize": "options", "norm_options": ["shouting"]}'::jsonb);
|
ERROR: invalid value shouting for NORM_OPTIONS parameter
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
SELECT dbms_vector_utl_to_chunks('x'::clob, '{"extended": "yes"}'::jsonb);
|
ERROR: invalid value for EXTENDED parameter
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
SELECT dbms_vector_utl_to_chunks('x'::clob, '[]'::jsonb);
|
ERROR: params must be a JSON object
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
SELECT dbms_vector_utl_to_chunks(NULL::clob);
|
ERROR: data must be specified
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
-- ===========================================================================
|
-- 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"}');
|
dbms_vector_utl_to_generate_text
|
----------------------------------
|
reply to: tell me about vectors
|
(1 row)
|
|
-- 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"}');
|
dbms_vector_utl_to_generate_text
|
----------------------------------
|
completion of: once upon a time
|
(1 row)
|
|
-- 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
|
chat key=sk-test-0600 model=gpt-test keys=messages,model,temperature,user prompt=tell me about vectors
|
completions key=sk-test-0600 model=gpt-test keys=model,prompt prompt=once upon a time
|
\! 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);
|
ERROR: You did not specify a value for the parameter provider
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
SELECT dbms_vector_utl_to_generate_text('hi'::clob, NULL::jsonb);
|
ERROR: You did not specify a value for the parameter provider
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
SELECT dbms_vector_utl_to_generate_text('hi'::clob, '{"provider":""}'::jsonb);
|
ERROR: You did not specify a value for the parameter provider
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
-- unsupported provider (pls:2972)
|
SELECT dbms_vector_utl_to_generate_text('hi'::clob, '{"provider":"cohere"}'::jsonb);
|
ERROR: An unsupported provider was specified: cohere
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
HINT: Supported providers: openai.
|
-- params must be a JSON object
|
SELECT dbms_vector_utl_to_generate_text('hi'::clob, '["not", "an", "object"]'::jsonb);
|
ERROR: params must be a JSON object
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
-- data is required
|
SELECT dbms_vector_utl_to_generate_text(NULL::clob);
|
ERROR: data must be specified
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
-- 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"}');
|
ERROR: missing URL parameter
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
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"}');
|
ERROR: missing MODEL parameter
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
SELECT dbms_vector_utl_to_generate_text('hi'::clob, '{"provider":"openai","url":"http://127.0.0.1:18180/v1/chat/completions","model":"gpt-test"}');
|
ERROR: missing CREDENTIAL_NAME parameter
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
-- 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"}');
|
ERROR: credential no_such_cred does not exist
|
DETAIL: Oracle error: ORA-20001 (EXCP_CRED_NOT_EXIST).
|
-- 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"}');
|
ERROR: The provider returned an error: Invalid API key provided
|
DETAIL: Oracle error: ORA-20002 (EXCP_PROVIDER_ERR).
|
-- 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"}');
|
ERROR: The provider returned an error: Invalid request: unknown model
|
DETAIL: Oracle error: ORA-20002 (EXCP_PROVIDER_ERR).
|
-- 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"}');
|
ERROR: The provider returned an error: upstream exploded
|
DETAIL: Oracle error: ORA-20002 (EXCP_PROVIDER_ERR).
|
-- 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"}');
|
ERROR: The provider returned an error: model overloaded, retry later
|
DETAIL: Oracle error: ORA-20002 (EXCP_PROVIDER_ERR).
|
-- 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}');
|
ERROR: provider request failed: Timeout was reached
|
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';
|
amname | opcname | reloptions
|
--------+---------------+--------------------------
|
hnsw | vector_l2_ops | {m=8,ef_construction=48}
|
(1 row)
|
|
-- 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);
|
NOTICE: ivfflat index created with little data
|
DETAIL: This will cause low recall.
|
HINT: Drop the index until the table has more data.
|
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';
|
amname | opcname | reloptions
|
---------+-------------------+------------
|
ivfflat | vector_cosine_ops | {lists=5}
|
(1 row)
|
|
-- 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';
|
amname | opcname | reloptions
|
--------+---------------+------------
|
hnsw | vector_ip_ops | {m=8}
|
(1 row)
|
|
-- 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);
|
ERROR: Organization - SPATIAL - is not a valid option
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
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);
|
ERROR: Partitioning scheme - GLOBAL - is not a valid option
|
DETAIL: RuDB has no Oracle index partitioning; only LOCAL (the default) is supported.
|
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);
|
ERROR: Distance metric - CHEBYSHEV - is not a valid option
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
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);
|
ERROR: Distance metric - HAMMING - is supported only for bit vectors
|
HINT: Bit vector distances are outside the scope of this port.
|
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);
|
ERROR: Index type - XYZ - is not a valid option
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
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);
|
ERROR: Index type - IVF - does not match the organization INMEMORY NEIGHBOR GRAPH
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
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);
|
ERROR: invalid value for NEIGHBORS parameter
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
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);
|
ERROR: idx_parameters must be a JSON object
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
-- 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);
|
ERROR: idx_organization must be specified
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
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);
|
ERROR: idx_parameters must be specified
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
-- 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);
|
ERROR: invalid table name: public.dbms_vector_create_index_tab
|
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);
|
ERROR: invalid vector column name: bad-name
|
-- 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);
|
ERROR: relation "dbms_vector_no_tab" does not exist
|
CONTEXT: SQL statement "CREATE INDEX BAD ON dbms_vector_no_tab USING hnsw (v vector_l2_ops)"
|
CALL dbms_vector_create_index('bad', 'dbms_vector_create_index_tab', 'nope', NULL, 'LOCAL', 'INMEMORY NEIGHBOR GRAPH', 'EUCLIDEAN', 95, '{"type":"HNSW"}'::jsonb, 4, NULL);
|
ERROR: column "nope" does not exist
|
LINE 1: ...X BAD ON dbms_vector_create_index_tab USING hnsw (nope vecto...
|
^
|
QUERY: CREATE INDEX BAD ON dbms_vector_create_index_tab USING hnsw (nope vector_l2_ops)
|
-- 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);
|
ERROR: access method "hnsw" does not support included columns
|
CONTEXT: SQL statement "CREATE INDEX VEC_INC_IDX ON dbms_vector_create_index_tab USING hnsw (v vector_l2_ops) INCLUDE (payload)"
|
-- 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';
|
fallback_created
|
------------------
|
1
|
(1 row)
|
|
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';
|
amname | opcname | reloptions | indisvalid
|
--------+---------------+--------------------------+------------
|
hnsw | vector_l2_ops | {m=8,ef_construction=48} | t
|
(1 row)
|
|
-- 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';
|
amname | opcname | reloptions | indisvalid
|
--------+---------------+---------------------------+------------
|
hnsw | vector_l2_ops | {m=16,ef_construction=64} | t
|
(1 row)
|
|
-- 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';
|
amname | opcname | reloptions | indisvalid
|
--------+-------------------+---------------------------+------------
|
hnsw | vector_cosine_ops | {m=16,ef_construction=64} | t
|
(1 row)
|
|
-- 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);
|
NOTICE: ivfflat index created with little data
|
DETAIL: This will cause low recall.
|
HINT: Drop the index until the table has more data.
|
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';
|
amname | opcname | reloptions | indisvalid
|
---------+-------------------+------------+------------
|
ivfflat | vector_cosine_ops | {lists=4} | t
|
(1 row)
|
|
-- 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);
|
NOTICE: ivfflat index created with little data
|
DETAIL: This will cause low recall.
|
HINT: Drop the index until the table has more data.
|
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';
|
amname | opcname | reloptions | indisvalid
|
---------+-------------------+------------+------------
|
ivfflat | vector_cosine_ops | {lists=4} | t
|
(1 row)
|
|
-- 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';
|
amname | opcname | reloptions | indisvalid
|
--------+---------------+------------+------------
|
hnsw | vector_ip_ops | {m=12} | t
|
(1 row)
|
|
-- 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';
|
amname | opcname | reloptions | indisvalid
|
--------+---------------+------------+------------
|
hnsw | vector_ip_ops | {m=12} | t
|
(1 row)
|
|
-- nonexistent index
|
CALL dbms_vector_rebuild_index('no_such_rebuild_idx');
|
ERROR: index NO_SUCH_REBUILD_IDX does not exist
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
-- non-vector index
|
CREATE INDEX vec_rebuild_btree ON dbms_vector_rebuild_tab (id);
|
CALL dbms_vector_rebuild_index('vec_rebuild_btree');
|
ERROR: index VEC_REBUILD_BTREE is not a vector index
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
-- 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);
|
ERROR: Distance metric - HAMMING - is supported only for bit vectors
|
HINT: Bit vector distances are outside the scope of this port.
|
SELECT i.indisvalid FROM pg_index i JOIN pg_class c ON c.oid = i.indexrelid WHERE c.relname = 'vec_rebuild_idx';
|
indisvalid
|
------------
|
t
|
(1 row)
|
|
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');
|
dbms_vector_get_index_status
|
----------------------------------------------------------------------
|
{"am": "hnsw", "state": "COMPLETED", "index_name": "vec_status_idx"}
|
(1 row)
|
|
SELECT dbms_vector_get_index_status('VEC_STATUS_IDX');
|
dbms_vector_get_index_status
|
----------------------------------------------------------------------
|
{"am": "hnsw", "state": "COMPLETED", "index_name": "vec_status_idx"}
|
(1 row)
|
|
-- !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');
|
dbms_vector_get_index_status
|
-------------------------------------------------------------------
|
{"am": "hnsw", "state": "FAILED", "index_name": "vec_status_idx"}
|
(1 row)
|
|
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');
|
ERROR: index NO_SUCH_STATUS_IDX does not exist
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
CREATE INDEX vec_status_btree ON dbms_vector_status_tab (id);
|
SELECT dbms_vector_get_index_status('vec_status_btree');
|
ERROR: index VEC_STATUS_BTREE is not a vector index
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
SELECT dbms_vector_get_index_status(NULL);
|
ERROR: index name must be specified
|
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);
|
dbms_vector_index_vector_memory_advisor
|
---------------------------------------------------------------------
|
{"bytes_per_row": 216, "rows_estimated": 2, "estimated_bytes": 432}
|
(1 row)
|
|
-- 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);
|
dbms_vector_index_vector_memory_advisor
|
---------------------------------------------------------------------
|
{"bytes_per_row": 408, "rows_estimated": 2, "estimated_bytes": 816}
|
(1 row)
|
|
-- 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);
|
NOTICE: ivfflat index created with little data
|
DETAIL: This will cause low recall.
|
HINT: Drop the index until the table has more data.
|
SELECT dbms_vector_index_vector_memory_advisor('vec_adv_ivf_idx', NULL);
|
dbms_vector_index_vector_memory_advisor
|
-------------------------------------------------------------------
|
{"bytes_per_row": 12, "rows_estimated": 2, "estimated_bytes": 72}
|
(1 row)
|
|
-- 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');
|
dbms_vector_index_vector_memory_advisor
|
----------------------------------------------------------------------
|
{"bytes_per_row": 408, "rows_estimated": 3, "estimated_bytes": 1224}
|
(1 row)
|
|
-- 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');
|
dbms_vector_index_vector_memory_advisor
|
----------------------------------------------------------------------
|
{"bytes_per_row": 408, "rows_estimated": 3, "estimated_bytes": 1224}
|
(1 row)
|
|
-- error paths
|
SELECT dbms_vector_index_vector_memory_advisor('never_created_idx', NULL);
|
ERROR: index NEVER_CREATED_IDX does not exist
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
CREATE TABLE dbms_vector_adv_plain (id int, payload text);
|
SELECT dbms_vector_index_vector_memory_advisor(NULL, 'dbms_vector_adv_plain');
|
ERROR: table dbms_vector_adv_plain has no vector column
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
SELECT dbms_vector_index_vector_memory_advisor(NULL, 'dbms_vector_no_tab');
|
ERROR: table dbms_vector_no_tab does not exist
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
SELECT dbms_vector_index_vector_memory_advisor(NULL, NULL);
|
ERROR: idx_name or table_name must be specified
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
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';
|
idx_schema | idx_name | enabled
|
------------+--------------+---------
|
public | vec_ckpt_idx | f
|
(1 row)
|
|
SELECT reloptions FROM pg_class WHERE relname = 'vec_ckpt_idx';
|
reloptions
|
-------------------------
|
{m=8,checkpointing=off}
|
(1 row)
|
|
-- 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';
|
idx_schema | idx_name | enabled
|
------------+--------------+---------
|
public | vec_ckpt_idx | t
|
(1 row)
|
|
SELECT reloptions FROM pg_class WHERE relname = 'vec_ckpt_idx';
|
reloptions
|
------------------------
|
{m=8,checkpointing=on}
|
(1 row)
|
|
-- 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';
|
idx_name | enabled
|
--------------+---------
|
vec_ckpt_idx | f
|
(1 row)
|
|
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 = '*';
|
idx_schema | idx_name | enabled
|
------------+----------+---------
|
* | * | f
|
(1 row)
|
|
CALL dbms_vector_enable_checkpoint(NULL);
|
SELECT idx_schema, idx_name, enabled FROM "SYS".vector_index_checkpointing WHERE idx_schema = '*';
|
idx_schema | idx_name | enabled
|
------------+----------+---------
|
* | * | t
|
(1 row)
|
|
-- unknown index
|
CALL dbms_vector_enable_checkpoint('no_such_ckpt_idx');
|
ERROR: index NO_SUCH_CKPT_IDX does not exist
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
-- 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');
|
ERROR: permission denied for index VEC_CKPT_IDX
|
HINT: Only the index owner or a superuser may toggle its checkpointing state.
|
CALL dbms_vector_disable_checkpoint(NULL);
|
ERROR: permission denied to change the cluster-wide checkpointing state
|
DETAIL: Only superusers may toggle the cluster-wide state.
|
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';
|
indisvalid
|
------------
|
t
|
(1 row)
|
|
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');
|
ERROR: model never_loaded_pin_model does not exist
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
CALL dbms_vector_inmemory_onnx_model(NULL);
|
ERROR: model name must be specified
|
DETAIL: Oracle error: ORA-20003 (EXCP_GU_ERR).
|
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);
|
pin_matrix_ok
|
---------------
|
t
|
(1 row)
|
|
-- ===========================================================================
|
-- 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';
|
amname | opcname | reloptions | state | est_bytes
|
--------+---------------+--------------------------+-----------+-----------
|
hnsw | vector_l2_ops | {m=8,ef_construction=48} | COMPLETED | 648
|
(1 row)
|
|
CALL dbms_vector_rebuild_index('vec_lifecycle_idx', NULL, NULL, NULL, 'LOCAL', 'NEIGHBOR PARTITIONS', 'EUCLIDEAN', 95, '{"type":"IVF","partitions":4}'::jsonb, 4);
|
NOTICE: ivfflat index created with little data
|
DETAIL: This will cause low recall.
|
HINT: Drop the index until the table has more data.
|
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';
|
amname | opcname | reloptions | state | est_bytes
|
---------+---------------+------------+-----------+-----------
|
ivfflat | vector_l2_ops | {lists=4} | COMPLETED | 84
|
(1 row)
|
|
CALL dbms_vector_disable_checkpoint('vec_lifecycle_idx');
|
CALL dbms_vector_rebuild_index('vec_lifecycle_idx');
|
NOTICE: ivfflat index created with little data
|
DETAIL: This will cause low recall.
|
HINT: Drop the index until the table has more data.
|
SELECT (dbms_vector_get_index_status('vec_lifecycle_idx') ->> 'state') AS state,
|
c.reloptions
|
FROM pg_class c
|
WHERE c.relname = 'vec_lifecycle_idx';
|
state | reloptions
|
-----------+-----------------------------
|
COMPLETED | {lists=4,checkpointing=off}
|
(1 row)
|
|
CALL dbms_vector_enable_checkpoint('vec_lifecycle_idx');
|
SELECT enabled FROM "SYS".vector_index_checkpointing WHERE idx_name = 'vec_lifecycle_idx';
|
enabled
|
---------
|
t
|
(1 row)
|
|
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
|