sentence-transformers' native ONNX backend has compatibility issues with nomic-embed-text due to:
- Custom code requirement: nomic-embed-text uses
trust_remote_code=Truefor custom model architecture - safe_serialization argument: sentence-transformers passes this argument to ORTModel which doesn't accept it
- Multiple ONNX files: The model has 8 ONNX variants, causing ambiguity warnings
Error message:
ORTModel._from_pretrained() got an unexpected keyword argument 'safe_serialization'
Solution: Use Optimum directly instead:
from optimum.onnxruntime import ORTModelForFeatureExtraction
model = ORTModelForFeatureExtraction.from_pretrained(
"nomic-ai/nomic-embed-text-v1.5",
file_name="model_int8.onnx",
subfolder="onnx",
provider="CPUExecutionProvider",
trust_remote_code=True
)
This approach is actually better as it gives you full control over which ONNX variant to load.