addSourceFromFileWithChunking method

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

Add a document from a file path using a Rust-side ingest fast path.

The file body never crosses the FFI boundary — Rust reads the file itself and runs the rest of the staging pipeline locally. Only the path string is sent Dart→Rust. Strategy is auto-detected from the extension when strategy is null (.md / .markdown → Markdown, else Recursive). Text-like extensions (.txt, .md, .markdown) are decoded as UTF-8; everything else falls through to the magic-byte document extractor (PDF / DOCX).

Implementation

Future<SourceAddResult> addSourceFromFileWithChunking(
  String filePath, {
  String? metadata,
  String? name,
  ChunkingStrategy? strategy,
  Duration? chunkDelay,
  void Function(int done, int total)? onProgress,
}) async {
  final prepared = await rust_ingest.prepareSourceIngestionFromFile(
    collectionId: collectionId,
    filePath: filePath,
    metadata: metadata,
    name: name ?? filePath,
    strategyHint: strategy == null ? null : _toIngestStrategy(strategy),
    maxChars: maxChunkChars,
    overlapChars: overlapChars,
  );
  return _runPreparedIngestion(
    prepared,
    chunkDelay: chunkDelay,
    onProgress: onProgress,
  );
}