clearAllData method

Future<void> clearAllData()

Clear all data (database and index files) and reset the engine.

This is a destructive operation that:

  1. Closes the database connection and the vector store
  2. Deletes the SQLite database file and its sidecars
  3. Deletes the vector store and the HNSW indexes of every collection
  4. Re-initializes the database and service

It first waits for running work in every collection (ingests, removals, rebuilds, warmups). Writes and rebuilds called while it runs start after the new database is ready.

Implementation

Future<void> clearAllData() async {
  if (_disposed) {
    throw StateError('RagEngine was disposed. Initialize a new engine.');
  }
  final running = _resetInProgress;
  if (running != null) return running.future;
  final reset = Completer<void>();
  _resetInProgress = reset;
  try {
    await _clearAllData();
  } finally {
    _resetInProgress = null;
    reset.complete();
  }
}