embedBatchAsync method

Future<EmbeddingsResult> embedBatchAsync(
  1. EmbeddingsRequest request
)

Embed a batch through the lifecycle-owned generated-proto ABI, running the blocking native call in a short-lived worker isolate (Isolate.run) so the calling isolate — usually the Flutter UI isolate — stays responsive. Embedding a large batch (e.g. RAG ingest) is a long synchronous block; on the UI isolate it freezes frames. Mirrors dart_bridge_stt.dart's transcribeLifecycleProtoAsync: this ABI is lifecycle-owned (no Dart-held handle), so the worker re-resolves the engine via the commons model lifecycle — nothing isolate-bound crosses.

Implementation

Future<EmbeddingsResult> embedBatchAsync(EmbeddingsRequest request) async {
  _validateRequest(request);

  final override = _embedBatchLifecycleProtoForTesting;
  if (override != null) {
    return override(request);
  }

  if (RacNative.bindings.rac_embeddings_embed_batch_lifecycle_proto == null) {
    throw UnsupportedError(
      'rac_embeddings_embed_batch_lifecycle_proto is unavailable',
    );
  }

  final requestBytes = request.writeToBuffer();
  final resultBytes =
      await Isolate.run(() => _embeddingsEmbedBatchWorker(requestBytes));
  return EmbeddingsResult.fromBuffer(resultBytes);
}