No Python, No Problem: Model Inference with ONNX in Java, or Any Other Language
May 30, 2025Stefan Webb

Summary
This post details how to export HuggingFace models (specifically text embedding models) into the ONNX format and then perform inference using these ONNX models directly from Java. It covers exporting both the model and its tokenizer using Python libraries like `sentence-transformers` and `onnxruntime-extensions`, and then demonstrates how to load and run these ONNX files within a Java application using the ONNX Runtime Java API. This enables local, language-agnostic model inference for AI applications, particularly relevant for data ingestion into vector databases like Milvus.
More from the AI Data Storage Engine trail
- Milvus Snapshots: Point-in-Time Collection Views Without Copying Data
- Announcing Milvus 3.0: Lake-Native Vector Search and a More Powerful Retrieval Engine
- How to Recover Milvus Data After etcd Corruption Without a Backup
- Open Tag: An Open-Source Claude Tag for Claude Code and Codex
- How Force Merge Compaction Nearly Doubled Milvus Search QPS