addDocument method
Add a document with automatic chunking and embedding.
The document is:
- Split into chunks based on file type (auto-detected from
filePath) - Each chunk is embedded using the loaded model
- Source and chunks are stored in the database
Remember to call rebuildIndex after adding documents for optimal search performance.
Implementation
Future<SourceAddResult> addDocument(
String content, {
String? metadata,
String? name,
String? filePath,
ChunkingStrategy? strategy,
Duration? chunkDelay,
void Function(int done, int total)? onProgress,
}) async {
_startOperation(); // Start tracking
try {
final result = await _ragService.addSourceWithChunking(
content,
metadata: metadata,
name: name,
filePath: filePath,
strategy: strategy,
chunkDelay: chunkDelay,
onProgress: onProgress,
);
return result;
} finally {
_endOperation(); // End tracking -> Schedule debounce
}
}