OracleDB の Vector型において、次元数を定義した時としていない時の挙動の違いを確認します。
以下では、VEC1 は次元数を定義し (2次元)、VEC2 は次元数を定義していません。
SQL> create table testtab (id number, vec1 vector(2,float32), vec2 vector);
Table TESTTAB created.
SQL> info testtab
TABLE: TESTTAB
LAST ANALYZED:
ROWS :
SAMPLE SIZE :
INMEMORY :DISABLED
COMMENTS :
Columns
NAME DATA TYPE NULL DEFAULT COMMENTS
ID NUMBER Yes
VEC1 VECTOR(2,FLOAT32,DENSE) Yes ★2次元
VEC2 VECTOR(*,*,DENSE) Yes ★未定義
次元数が定義された Vector型の列に対して、次元の異なるデータ (ここでは 3次元) を追加しようとするとエラーとなります。
SQL> insert into testtab (id, vec1) values (1,'[1,2]'); ★2次元
1 row inserted.
SQL> insert into testtab (id, vec1) values (2,'[1,2,3]'); ★3次元
Error starting at line : 1 in command -
insert into testtab (id, vec1) values (2,'[1,2,3]')
Error at Command Line : 1 Column : 42
Error report -
SQL Error: ORA-51803: Vector dimension count must match the dimension count spec ified in
the column definition (expected 2 dimensions, specified 3 dimensions).
https://docs.oracle.com/error-help/db/ora-51803/
More Details :
https://docs.oracle.com/error-help/db/ora-51803/
SQL>
ORA-51803
Vector dimension count must match the dimension count specified in the column definition (expected dimension_count_1 dimensions, specified dimension_count_2 dimensions).
dimension_count_1: The dimension count specified in the column definition.
dimension_count_2: The dimension count parsed from the user query.
Cause
The dimension count of the vector does not match the dimension count specified in the column definition.
Action
Ensure that the vector has the same dimension count as specified in the column definition.
次元数が定義されていない Vector型の列は、異なる次元のベクトルデータを受け入れます。
SQL> insert into testtab (id, vec2) values (3,'[1,2]'); ★2次元
1 row inserted.
SQL> insert into testtab (id, vec2) values (4,'[1,2,3]'); ★3次元
1 row inserted.
SQL> select * from testtab;
ID VEC1 VEC2
_____ ______________________ _______________________________
1 [1.0E+000,2.0E+000]
3 [1.0E+000,2.0E+000]
4 [1.0E+000,2.0E+000,3.0E+000]
SQL>
ただし、異なる次元のベクトルデータが格納された Vector型の列に対して、ベクトルインデックスを作成することはできません。(HNSW, IVF のいずれも不可)
SQL> create vector index testtab_idx on testtab(vec2)
2* organization inmemory neighbor graph; ★HNSW
Error starting at line : 1 in command -
create vector index testtab_idx on testtab(vec2)
organization inmemory neighbor graph
Error report -
ORA-51902: Cannot create a vector index on a vector column with different
dimensions
https://docs.oracle.com/error-help/db/ora-51902/
SQL> create vector index testtab_idx on testtab(vec2)
2* organization neighbor partitions; ★IVF
Error starting at line : 1 in command -
create vector index testtab_idx on testtab(vec2)
organization neighbor partitions
Error report -
ORA-51902: Cannot create a vector index on a vector column with different
dimensions
https://docs.oracle.com/error-help/db/ora-51902/
SQL>
ORA-51902
Cannot create a vector index on a vector column with different dimensions
Cause
An attempt is being made to create a vector index on a vector column whose dimension values are not all the same.
Action
Create the vector index on a vector column having same dimension values.
異なる次元のベクトルデータを削除すれば、ベクトルインデックスを作成できるようになります。
SQL> delete from testtab where id=3;
1 row deleted.
SQL> create vector index testtab_idx on testtab(vec2)
2* organization inmemory neighbor graph;
Vector INDEX created.
ベクトルインデックスを作成した状態では、異なる次元のベクトルデータを追加することはできません。
SQL> insert into testtab (id, vec2) values (5,'[1,2]');
Error starting at line : 1 in command -
insert into testtab (id, vec2) values (5,'[1,2]')
Error at Command Line : 1 Column : 42
Error report -
SQL Error: ORA-51932: Mismatched dimension count in the maintainence of a vector index
(input 2, required 3)
https://docs.oracle.com/error-help/db/ora-51932/
More Details :
https://docs.oracle.com/error-help/db/ora-51932/
SQL>
ベクトルインデックスを削除すれば、異なる次元のベクトルデータを再び追加可能となります。
SQL> drop index testtab_idx;
Index TESTTAB_IDX dropped.
SQL> insert into testtab (id, vec2) values (5,'[1,2]');
1 row inserted.
SQL>
ベクトルデータの次元数の確認には、vector_dimension_countが使用可能です。
SQL> select id, vector_dimension_count(vec2) from testtab order by 2;
ID VECTOR_DIMENSION_COUNT(VEC2)
_____ _______________________________
5 2
4 3
1
SQL> select id, vector_dimension_count(vec2) from testtab order by 2 desc;
ID VECTOR_DIMENSION_COUNT(VEC2)
_____ _______________________________
1
4 3
5 2
SQL>