generateEmbedding method
Implementation
Future<CactusEmbeddingResult> generateEmbedding({required String text, String? modelName}) async {
return await _handleLock.synchronized(() async {
if (_lastInitializedModel == null || !await _isModelDownloaded(_lastInitializedModel!)) {
throw Exception('Model $_lastInitializedModel is not downloaded. Please download it before generating completions.');
}
final model = modelName ?? _lastInitializedModel ?? defaultInitParams.model;
final currentHandle = await _getValidatedHandle(model: model);
final quantization = (await Supabase.getModel(model))?.quantization ?? 8;
try {
if(currentHandle != null) {
final result = await CactusContext.generateEmbedding(currentHandle, text, quantization);
_logEmbeddingTelemetry(result, model, success: result.success, message: result.errorMessage);
return result;
} else {
throw Exception('Context not initialized');
}
} catch (e) {
_logEmbeddingTelemetry(null, model, success: false, message: e.toString());
rethrow;
}
});
}