create static method
Future<LitertEmbeddingModel>
create({
- required String modelPath,
- required String tokenizerPath,
- PreferredBackend? preferredBackend,
- int? inputSequenceLength,
- int? outputDimension,
- VoidCallback? onClose,
Load a .tflite embedding model from disk and prepare it for inference
on a background isolate.
modelPath points at a .tflite file (Gecko 64, EmbeddingGemma 256,
etc.). tokenizerPath is the matching SentencePiece .model or exported
.json. preferredBackend is accepted for API symmetry but currently
ignored — embeddings run on CPU (the GPU delegate returns zero vectors;
see _backendFor). Input sequence length and output dimension are
auto-detected from the compiled model's tensor layouts; pass them to
override (rare).
Caller owns the returned instance and must call close when done.
Implementation
static Future<LitertEmbeddingModel> create({
required String modelPath,
required String tokenizerPath,
PreferredBackend? preferredBackend,
int? inputSequenceLength,
int? outputDimension,
VoidCallback? onClose,
}) async {
final worker = await EmbeddingWorker.spawn(
modelPath: modelPath,
tokenizerPath: tokenizerPath,
backend: _backendFor(preferredBackend),
inputSequenceLength: inputSequenceLength,
outputDimension: outputDimension,
);
return LitertEmbeddingModel._(worker, onClose ?? () {});
}