addDocumentUtf8 method

Future<SourceAddResult> addDocumentUtf8(
  1. Uint8List bytes, {
  2. String? metadata,
  3. String? name,
  4. ChunkingStrategy? strategy,
  5. Duration? chunkDelay,
  6. void onProgress(
    1. int done,
    2. int total
    )?,
  7. String? collectionId,
})

Add a UTF-8 document payload while reducing input-side Dart String materialization.

Implementation

Future<SourceAddResult> addDocumentUtf8(
  Uint8List bytes, {
  String? metadata,
  String? name,
  ChunkingStrategy? strategy,
  Duration? chunkDelay,
  void Function(int done, int total)? onProgress,
  String? collectionId,
}) async {
  final normalized = _normalizeCollectionId(collectionId);
  final service = await _serviceForCollection(normalized);

  if (normalized == SourceRagService.defaultCollectionId) {
    _startOperation();
  }
  try {
    return await service.addSourceUtf8WithChunking(
      bytes,
      metadata: metadata,
      name: name,
      strategy: strategy,
      chunkDelay: chunkDelay,
      onProgress: onProgress,
    );
  } finally {
    if (normalized == SourceRagService.defaultCollectionId) {
      _endOperation();
    }
  }
}