Optional durability for the annotation Annotai.Store.
Opt-in via app config. When enabled, this GenServer:
- hydrates the Store from the on-disk snapshot on boot (pruning terminal annotations older than the optional TTL),
- debounces a snapshot write after each mutation, so a burst of edits collapses into one disk write off the mutation hot path, and
- flushes a final time on graceful shutdown.
The Store pokes this process (GenServer.cast(_, :changed)) after every
mutation; the poke is a no-op when persistence is disabled, so the Store stays
fully decoupled. The actual encode/write lives behind
Annotai.Persistence.Adapter (default Annotai.Persistence.Adapter.File).
Config
config :annotai, persistence: false # (default) off
config :annotai, persistence: true # on, defaults
config :annotai, persistence: [path: "...", ttl: {14, :day}] # on, overridesConfig deep-merges keyword lists across env files, so override per env by
setting the whole value (e.g. persistence: false in test.exs), not partial
keys.
Summary
Functions
Returns a specification to start this module under a supervisor.
Read and normalize the :persistence app config: :disabled | map.
Force an immediate, synchronous snapshot. No-op when persistence isn't running.
Normalize a config value to :disabled or a %{adapter:, path:, ttl:} map.
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec config() :: :disabled | map()
Read and normalize the :persistence app config: :disabled | map.
@spec flush(GenServer.server()) :: :ok
Force an immediate, synchronous snapshot. No-op when persistence isn't running.
Used by the "delete all" route so an explicit purge is durable at once rather than waiting out the debounce window.
Normalize a config value to :disabled or a %{adapter:, path:, ttl:} map.
Accepts the false | true | keyword union; true and a keyword both enable
(presence == enabled), filling in defaults.