Skip to Main Content

Oracle Database Free

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Error with DBMS_VECTOR.CREATE_CREDENTIAL when access token is longer than 130 characters

Gianni CeresaSep 12 2024

Hi,

I'm using 23.5 free in docker and playing with dbms_vector. To use 3rd-party webservice for embedding or text generation credentials for that service have to be created first.

All good when the API keys are 130 or less characters, but when the API key is longer it can't be retrieved correctly.

For example: OpenAI can have API keys of 132 characters, and those will not work (they generate keys of variable length, when unlucky it's a long one).

For example when calling dbms_vector.utl_to_embedding the error ORA-06525: Length Mismatch for CHAR or RAW data is raised if the access token in the credential (saved as “key”) is longer than 130 characters.

The impression is that DBMS_VECTOR.CREATE_CREDENTIAL is just a layer on top of DBMS_CREDENTIAL.CREATE_CREDENTIAL, and the issue is there somewhere (maybe not in the CREATE_CREDENTIAL, but in the code retrieving the credential once it was stored).

The easiest way to reproduce is by using mostly the code from the doc:

declare
  jo json_object_t;
begin
  jo := json_object_t();
  jo.put('access_token', 'i-am-a-long-key-of-more-than-130-characters-that-will-fail-with-ORA-06525-Length-Mismatch-for-CHAR-or-RAW-data-when-trying-to-use-it');
  dbms_vector.create_credential(
    credential_name   => 'CRED_TOO_LONG',
    params            => json(jo.to_string));
end;
/

declare
  input clob;
  params clob;
  v vector;
begin
  input := 'Hello world';
  params := '
{
  "provider": "OpenAI",
  "credential_name": "CRED_TOO_LONG",
  "url": "https://api.openai.com/v1/embeddings",
  "model": "text-embedding-3-small"
}';

  v := dbms_vector.utl_to_embedding(input, json(params));
  dbms_output.put_line(vector_serialize(v));
exception
  when OTHERS THEN
    DBMS_OUTPUT.PUT_LINE (SQLERRM);
end;
/

begin
  dbms_vector.drop_credential(
    credential_name   => 'CRED_TOO_LONG');
end;
/

This will generate ORA-06525: Length Mismatch for CHAR or RAW data .

If you run the same code by removing 2 (or a few more) characters from the access_token in the credential, you get the error ORA-20002: provider returned an error: Incorrect API key provided as expected (because it's obviously not a valid API key).

Would be nice if a credential could store more than 130 characters as key.

Comments
Post Details
Added on Sep 12 2024
1 comment
87 views