createEmbeddingModel method
Future<EmbeddingModel>
createEmbeddingModel({
- String? modelPath,
- String? tokenizerPath,
- PreferredBackend? preferredBackend,
override
Creates and returns a new EmbeddingModel instance.
Modern API: If paths are not provided, uses the active embedding model set via
FlutterGemma.installEmbeddingModel()
or modelManager.setActiveModel()
.
Legacy API: Provide explicit paths for backward compatibility.
modelPath
— path to the embedding model file (optional if active model set).
tokenizerPath
— path to the tokenizer file (optional if active model set).
preferredBackend
— backend preference (e.g., CPU, GPU).
Implementation
@override
Future<EmbeddingModel> createEmbeddingModel({
String? modelPath,
String? tokenizerPath,
PreferredBackend? preferredBackend,
}) async {
// Modern API: Use active embedding model if paths not provided
if (modelPath == null || tokenizerPath == null) {
// Web: Embedding models not fully supported yet, but keep API consistent
if (modelManager.activeEmbeddingModel == null) {
throw Exception('No active embedding model set. Use `FlutterGemma.installEmbeddingModel()` or `modelManager.setActiveModel()` to set a model first');
}
// TODO: Implement full embedding model support on web
throw UnimplementedError('Embedding models are not fully supported on web platform yet');
}
final model = _initializedEmbeddingModel ??= WebEmbeddingModel(
onClose: () {
_initializedEmbeddingModel = null;
},
);
return Future.value(model);
}