Skip to main content

Load ONNX embedding models into Oracle AI Database with one command

Project description

onnx2oracle

Load ONNX embedding models into Oracle AI Database with one command.

CI Docs PyPI License: MIT

pip install onnx2oracle
onnx2oracle docker up
onnx2oracle load all-MiniLM-L6-v2 --target local
onnx2oracle verify --target local

Embeddings run entirely in-database via Oracle's VECTOR_EMBEDDING (no external API calls, no network round-trips, no serving layer).

How it works

onnx2oracle downloads a sentence-transformer model from HuggingFace, wraps its tokenizer as ONNX ops, merges it with the transformer body, and appends pooling + L2 normalization. The resulting single-graph ONNX is uploaded to Oracle via DBMS_VECTOR.LOAD_ONNX_MODEL, after which you can query it with:

SELECT VECTOR_EMBEDDING(ALL_MINILM_L6_V2 USING 'hello world' AS DATA) FROM dual;

Architecture

See Architecture Diagram (Excalidraw, open at excalidraw.com) and Architecture Overview for visual documentation of how the pieces fit together.

The augmented ONNX pipeline is the interesting bit. HuggingFace ships a Python tokenizer; Oracle needs an ONNX graph it can call directly. pipeline.py wraps the fast tokenizer as ONNX ops via onnxruntime-extensions, welds it onto the transformer body, bolts mean- or CLS-pooling on top, appends L2 normalization, and emits a single graph that goes string to float32 vector. That's what gets uploaded via DBMS_VECTOR.LOAD_ONNX_MODEL.

Directory Structure

src/onnx2oracle/
├── cli.py            # Typer commands: load, verify, presets, docker, config
├── presets.py        # 6 curated ModelSpecs
├── connection.py     # DSN resolution (CLI > env > toml > target > prompt)
├── pipeline.py       # HF model -> augmented ONNX bytes
├── loader.py         # DBMS_VECTOR.LOAD_ONNX_MODEL wrapper
└── verify.py         # Smoke test via VECTOR_EMBEDDING
docker/
└── docker-compose.yml  # Oracle 26ai Free (gvenzl fallback documented)
docs/                 # GitHub Pages site + architecture docs
tests/                # Unit + integration (needs --run-integration)

Presets

Preset Dims Size Pooling
all-MiniLM-L6-v2 384 90 MB mean
all-MiniLM-L12-v2 384 130 MB mean
all-mpnet-base-v2 768 420 MB mean
bge-small-en-v1.5 384 130 MB cls
nomic-embed-text-v1 768 540 MB mean

Any sentence-transformer-style HuggingFace model also works via --from-huggingface.

Common tasks

# List all presets
onnx2oracle presets

# Load into a cloud ADB
onnx2oracle load all-mpnet-base-v2 --dsn 'app/pass@adb.region.oraclecloud.com:1522/xxx_high'

# Load a non-preset model
onnx2oracle load --from-huggingface BAAI/bge-base-en-v1.5 \
  --pooling cls --normalize --dims 768 --name BGE_BASE_EN_V1_5

# End-to-end verification
onnx2oracle verify --target local

Requirements

  • Python 3.10+
  • Docker (for the local Oracle 26ai Free path) or any Oracle 23ai/26ai instance
  • ~2 GB free RAM during model augmentation
  • ~1 GB DB storage per preset

Documentation

Full guide at jasperan.github.io/onnx2oracle.

Development

git clone https://github.com/jasperan/onnx2oracle
cd onnx2oracle
conda create -n onnx2oracle python=3.12 -y
conda activate onnx2oracle
pip install -e ".[dev]"
pytest tests/ -v -m "not slow and not integration"

License

MIT.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

onnx2oracle-0.1.1.tar.gz (19.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

onnx2oracle-0.1.1-py3-none-any.whl (16.9 kB view details)

Uploaded Python 3

File details

Details for the file onnx2oracle-0.1.1.tar.gz.

File metadata

  • Download URL: onnx2oracle-0.1.1.tar.gz
  • Upload date:
  • Size: 19.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for onnx2oracle-0.1.1.tar.gz
Algorithm Hash digest
SHA256 787522d5f2673d8f039756b122edefd8f10e4b64631d4b990d8fb31d9d23c05f
MD5 5e1ab8d36973dd9279c78fda010e7b2a
BLAKE2b-256 4de477e8ee7cc88ca414ab1f0c7491cf7421c735c323cd3910f7557ab8d2d834

See more details on using hashes here.

File details

Details for the file onnx2oracle-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: onnx2oracle-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 16.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for onnx2oracle-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 dcbfc2c3db2ca389fb6a75bfe19c692873c78e44d16aede538ca8793206d564c
MD5 fda222ff9fcf39d985a4daccf4166dda
BLAKE2b-256 d5ce0d72ff8ab1e2c5075e8e4bf1a1a84df511b98d4daf0ddf911af6a959f54d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page