embedBatch static method
Batch embed multiple texts (sequential processing)
ONNX session doesn't support concurrent access, so processing is sequential
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, // Sequential due to ONNX session limitation
void Function(int completed, int total)? onProgress,
}) async {
return _executor.run(() async {
if (_session == null) {
throw Exception("EmbeddingService not initialized. Call init() first.");
}
if (texts.isEmpty) return <List<double>>[];
final results = <List<double>>[];
if (concurrency != 1 && debugMode) {
debugPrint(
'[EmbeddingService] concurrency=$concurrency is ignored; embedding runs serially.',
);
}
// Sequential processing (ONNX session is not thread-safe)
for (var i = 0; i < texts.length; i++) {
final embedding = await _embedInternal(texts[i]);
results.add(embedding);
onProgress?.call(i + 1, texts.length);
}
return results;
});
}