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 {
if (_session == null) {
throw Exception("EmbeddingService not initialized. Call init() first.");
}
if (texts.isEmpty) return [];
final results = <List<double>>[];
// Sequential processing (ONNX session is not thread-safe)
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;
}