latent.prefect.checkpoint¶
Development-mode disk memoization for expensive calls inside a task.
Production resumability lives in :mod:latent.prefect.resumable; this module
is the fast-iteration convenience only.
Functions¶
checkpoint¶
Decorator that memoizes function results to disk, in development mode only.
Keyed on the call arguments, so a repeated call inside the same iteration loop skips the work — the point is a fast edit-rerun cycle while debugging, not durability. In production this decorator is a no-op: an argument-hash disk cache that outlives a run would serve yesterday's answers as today's results.
For resuming a production run that died part-way through a batch, use
:func:latent.prefect.resumable instead. It keys on the caller's item id
rather than an argument hash, records each item as it completes, and deletes
its checkpoint once the batch finishes — so it only ever replays a crash.
Args: func: Function to memoize
Returns: Wrapped function with memoization enabled (dev) or the original function unchanged (prod)
Example: >>> from latent.prefect import task, checkpoint >>> >>> @task("process_documents") >>> def process_documents(documents: list[dict]) -> list[dict]: ... @checkpoint ... def expensive_llm_call(doc: dict) -> dict: ... response = llm_client.complete(doc["prompt"]) ... return {"id": doc["id"], "response": response} ... ... # Re-running the flow in dev skips docs already answered ... return [expensive_llm_call(doc) for doc in documents]
Environment Behavior: - Development mode (LATENT_ENVIRONMENT=dev): Caching enabled - Production mode (default): Caching disabled (no-op)
Note: - Function arguments and return values must be picklable - Cache is stored in .latent/cache/ directory - Use clear_checkpoints() to manually clear cached data
clear_checkpoints¶
Clear all checkpoint data from disk.
This removes all cached function results. Only works in development mode.
Example: >>> from latent.prefect import clear_checkpoints >>> >>> # Clear all checkpoints after successful run >>> clear_checkpoints()