SQL*Loaderを使用した文字ベクトル・データのロードの例
この例では、SQL*Loaderを使用してベクトル・データを5次元ベクトル空間にロードする方法を確認できます。
銀河をタイプ別に分類する次のテキスト文書があるとします。
- DOC1: "Messier 31 is a barred spiral galaxy in the Andromeda constellation which has a lot of barred spiral galaxies."
- DOC2: "Messier 33 is a spiral galaxy in the Triangulum constellation."
- DOC3: "Messier 58 is an intermediate barred spiral galaxy in the Virgo constellation."
- DOC4: "Messier 63 is a spiral galaxy in the Canes Venatici constellation."
- DOC5: "Messier 77 is a barred spiral galaxy in the Cetus constellation."
- DOC6: "Messier 91 is a barred spiral galaxy in the Coma Berenices constellation."
- DOC7: "NGC 1073 is a barred spiral galaxy in Cetus constellation."
- DOC8: "Messier 49 is a giant elliptical galaxy in the Virgo constellation."
- DOC9: "Messier 60 is an elliptical galaxy in the Virgo constellation."
各ドキュメントに現れる重要な単語の数に基づく次の5次元ベクトル空間を使用して、前述の銀河のクラスを表すベクトルを作成できます。
表5-1 5次元ベクトル空間
銀河のクラス | Intermediate | Barred | Spiral | Giant | Elliptical |
---|---|---|---|---|---|
M31 | 0 | 2 | 2 | 0 | 0 |
M33 | 0 | 0 | 1 | 0 | 0 |
M58 | 1 | 1 | 1 | 0 | 0 |
M63 | 0 | 0 | 1 | 0 | 0 |
M77 | 0 | 1 | 1 | 0 | 0 |
M91 | 0 | 1 | 1 | 0 | 0 |
M49 | 0 | 0 | 0 | 1 | 1 |
M60 | 0 | 0 | 0 | 0 | 1 |
NGC1073 | 0 | 1 | 1 | 0 | 0 |
これにより、次のベクトルが必然的に得られます。
- M31:
[0,2,2,0,0]
- M33:
[0,0,1,0,0]
- M58:
[1,1,1,0,0]
- M63:
[0,0,1,0,0]
- M77:
[0,1,1,0,0]
- M91:
[0,1,1,0,0]
- M49:
[0,0,0,1,1]
- M60:
[0,0,0,0,1]
- NGC1073:
[0,1,1,0,0]
SQL*Loaderを使用して、次のように定義されたGALAXIES
データベース表にこのデータをロードできます。
drop table galaxies purge;
create table galaxies (id number, name varchar2(50), doc varchar2(500), embedding vector);
前述のデータに基づいて、次のgalaxies_vec.csv
ファイルを作成できます。
1:M31:Messier 31 is a barred spiral galaxy in the Andromeda constellation which has a lot of barred spiral galaxies.:[0,2,2,0,0]:
2:M33:Messier 33 is a spiral galaxy in the Triangulum constellation.:[0,0,1,0,0]:
3:M58:Messier 58 is an intermediate barred spiral galaxy in the Virgo constellation.:[1,1,1,0,0]:
4:M63:Messier 63 is a spiral galaxy in the Canes Venatici constellation.:[0,0,1,0,0]:
5:M77:Messier 77 is a barred spiral galaxy in the Cetus constellation.:[0,1,1,0,0]:
6:M91:Messier 91 is a barred spiral galaxy in the Coma Berenices constellation.:[0,1,1,0,0]:
7:M49:Messier 49 is a giant elliptical galaxy in the Virgo constellation.:[0,0,0,1,1]:
8:M60:Messier 60 is an elliptical galaxy in the Virgo constellation.:[0,0,0,0,1]:
9:NGC1073:NGC 1073 is a barred spiral galaxy in Cetus constellation.:[0,1,1,0,0]:
使用可能なSQL*Loader制御ファイルgalaxies_vec.ctl
を次に示します。
recoverable
LOAD DATA
infile 'galaxies_vec.csv'
INTO TABLE galaxies
fields terminated by ':'
trailing nullcols
(
id,
name char (50),
doc char (500),
embedding char (32000)
)
ノート:
CSVファイルのフィールド終端子として、カンマ区切りのベクトル(カンマで区切られたベクトル)は使用できません。別のデリミネータを使用する必要があります。これらの例では、デリミネータはコロン(:
)です。
galaxies_vec.csv
とgalaxies_vec.ctl
の2つのファイルを作成した後、お気に入りのSQLコマンドライン・ツールから直接、次の一連の指示を実行できます。
host sqlldr vector/vector@CDB1_PDB1 control=galaxies_vec.ctl log=galaxies_vec.log
SQL*Loader: Release 23.0.0.0.0 - Development on Thu Jan 11 19:46:21 2024
Version 23.4.0.23.00
Copyright (c) 1982, 2024, Oracle and/or its affiliates. All rights reserved.
Path used: Conventional
Commit point reached - logical record count 10
Table GALAXIES2:
9 Rows successfully loaded.
Check the log file:
galaxies_vec.log
for more information about the load.
SQL>
select * from galaxies;
ID NAME DOC EMBEDDING
--- ------ ---------------------------------------------------------- ---------------------------------
1 M31 Messier 31 is a barred spiral galaxy in the Andromeda ... [0,2.0E+000,2.0E+000,0,0]
2 M33 Messier 33 is a spiral galaxy in the Triangulum ... [0,0,1.0E+000,0,0]
3 M58 Messier 58 is an intermediate barred spiral galaxy ... [1.0E+000,1.0E+000,1.0E+000,0,0]
4 M63 Messier 63 is a spiral galaxy in the Canes Venatici ... [0,0,1.0E+000,0,0]
5 M77 Messier 77 is a barred spiral galaxy in the Cetus ... [0,1.0E+000,1.0E+000,0,0]
6 M91 Messier 91 is a barred spiral galaxy in the Coma ... [0,1.0E+000,1.0E+000,0,0]
7 M49 Messier 49 is a giant elliptical galaxy in the Virgo ... [0,0,0,1.0E+000,1.0E+000]
8 M60 Messier 60 is an elliptical galaxy in the Virgo ... [0,0,0,0,1.0E+000]
9 NGC1073 NGC 1073 is a barred spiral galaxy in Cetus ... [0,1.0E+000,1.0E+000,0,0]
9 rows selected.
SQL>
このロードの結果のログ・ファイル(galaxies_vec.log
)を次に示します。
cat galaxies_vec.log
SQL*Loader: Release 23.0.0.0.0 - Development on Thu Jan 11 19:46:21 2024
Version 23.4.0.23.00
Copyright (c) 1982, 2024, Oracle and/or its affiliates. All rights reserved.
Control File: galaxies_vec.ctl
Data File: galaxies_vec.csv
Bad File: galaxies_vec.bad
Discard File: none specified
(Allow all discards)
Number to load: ALL
Number to skip: 0
Errors allowed: 50
Bind array: 250 rows, maximum of 1048576 bytes
Continuation: none specified
Path used: Conventional
Table GALAXIES, loaded from every logical record.
Insert option in effect for this table: INSERT
TRAILING NULLCOLS option in effect
Column Name Position Len Term Encl Datatype
----------- ---------- ----- ---- ---- ----------
ID FIRST * : CHARACTER
NAME NEXT 50 : CHARACTER
DOC NEXT 500 : CHARACTER
EMBEDDING NEXT 32000 : CHARACTER
value used for ROWS parameter changed from 250 to 31
Table GALAXIES2:
9 Rows successfully loaded.
0 Rows not loaded due to data errors.
0 Rows not loaded because all WHEN clauses were failed.
Space allocated for bind array: 1017234 bytes(31 rows)
Read buffer bytes: 1048576
Total logical records skipped: 0
Total logical records read: 9
Total logical records rejected: 0
Total logical records discarded: 1
Run began on Thu Jan 11 19:46:21 2024
Run ended on Thu Jan 11 19:46:24 2024
Elapsed time was: 00:00:02.43
CPU time was: 00:00:00.03
$
ノート:
この例では、embedding char (32000)
のベクトルを使用しています。非常に大きなベクトルの場合は、LOBFILE
機能を使用できます。
関連トピック
親トピック: SQL*Loaderを使用したベクトル・データのロード