TL;DR
git clone https://github.com/ujnak/oml4py-on-db23ai-free
cd oml4py-on-db23ai-free
podman run -d --name oml4py-db -p 1521:1521 -v $PWD:/home/oracle/work container-registry.oracle.com/database/free:latest
podman exec oml4py-db sh ./work/config-oml4py.sh [passowrd for oml_user]
構成手順の説明
VirtualBox23ai QuickStart for OML4PY
https://practicalplsql.org/2024/08/11/virtualbox23ai-quickstart-for-oml4py/
作業はmacOSのpodmanで実行しているOracle Database Freeのコンテナで行っていますが、OML4Pyはx86-64限定なのでamd64のコンテナ(arm64ではなく)を使います。2025年5月28日時点のバージョンは23.8です。
以下より作業ログになります。
podman pull container-registry.oracle.com/database/free:latest
% podman pull container-registry.oracle.com/database/free:latest
Trying to pull container-registry.oracle.com/database/free:latest...
Getting image source signatures
Copying blob sha256:3c19df83dc536c431f1f991013d53f88157d03afed4452c014b3a0deb32add62
Copying blob
[中略]
Copying blob sha256:9339d36e49cd39cc09167f8fea58f3e8295ba7eeb23876bedc508454cd01be43
Copying config sha256:98201d89c4b33275f2ebb5c15d894c44d7e3273a23ed3b2435c5b329318db078
Writing manifest to image destination
98201d89c4b33275f2ebb5c15d894c44d7e3273a23ed3b2435c5b329318db078
%
mkdir oml4py
cd oml4py
% mkdir oml4py
% cd oml4py
oml4py %
Oracle Database Freeのコンテナとしてoml4py-dbを作成します。現在の作業ディレクトリをコンテナ内の/home/oracle/workにマウントしています。
podman run -d --name oml4py-db -p 1521:1521 -v $PWD:/home/oracle/work container-registry.oracle.com/database/free:latest
oml4py % podman run -d --name oml4py-db -p 1521:1521 -v $PWD:/home/oracle/work container-registry.oracle.com/database/free:latest
52f79d1da74c4c5ba6338b7c75a8f0d8a5dfcfcf10bb75cc7054e65f86b88418
oml4py %
コンテナの作成状況を確認します。
podman logs oml4py-db -f
DATABASE IS READY TO USE!と表示されていれば、コンテナの作成が完了し利用できる状態です。
oml4py % podman logs oml4py-db -f
Starting Oracle Net Listener.
Oracle Net Listener started.
Starting Oracle Database instance FREE.
Oracle Database instance FREE started.
The Oracle base remains unchanged with value /opt/oracle
#########################
DATABASE IS READY TO USE!
#########################
The following output is now a tail of the alert.log:
PDB$SEED(2):Autotune of undo retention is turned on.
PDB$SEED(2):Opening pdb with Resource Manager plan: DEFAULT_PLAN
(3):--ATTENTION--
(3):PARALLEL_MAX_SERVERS (with value 1) is insufficient. This may affect transaction recovery performance.
Modify PARALLEL_MAX_SERVERS parameter to a value > 4 (= parallel servers count computed from parameter FAST_START_PARALLEL_ROLLBACK) in PDB ID 3
FREEPDB1(3):Autotune of undo retention is turned on.
2025-05-28T03:57:10.300873+00:00
FREEPDB1(3):Opening pdb with Resource Manager plan: DEFAULT_PLAN
Completed: Pluggable database FREEPDB1 opened read write
Completed: ALTER DATABASE OPEN
2025-05-28T03:57:10.906901+00:00
===========================================================
Dumping current patch information
===========================================================
No patches have been applied
===========================================================
^C
oml4py %
OML4Pyのインストールを行うために、作成したコンテナoml4py-dbに接続します。
oml4py % podman exec -it oml4py-db bash
bash-4.4$
使用するPythonのバージョンが指定されているため、Python 3.12.6をインストールします。
4.2 Build and Install Python for Linux for On-Premises Databases
https://docs.oracle.com/en/database/oracle/machine-learning/oml4py/2-23ai/mlpug/build-and-install-python-linux-premises-databases.html
実行するコマンドが前後しますが、最初にOSにパッケージを追加します。4.2.3のyumコマンドの実行に当たります。
cat /etc/dnf/vars/ociregion
bash-4.4$ cat /etc/dnf/vars/ociregion
-us-phoenix-1
bash-4.4$
su -c "echo '' > /etc/dnf/vars/ociregion"
cat /etc/dnf/vars/ociregion
bash-4.4$ su -c "echo '' > /etc/dnf/vars/ociregion"
bash-4.4$ cat /etc/dnf/vars/ociregion
bash-4.4$
bash-4.4$ su -c "dnf -y install perl-Env libffi-devel openssl openssl-devel tk-devel xz-devel zlib-devel bzip2-devel readline-devel libuuid-devel ncurses-devel wget gcc"
Oracle Linux 8 BaseOS Latest (x86_64) 8.2 MB/s | 99 MB 00:12
Oracle Linux 8 Application Stream (x86_64) 8.6 MB/s | 71 MB 00:08
Oracle Linux 8 Development Packages (x86_64) 9.3 MB/s | 205 MB 00:21
Last metadata expiration check: 0:00:13 ago on Wed May 28 04:20:13 2025.
Package openssl-1:1.1.1k-14.el8_6.x86_64 is already installed.
Dependencies resolved.
============================================================================================
Package Arch Version Repository Size
============================================================================================
Installing:
bzip2-devel x86_64 1.0.6-28.el8_10 ol8_baseos_latest 224 k
gcc x86_64 8.5.0-26.0.1.el8_10 ol8_appstream 23 M
[中略]
tk-devel-1:8.6.8-1.el8.x86_64
wget-1.19.5-12.0.1.el8_10.x86_64
xorg-x11-proto-devel-2020.1-3.el8.noarch
xz-devel-5.2.4-4.el8_6.x86_64
zlib-devel-1.2.11-25.el8.x86_64
Complete!
bash-4.4$
wget https://www.python.org/ftp/python/3.12.6/Python-3.12.6.tgz
bash-4.4$ wget https://www.python.org/ftp/python/3.12.6/Python-3.12.6.tgz
--2025-05-28 04:28:39-- https://www.python.org/ftp/python/3.12.6/Python-3.12.6.tgz
Resolving www.python.org (www.python.org)... 151.101.64.223, 151.101.0.223, 151.101.128.223, ...
Connecting to www.python.org (www.python.org)|151.101.64.223|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 27009716 (26M) [application/octet-stream]
Saving to: 'Python-3.12.6.tgz'
Python-3.12.6.tgz 100%[============================>] 25.76M 2.72MB/s in 13s
2025-05-28 04:28:53 (1.94 MB/s) - 'Python-3.12.6.tgz' saved [27009716/27009716]
bash-4.4$
bash-4.4$ mkdir -p $HOME/python
bash-4.4$ tar -xvzf Python-3.12.6.tgz --strip-components=1 -C $HOME/python
Python-3.12.6/.devcontainer/
Python-3.12.6/.devcontainer/Dockerfile
Python-3.12.6/.devcontainer/devcontainer.json
Python-3.12.6/.editorconfig
Python-3.12.6/.mailmap
Python-3.12.6/.pre-commit-config.yaml
Python-3.12.6/.readthedocs.yml
[中略]
Python-3.12.6/configure
Python-3.12.6/configure.ac
Python-3.12.6/install-sh
Python-3.12.6/pyconfig.h.in
bash-4.4$
Pythonのコンパイルとインストールを行います。
bash-4.4$ cd $HOME/python
bash-4.4$ ./configure --enable-shared --prefix=$HOME/python
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking for Python interpreter freezing... ./_bootstrap_python
checking for python3.12... no
checking for python3.12... no
checking for python3.11... no
checking for python3.10... no
[中略]
configure:
If you want a release build with all stable optimizations active (PGO, etc),
please run ./configure --enable-optimizations
bash-4.4$
bash-4.4$ make clean; make
find . -depth -name '__pycache__' -exec rm -rf {} ';'
find . -name '*.py[co]' -exec rm -f {} ';'
find . -name '*.[oa]' -exec rm -f {} ';'
[中略]
LC_ALL=C sed -e 's,\$(\([A-Za-z0-9_]*\)),\$\{\1\},g' < Misc/python-config.sh >python-config
The following modules are *disabled* in configure script:
_sqlite3
The necessary bits to build these optional modules were not found:
_dbm _gdbm nis
To find the necessary bits, look in configure.ac and config.log.
Checked 111 modules (31 built-in, 75 shared, 1 n/a on linux-x86_64, 1 disabled, 3 missing, 0 failed on import)
bash-4.4$ make altinstall
Creating directory /home/oracle/python/bin
Creating directory /home/oracle/python/lib
if test "no-framework" = "no-framework" ; then \
/usr/bin/install -c python /home/oracle/python/bin/python3.12; \
else \
/usr/bin/install -c -s Mac/pythonw /home/oracle/python/bin/python3.12; \
fi
if test "3.12" != "3.12"; then \
if test -f /home/oracle/python/bin/python3.12 -o -h /home/oracle/python/bin/python3.12; \
then rm -f /home/oracle/python/bin/python3.12; \
fi; \
(cd /home/oracle/python/bin; ln python3.12 python3.12); \
fi
[中略]
Looking in links: /tmp/tmpryd272pl
Processing /tmp/tmpryd272pl/pip-24.2-py3-none-any.whl
Installing collected packages: pip
WARNING: The script pip3.12 is installed in '/home/oracle/python/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed pip-24.2
bash-4.4$
bash-4.4$ export PYTHONHOME=$HOME/python
bash-4.4$ export PATH=$PYTHONHOME/bin:$PATH
bash-4.4$ export LD_LIBRARY_PATH=$PYTHONHOME/lib:$LD_LIBRARY_PATH
bash-4.4$
bash-4.4$ cd $HOME/python/bin
bash-4.4$ ln -s python3.12 python3
bash-4.4$
pipコマンドを最新にします。
bash-4.4$ cd
bash-4.4$ python3 -m pip install --upgrade pip
Requirement already satisfied: pip in ./python/lib/python3.12/site-packages (24.2)
Collecting pip
Downloading pip-25.1.1-py3-none-any.whl.metadata (3.6 kB)
Downloading pip-25.1.1-py3-none-any.whl (1.8 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.8/1.8 MB 9.6 MB/s eta 0:00:00
Installing collected packages: pip
Attempting uninstall: pip
Found existing installation: pip 24.2
Uninstalling pip-24.2:
Successfully uninstalled pip-24.2
Successfully installed pip-25.1.1
bash-4.4$
インストールしたpython 3.12.6を実行します。
bash-4.4$ python3
Python 3.12.6 (main, May 28 2025, 04:34:28) [GCC 8.5.0 20210514 (Red Hat 8.5.0-26.0.1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import sys
>>> print(sys.executable)
/home/oracle/python/bin/python3
>>>
bash-4.4$
4.3 Install the Required Supporting Packages for Linux for On-Premises Databases
https://docs.oracle.com/en/database/oracle/machine-learning/oml4py/2-23ai/mlpug/install-required-supporting-packages-linux-premises-databases.html
--extra-index-url https://download.pytorch.org/whl/cpu
pandas==2.2.2
setuptools==70.0.0
scipy==1.14.0
matplotlib==3.8.4
oracledb==2.4.1
scikit-learn==1.5.1
numpy==2.0.1
onnxruntime==1.20.0
onnxruntime-extensions==0.12.0
onnx==1.17.0
torch==2.6.0
transformers==4.49.0
sentencepiece==0.2.0
bash-4.4$ pip3.12 install -r requirements.txt
Looking in indexes: https://pypi.org/simple, https://download.pytorch.org/whl/cpu
Collecting pandas==2.2.2 (from -r requirements.txt (line 2))
Downloading pandas-2.2.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (19 kB)
Collecting setuptools==70.0.0 (from -r requirements.txt (line 3))
Downloading https://download.pytorch.org/whl/setuptools-70.0.0-py3-none-any.whl (863 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 863.4/863.4 kB 7.7 MB/s eta 0:00:00
Collecting scipy==1.14.0 (from -r requirements.txt (line 4))
Downloading scipy-1.14.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (60 kB)
[中略]
Downloading urllib3-2.4.0-py3-none-any.whl (128 kB)
Downloading certifi-2025.4.26-py3-none-any.whl (159 kB)
Installing collected packages: sentencepiece, pytz, onnxruntime-extensions, mpmath, flatbuffers, urllib3, tzdata, typing-extensions, tqdm, threadpoolctl, sympy, six, setuptools, safetensors, regex, pyyaml, pyparsing, pycparser, protobuf, pillow, packaging, numpy, networkx, MarkupSafe, kiwisolver, joblib, idna, humanfriendly, hf-xet, fsspec, fonttools, filelock, cycler, charset-normalizer, certifi, scipy, requests, python-dateutil, onnx, jinja2, contourpy, coloredlogs, cffi, torch, scikit-learn, pandas, onnxruntime, matplotlib, huggingface-hub, cryptography, tokenizers, oracledb, transformers
Successfully installed MarkupSafe-3.0.2 certifi-2025.4.26 cffi-1.17.1 charset-normalizer-3.4.2 coloredlogs-15.0.1 contourpy-1.3.2 cryptography-45.0.3 cycler-0.12.1 filelock-3.18.0 flatbuffers-25.2.10 fonttools-4.58.0 fsspec-2025.5.1 hf-xet-1.1.2 huggingface-hub-0.32.2 humanfriendly-10.0 idna-3.10 jinja2-3.1.6 joblib-1.5.1 kiwisolver-1.4.8 matplotlib-3.8.4 mpmath-1.3.0 networkx-3.4.2 numpy-2.0.1 onnx-1.17.0 onnxruntime-1.20.0 onnxruntime-extensions-0.12.0 oracledb-2.4.1 packaging-25.0 pandas-2.2.2 pillow-11.2.1 protobuf-6.31.0 pycparser-2.22 pyparsing-3.2.3 python-dateutil-2.9.0.post0 pytz-2025.2 pyyaml-6.0.2 regex-2024.11.6 requests-2.32.3 safetensors-0.5.3 scikit-learn-1.5.1 scipy-1.14.0 sentencepiece-0.2.0 setuptools-70.0.0 six-1.17.0 sympy-1.13.1 threadpoolctl-3.6.0 tokenizers-0.21.1 torch-2.6.0+cpu tqdm-4.67.1 transformers-4.49.0 typing-extensions-4.13.2 tzdata-2025.2 urllib3-2.4.0
bash-4.4$
pandas==2.2.2
setuptools==70.0.0
scipy==1.14.0
matplotlib==3.8.4
oracledb==2.4.1
joblib==1.3.2
scikit-learn==1.5.1
numpy==2.0.1
bash-4.4$ . oraenv
ORACLE_SID = [FREE] ?
The Oracle base remains unchanged with value /opt/oracle
bash-4.4$
bash-4.4$ pip3.12 install -r requirements2.txt --target=$ORACLE_HOME/oml4py/modules
Collecting pandas==2.2.2 (from -r requirements2.txt (line 1))
Using cached pandas-2.2.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (19 kB)
Collecting setuptools==70.0.0 (from -r requirements2.txt (line 2))
Downloading setuptools-70.0.0-py3-none-any.whl.metadata (5.9 kB)
Collecting scipy==1.14.0 (from -r requirements2.txt (line 3))
Using cached scipy-1.14.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (60 kB)
Collecting matplotlib==3.8.4 (from -r requirements2.txt (line 4))
Using cached matplotlib-3.8.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (5.8 kB)
Collecting oracledb==2.4.1 (from -r requirements2.txt (line 5))
Using cached oracledb-2.4.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (5.2 kB)
Collecting joblib==1.3.2 (from -r requirements2.txt (line 6))
Downloading joblib-1.3.2-py3-none-any.whl.metadata (5.4 kB)
[中略]
Using cached six-1.17.0-py2.py3-none-any.whl (11 kB)
Using cached threadpoolctl-3.6.0-py3-none-any.whl (18 kB)
Using cached tzdata-2025.2-py2.py3-none-any.whl (347 kB)
Using cached pycparser-2.22-py3-none-any.whl (117 kB)
Installing collected packages: pytz, tzdata, threadpoolctl, six, setuptools, pyparsing, pycparser, pillow, packaging, numpy, kiwisolver, joblib, fonttools, cycler, scipy, python-dateutil, contourpy, cffi, scikit-learn, pandas, matplotlib, cryptography, oracledb
Successfully installed cffi-1.17.1 contourpy-1.3.2 cryptography-45.0.3 cycler-0.12.1 fonttools-4.58.0 joblib-1.3.2 kiwisolver-1.4.8 matplotlib-3.8.4 numpy-2.0.1 oracledb-2.4.1 packaging-25.0 pandas-2.2.2 pillow-11.2.1 pycparser-2.22 pyparsing-3.2.3 python-dateutil-2.9.0.post0 pytz-2025.2 scikit-learn-1.5.1 scipy-1.14.0 setuptools-70.0.0 six-1.17.0 threadpoolctl-3.6.0 tzdata-2025.2
bash-4.4$
インストールしたパッケージを確認します。python3を実行します。
bash-4.4$ python3
Python 3.12.6 (main, May 28 2025, 04:34:28) [GCC 8.5.0 20210514 (Red Hat 8.5.0-26.0.1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
以下のパッケージをインポートします。
import numpy
import pandas
import scipy
import matplotlib
import oracledb
import sklearn
import onnx
import torch
import onnxruntime_extensions
import transformers
import sentencepiece
>>> import numpy
>>> import pandas
>>> import scipy
>>> import matplotlib
>>> import oracledb
>>> import sklearn
>>> import onnx
>>> import torch
>>> import onnxruntime_extensions
>>> import transformers
>>> import sentencepiece
>>>
bash-4.4$
データベースにOML4Pyサーバーを構成します。
4.4 Install OML4Py Server for On-Premises Oracle Database
bash-4.4$ rpm -qa perl-Env
perl-Env-1.04-395.el8.noarch
bash-4.4$
export PYTHONHOME=$ORACLE_HOME/python
export PATH=$PYTHONHOME/bin:$ORACLE_HOME/bin:$PATH
export LD_LIBRARY_PATH=$PYTHONHOME/lib:$ORACLE_HOME/lib:$LD_LIBRARY_PATH
bash-4.4$ export ORACLE_HOME=/opt/oracle/product/23ai/dbhomeFree
bash-4.4$ export PYTHONHOME=$ORACLE_HOME/python
bash-4.4$ export PATH=$PYTHONHOME/bin:$ORACLE_HOME/bin:$PATH
bash-4.4$ export LD_LIBRARY_PATH=$PYTHONHOME/lib:$ORACLE_HOME/lib:$LD_LIBRARY_PATH
bash-4.4$
bash-4.4$ cd $ORACLE_HOME/oml4py/server
bash-4.4$
bash-4.4$ sqlplus / as sysdba
SQL*Plus: Release 23.0.0.0.0 - Production on Wed May 28 05:24:46 2025
Version 23.8.0.25.04
Copyright (c) 1982, 2025, Oracle. All rights reserved.
Connected to:
Oracle Database 23ai Free Release 23.0.0.0.0 - Develop, Learn, and Run for Free
Version 23.8.0.25.04
SQL>
公式ドキュメントの手順ではルート・コンテナにOML4Pyサーバーを構成していますが、どう考えても不要なのでスキップします。PDBのFREEPDB1にのみOML4Pyサーバーを構成します。
SQL> spool install_pdb.txt
SQL>
alter session set container=FREEPDB1;
SQL> alter session set container=FREEPDB1;
Session altered.
SQL>
SQL> @pyqcfg.sql SYSAUX TEMP /opt/oracle/product/23ai/dbhomeFree/python
Session altered.
no rows selected
old 11: :permtbl_value := nvl('&1', 'SYSAUX');
new 11: :permtbl_value := nvl('SYSAUX', 'SYSAUX');
old 12: :temptbl_value := nvl('&2', default_temptbl);
new 12: :temptbl_value := nvl('TEMP', default_temptbl);
old 18: :pythonhome_value := nvl('&3', :orahome_value || '/python');
new 18: :pythonhome_value := nvl('/opt/oracle/product/23ai/dbhomeFree/python', :orahome_value || '/python');
PL/SQL procedure successfully completed.
[中略]
Session altered.
Session altered.
PL/SQL procedure successfully completed.
Session altered.
SQL>
スクリプトが終了したら、OML4Pyサーバーの構成は完了です。sqlplusを終了します。
SQL> exit
Disconnected from Oracle Database 23ai Free Release 23.0.0.0.0 - Develop, Learn, and Run for Free
Version 23.8.0.25.04
bash-4.4$
bash-4.4$ sqlplus / as sysdba
SQL*Plus: Release 23.0.0.0.0 - Production on Wed May 28 07:45:36 2025
Version 23.8.0.25.04
Copyright (c) 1982, 2025, Oracle. All rights reserved.
Connected to:
Oracle Database 23ai Free Release 23.0.0.0.0 - Develop, Learn, and Run for Free
Version 23.8.0.25.04
SQL> alter session set container=FREEPDB1;
Session altered.
SQL> @pyquser.sql oml_user USERS TEMP unlimited pyqadmin
Session altered.
Enter value for password: *********
old 1: create user &&1 identified by &password
new 1: create user oml_user identified by oracle
old 2: default tablespace &&2
new 2: default tablespace USERS
old 3: temporary tablespace &&3
new 3: temporary tablespace TEMP
old 4: quota &&4 on &&2
new 4: quota unlimited on USERS
User created.
old 4: 'create procedure, create mining model to &&1';
new 4: 'create procedure, create mining model to oml_user';
old 6: IF lower('&&5') = 'pyqadmin' THEN
new 6: IF lower('pyqadmin') = 'pyqadmin' THEN
old 7: execute immediate 'grant PYQADMIN to &&1';
new 7: execute immediate 'grant PYQADMIN to oml_user';
PL/SQL procedure successfully completed.
Session altered.
SQL> exit
Disconnected from Oracle Database 23ai Free Release 23.0.0.0.0 - Develop, Learn, and Run for Free
Version 23.8.0.25.04
bash-4.4$
select * from sys.pyq_config;
exit
bash-4.4$ sqlplus oml_user/*******@localhost/freepdb1
SQL*Plus: Release 23.0.0.0.0 - Production on Wed May 28 05:55:17 2025
Version 23.8.0.25.04
Copyright (c) 1982, 2025, Oracle. All rights reserved.
Last Successful login time: Wed May 28 2025 05:54:33 +00:00
Connected to:
Oracle Database 23ai Free Release 23.0.0.0.0 - Develop, Learn, and Run for Free
Version 23.8.0.25.04
SQL> select * from sys.pyq_config;
NAME
--------------------------------------------------------------------------------
VALUE
--------------------------------------------------------------------------------
PYTHONHOME
TRUE
PYTHONPATH
/opt/oracle/product/23ai/dbhomeFree/oml4py/modules
VERSION
2.0
NAME
--------------------------------------------------------------------------------
VALUE
--------------------------------------------------------------------------------
PLATFORM
ODB
DSWLIST
oml.*;pandas.*;numpy.*;matplotlib.*;sklearn.*
SQL> exit;
Disconnected from Oracle Database 23ai Free Release 23.0.0.0.0 - Develop, Learn, and Run for Free
Version 23.8.0.25.04
bash-4.4$
インストールされたOML4Pyサーバーの動作確認を行います。
export PYTHONPATH=$ORACLE_HOME/oml4py/modules
bash-4.4$ python3
Python 3.12.9 (main, Feb 27 2025, 10:55:36) [GCC 8.5.0 20210514 (Red Hat 8.5.0-18.0.6)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
パッケージomlを読み込み、データベースにユーザーoml_userで接続します。パスワードはユーザー作成時に設定した値に置き換えます。
import oml
oml.connect(user='oml_user',password='password',port=1521,host='localhost',service_name='freepdb1')
>>> import oml
>>> oml.connect(user='oml_user',password='******',port=1521,host='localhost',service_name='freepdb1')
>>>
PythonのスクリプトとしてTESTを作成します。
>>> oml.script.create("TEST", func='def func():return 1 + 1', overwrite=True)
>>>
TESTを実行し、結果を表示します。
>>> res = oml.do_eval(func='TEST')
>>> res
2
>>>
スクリプトTESTを削除します。
>>> oml.script.drop("TEST")
>>>
bash-4.4$
以上でOML4Pyのサーバーのインストールは完了しました。
bash-4.4$ cd
bash-4.4$ ls work
V1048628-01.zip
bash-4.4$
V1048628-01.zipを解凍します。/home/oracle以下にclientというディレクトリが作成され、その下にV1048628-01.zipの内容が保存されます。
bash-4.4$ unzip work/V1048628-01.zip
Archive: work/V1048628-01.zip
inflating: client/client.pl
inflating: client/OML4PInstallShared.pm
inflating: client/oml-2.1-cp312-cp312-linux_x86_64.whl
extracting: client/oml4py.ver
bash-4.4$
export PATH=$PYTHONHOME/bin:$PATH
export LD_LIBRARY_PATH=$PYTHONHOME/lib:$LD_LIBRARY_PATH
unset PYTHONPATH
bash-4.4$ export PYTHONHOME=$HOME/python
bash-4.4$ export PATH=$PYTHONHOME/bin:$PATH
bash-4.4$ export LD_LIBRARY_PATH=$PYTHONHOME/lib:$LD_LIBRARY_PATH
bash-4.4$ unset PYTHONPATH
bash-4.4$ pip3 install client/oml-2.1-cp312-cp312-linux_x86_64.whl
Processing ./client/oml-2.1-cp312-cp312-linux_x86_64.whl
Requirement already satisfied: numpy>=2.0.1 in ./python/lib/python3.12/site-packages (from oml==2.1) (2.0.1)
Requirement already satisfied: pandas>=2.2.2 in ./python/lib/python3.12/site-packages (from oml==2.1) (2.2.2)
Requirement already satisfied: scipy>=1.14.0 in ./python/lib/python3.12/site-packages (from oml==2.1) (1.14.0)
Requirement already satisfied: matplotlib>=3.8.4 in ./python/lib/python3.12/site-packages (from oml==2.1) (3.8.4)
Requirement already satisfied: oracledb>=2.4.1 in ./python/lib/python3.12/site-packages (from oml==2.1) (2.4.1)
Requirement already satisfied: scikit-learn>=1.5.1 in ./python/lib/python3.12/site-packages (from oml==2.1) (1.5.1)
[中略]
Requirement already satisfied: joblib>=1.2.0 in ./python/lib/python3.12/site-packages (from scikit-learn>=1.5.1->oml==2.1) (1.5.1)
Requirement already satisfied: threadpoolctl>=3.1.0 in ./python/lib/python3.12/site-packages (from scikit-learn>=1.5.1->oml==2.1) (3.6.0)
Installing collected packages: oml
Successfully installed oml-2.1
bash-4.4$
bash-4.4$ perl -Iclient client/client.pl
Oracle Machine Learning for Python 2.1 Client.
Copyright (c) 2018, 2025 Oracle and/or its affiliates. All rights reserved.
Checking platform .................. Pass
Checking Python .................... Pass
Checking dependencies .............. Pass
Checking OML4P version ............. Pass
Current configuration
Python Version ................... 3.12.6
PYTHONHOME ....................... /home/oracle/python
Existing OML4P module version .... 2.1
Operation ........................ Install/Upgrade
Proceed? [yes]
Found existing installation: oml 2.1
Uninstalling oml-2.1:
Successfully uninstalled oml-2.1
Processing ./client/oml-2.1-cp312-cp312-linux_x86_64.whl
Installing collected packages: oml
Successfully installed oml-2.1
Done
bash-4.4$
bash-4.4$ python3
Python 3.12.6 (main, May 28 2025, 07:33:58) [GCC 8.5.0 20210514 (Red Hat 8.5.0-26.0.1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
oml.__version__
oml.__path__
oml.connect(user='oml_user',password='*********',port=1521,host='localhost',service_name='freepdb1')
>>> import oml
>>> oml.__version__
'2.1'
>>> oml.__path__
['/home/oracle/python/lib/python3.12/site-packages/oml']
>>> oml.connect(user='oml_user',password='*******',port=1521,host='localhost',service_name='freepdb1')
>>>
ONNX Pipeline Models : Text Embedding
https://docs.oracle.com/en/database/oracle/oracle-database/23/vecse/onnx-pipeline-models-text-embedding.html
python3を起動し、データベースに接続したところから作業を始めます。
ONNXPipelineConfig.show_preconfigured()
ONNXPipelineConfig.show_templates()
pipeline.export2file("all-MiniLM-L6-v2",output_dir="./work")
>>> from oml.utils import ONNXPipeline, ONNXPipelineConfig
>>> ONNXPipelineConfig.show_preconfigured()
['sentence-transformers/all-mpnet-base-v2', 'sentence-transformers/all-MiniLM-L6-v2', 'sentence-transformers/multi-qa-MiniLM-L6-cos-v1', 'sentence-transformers/distiluse-base-multilingual-cased-v2', 'sentence-transformers/all-MiniLM-L12-v2', 'BAAI/bge-small-en-v1.5', 'BAAI/bge-base-en-v1.5', 'taylorAI/bge-micro-v2', 'intfloat/e5-small-v2', 'intfloat/e5-base-v2', 'thenlper/gte-base', 'thenlper/gte-small', 'TaylorAI/gte-tiny', 'sentence-transformers/paraphrase-multilingual-mpnet-base-v2', 'intfloat/multilingual-e5-base', 'intfloat/multilingual-e5-small', 'sentence-transformers/stsb-xlm-r-multilingual', 'Snowflake/snowflake-arctic-embed-xs', 'Snowflake/snowflake-arctic-embed-s', 'Snowflake/snowflake-arctic-embed-m', 'mixedbread-ai/mxbai-embed-large-v1', 'openai/clip-vit-large-patch14', 'google/vit-base-patch16-224', 'microsoft/resnet-18', 'microsoft/resnet-50', 'WinKawaks/vit-tiny-patch16-224', 'Falconsai/nsfw_image_detection', 'WinKawaks/vit-small-patch16-224', 'nateraw/vit-age-classifier', 'rizvandwiki/gender-classification', 'AdamCodd/vit-base-nsfw-detector', 'trpakov/vit-face-expression', 'BAAI/bge-reranker-base']
>>> ONNXPipelineConfig.show_templates()
['image_convnext', 'image_vit', 'multimodal_clip', 'text']
>>> pipeline = ONNXPipeline(model_name="sentence-transformers/all-MiniLM-L6-v2")
>>> pipeline.export2file("all-MiniLM-L6-v2",output_dir="./work")
tokenizer_config.json: 100%|███████████████████| 350/350 [00:00<00:00, 2.17MB/s]
vocab.txt: 100%|██████████████████████████████| 232k/232k [00:00<00:00, 745kB/s]
special_tokens_map.json: 100%|██████████████████| 112/112 [00:00<00:00, 546kB/s]
tokenizer.json: 100%|████████████████████████| 466k/466k [00:00<00:00, 2.63MB/s]
config.json: 100%|█████████████████████████████| 612/612 [00:00<00:00, 3.43MB/s]
model.safetensors: 100%|███████████████████| 90.9M/90.9M [00:09<00:00, 9.96MB/s]
>>>
bash-4.4$
cd
bash-4.4$ cd
bash-4.4$ ls work
V1048628-01.zip all-MiniLM-L6-v2.onnx
bash-4.4$
alter session set container=FREEPDB1;
bash-4.4$ sqlplus / as sysdba
SQL*Plus: Release 23.0.0.0.0 - Production on Wed May 28 08:01:34 2025
Version 23.8.0.25.04
Copyright (c) 1982, 2025, Oracle. All rights reserved.
Connected to:
Oracle Database 23ai Free Release 23.0.0.0.0 - Develop, Learn, and Run for Free
Version 23.8.0.25.04
SQL> alter session set container=FREEPDB1;
Session altered.
SQL>
作成するディレクトリの名前はONNX_IMPORT、実体となるディレクトリにONNXモデルがエクスポートされている/home/oracle/workを指定します。ユーザーOML_USERにディレクトリONNX_IMPORTへのアクセス権限とマイニング・モデルを作成する権限を与えます。
grant read, write on directory onnx_import to oml_user;
grant create mining model to oml_user;
SQL> create or replace directory ONNX_IMPORT as '/home/oracle/work';
Directory created.
SQL> grant read, write on directory onnx_import to oml_user;
Grant succeeded.
SQL> grant create mining model to oml_user;
Grant succeeded.
SQL> exit
Disconnected from Oracle Database 23ai Free Release 23.0.0.0.0 - Develop, Learn, and Run for Free
Version 23.8.0.25.04
bash-4.4$
bash-4.4$ sqlplus oml_user/*********@localhost/freepdb1
SQL*Plus: Release 23.0.0.0.0 - Production on Wed May 28 08:07:15 2025
Version 23.8.0.25.04
Copyright (c) 1982, 2025, Oracle. All rights reserved.
Last Successful login time: Wed May 28 2025 07:52:06 +00:00
Connected to:
Oracle Database 23ai Free Release 23.0.0.0.0 - Develop, Learn, and Run for Free
Version 23.8.0.25.04
SQL>
ONNXモデルall-MiniLM-L6-v2.onnxをALL_MINILM_L6_V2として、データベースにロードします。
begin
dbms_vector.load_onnx_model(
directory => 'ONNX_IMPORT'
,file_name => 'all-MiniLM-L6-v2.onnx'
,model_name => 'ALL_MINILM_L6_V2'
);
end;
/
SQL> begin
dbms_vector.load_onnx_model(
directory => 'ONNX_IMPORT'
,file_name => 'all-MiniLM-L6-v2.onnx'
,model_name => 'ALL_MINILM_L6_V2'
);
end;
/ 2 3 4 5 6 7 8
PL/SQL procedure successfully completed.
SQL>
ビューUSER_MINING_MODELSから、データベースにロードされたモデルを確認します。
select MODEL_NAME, ALGORITHM from user_mining_models;
SQL> select MODEL_NAME, ALGORITHM from user_mining_models;
MODEL_NAME
--------------------------------------------------------------------------------
ALGORITHM
------------------------------
ALL_MINILM_L6_V2
ONNX
SQL>
データベースにロードされたモデルALL_MINILM_L6_V2を使ってembeddingを生成します。
select vector_embedding(ALL_MINILM_L6_V2 using 'test' as data);
SQL> select vector_embedding(ALL_MINILM_L6_V2 using 'test' as data);
VECTOR_EMBEDDING(ALL_MINILM_L6_V2USING'TEST'ASDATA)
--------------------------------------------------------------------------------
[1.15733938E-002,2.51362529E-002,-3.67018655E-002,5.93249127E-002,
SQL>
以上ですべての作業は完了です。
SQL> exit
Disconnected from Oracle Database 23ai Free Release 23.0.0.0.0 - Develop, Learn, and Run for Free
Version 23.8.0.25.04
bash-4.4$
コンテナから切断します。
oml4py % ls
all-MiniLM-L6-v2.onnx V1048628-01.zip
oml4py %
alter session set container=FREEPDB1;
bash-4.4$ sqlplus / as sysdba
SQL*Plus: Release 23.0.0.0.0 - Production on Wed May 28 09:52:15 2025
Version 23.7.0.25.01
Copyright (c) 1982, 2025, Oracle. All rights reserved.
Connected to:
Oracle Database 23ai Free Release 23.0.0.0.0 - Develop, Learn, and Run for Free
Version 23.7.0.25.01
SQL> alter session set container=FREEPDB1;
Session altered.
SQL>
create user oml_user identified by ******** default tablespace users temporary tablespace temp;
alter user oml_user quota unlimited on users;
grant create session, create table, create view, create procedure, create mining model to oml_user;
grant execute on ctxsys.ctx_ddl to oml_user;
SQL> create user oml_user identified by ******** default tablespace users temporary tablespace temp;
User created.
SQL> alter user oml_user quota unlimited on users;
User altered.
SQL> grant create session, create table, create view, create procedure, create mining model to oml_user;
Grant succeeded.
SQL> grant execute on ctxsys.ctx_ddl to oml_user;
Grant succeeded.
SQL>
ONNXモデルを配置するディレクトリの作成と権限の付与
create or replace directory onnx_import as '/opt/oracle/apex';
grant read, write on directory onnx_import to oml_user;
SQL> create or replace directory onnx_import as '/opt/oracle/apex';
Directory created.
SQL> grant read, write on directory onnx_import to oml_user;
Grant succeeded.
SQL> exit
Disconnected from Oracle Database 23ai Free Release 23.0.0.0.0 - Develop, Learn, and Run for Free
Version 23.7.0.25.01
bash-4.4$
ユーザーOML_USERによるONNXモデルのロードとembeddingの生成
bash-4.4$ sqlplus oml_user/******@localhost/freepdb1
SQL*Plus: Release 23.0.0.0.0 - Production on Wed May 28 10:01:56 2025
Version 23.7.0.25.01
Copyright (c) 1982, 2025, Oracle. All rights reserved.
Connected to:
Oracle Database 23ai Free Release 23.0.0.0.0 - Develop, Learn, and Run for Free
Version 23.7.0.25.01
SQL>
ONNXモデルのロードとembedingの生成
begin
dbms_vector.load_onnx_model(
directory => 'ONNX_IMPORT'
,file_name => 'all-MiniLM-L6-v2.onnx'
,model_name => 'ALL_MINILM_L6_V2'
);
end;
/
SQL> begin
dbms_vector.load_onnx_model(
directory => 'ONNX_IMPORT'
,file_name => 'all-MiniLM-L6-v2.onnx'
,model_name => 'ALL_MINILM_L6_V2'
);
end;
/ 2 3 4 5 6 7 8
PL/SQL procedure successfully completed.
SQL> select MODEL_NAME, ALGORITHM from user_mining_models;
MODEL_NAME
--------------------------------------------------------------------------------
ALGORITHM
------------------------------
ALL_MINILM_L6_V2
ONNX
SQL> select vector_embedding(ALL_MINILM_L6_V2 using 'test' as data);
VECTOR_EMBEDDING(ALL_MINILM_L6_V2USING'TEST'ASDATA)
--------------------------------------------------------------------------------
[1.15733724E-002,2.51362175E-002,-3.6701858E-002,5.93249165E-002,
SQL>