“ORA-51801: VECTOR dimension mismatch”
Users face this error when the dimension of the vector being inserted or queried does not match the VECTOR column definition. Pls note that Oracle 26ai requires consistency between VECTOR column definition and the embedding being inserted or used in queries.
Here are few common Embedding Dimensions
Model Type Typical Dimension
MiniLM 384 or 768
BERT variants 768
OpenAI embeddings 1536
Large transformer models 1024+
For example 1: The below table has 768 dimension and inserting 1536, it will result ORA-51801 error.
SQL> CREATE TABLE documents (
id NUMBER,
embedding VECTOR(768)
);
SQL> INSERT INTO documents VALUES (1, :embedding_1536);
ORA-51801: VECTOR dimension mismatch
If you plan to use a 1536-dimension model, you must recreate the table with VECTOR(1536), since VECTOR dimensions cannot be altered directly.
For example 2: User can get ORA-51801 error while querying as well
SELECT * FROM documents
ORDER BY VECTOR_DISTANCE(embedding, :query_vector)
FETCH FIRST 8 ROWS ONLY;
If :query_vector dimension ≠ column dimension user will receive the error.
How to avoid these errors
raise ValueError("Invalid embedding dimension")
ORDER BY VECTOR_DISTANCE(embedding, :query_vector)
FETCH FIRST 8 ROWS ONLY;
If :query_vector dimension ≠ column dimension user will receive the error.
How to avoid these errors
- Develops should define embedding model centrally and make sure they document its output dimensions.
- Validate dimensions before insert, pls find below example
raise ValueError("Invalid embedding dimension")
SQL> CREATE TABLE embedding_config (
model_name VARCHAR2(100),
dimension NUMBER);
If user encounters the issue, then you should check what the VECTOR column dimension is, embedding model output and queries using same model using below query
SQL> SELECT column_name, data_type, data_length
FROM user_tab_columns
WHERE table_name = 'DOCUMENTS';
or
SQL> DESC DOCUMENTS;
The output shows
EMBEDDING VECTOR(768)
Always remember “Your VECTOR column dimension must exactly match your embedding model output”. Note that even single value difference will trigger ORA-51801
Always remember “Your VECTOR column dimension must exactly match your embedding model output”. Note that even single value difference will trigger ORA-51801
Thanks & Regards,
No comments:
Post a Comment