embedBatch static method

Future<List<List<double>>> embedBatch(
  1. List<String> texts, {
  2. int concurrency = 1,
  3. void onProgress(
    1. int completed,
    2. int total
    )?,
})

Batch embed multiple texts (sequential processing).

ONNX session doesn't support concurrent access, so processing is sequential. Each embed call is dispatched to the worker isolate.

texts: List of texts to embed onProgress: Progress callback (completed count, total count)

Implementation

static Future<List<List<double>>> embedBatch(
  List<String> texts, {
  int concurrency = 1,
  void Function(int completed, int total)? onProgress,
}) async {
  if (_workerSendPort == null) {
    throw Exception("EmbeddingService not initialized. Call init() first.");
  }

  if (texts.isEmpty) return <List<double>>[];

  final results = <List<double>>[];
  for (var i = 0; i < texts.length; i++) {
    final embedding = await embed(texts[i]);
    results.add(embedding);
    onProgress?.call(i + 1, texts.length);
  }
  return results;
}