saveState method

Future<int> saveState(
  1. String path, {
  2. int sequenceId = 0,
})

Saves the session's KV-cache state to path.

Resolves to the number of tokens the snapshot covers — positive on success, 0 when nothing is cached (no file is written). Restoring the file later with loadState lets the next generate reuse the saved prompt prefix instead of re-prefilling it (the prompt cache otherwise only survives while the same conversation stays the session's most recent one). Throws LlamaException on failure.

Implementation

Future<int> saveState(String path, {int sequenceId = 0}) =>
    _isolate.sessionState(id, path, save: true, sequenceId: sequenceId);