rebuildIndex method
Rebuild the HNSW index after adding documents.
Call this after adding one or more documents for optimal search
performance. The index enables fast approximate nearest neighbor search.
force - If true, rebuilds even if no changes were detected (default: false).
Implementation
Future<void> rebuildIndex({bool force = false, String? collectionId}) async {
final normalized = _normalizeCollectionId(collectionId);
final service = await _serviceForCollection(normalized);
if (normalized == SourceRagService.defaultCollectionId) {
_indexDebounceTimer
?.cancel(); // Cancel any pending auto-rebuild since we are doing it now
_indexDebounceTimer = null;
}
return service.rebuildIndex(force: force); // Service handles dirty check
}