init static method
Initialize ONNX model
Provide either modelBytes (loads from memory) or modelPath (loads from file).
modelPath is recommended for memory optimization.
Implementation
static Future<void> init({
Uint8List? modelBytes,
String? modelPath,
OrtSessionOptions? options,
}) async {
OrtEnv.instance.init();
final sessionOptions = options ?? OrtSessionOptions();
if (modelPath != null) {
// Load from file (Memory efficient)
// Note: Assuming 'fromFile' exists based on standard ONNX Runtime API patterns.
// If the specific binding uses a different name (e.g. create path), we'll catch it.
// The web search indicated session creation from file is supported.
try {
_session = OrtSession.fromFile(File(modelPath), sessionOptions);
if (debugMode) {
debugPrint('[EmbeddingService] Loaded model from file: $modelPath');
}
} catch (e) {
// Fallback or rethrow?
// If fromFile is not found, we might need to check if binding exposes naming differently.
// But for now let's assume standard API.
rethrow;
}
} else if (modelBytes != null) {
// Legacy: Load from memory (Double buffering)
_session = OrtSession.fromBuffer(modelBytes, sessionOptions);
if (debugMode) {
debugPrint('[EmbeddingService] Loaded model from memory buffer');
}
} else {
throw ArgumentError('Either modelBytes or modelPath must be provided');
}
}