LLMDB.Store (LLM DB v2025.12.4)
View SourceManages persistent_term storage for LLM model snapshots with atomic swaps.
Uses :persistent_term for fast, concurrent reads with atomic updates tracked by monotonic epochs.
Summary
Functions
Clears the persistent_term store.
Returns the current epoch from the store.
Reads the full store from persistent_term.
Returns the last load options from the store.
Returns a specific model by provider and ID.
Returns all models for a specific provider.
Returns a specific provider by ID.
Returns all providers from the snapshot.
Atomically swaps the store with new snapshot and options.
Returns the snapshot portion from the store.
Functions
@spec clear!() :: :ok
Clears the persistent_term store.
Primarily used for testing cleanup.
Returns
:ok
@spec epoch() :: non_neg_integer()
Returns the current epoch from the store.
Returns
Non-negative integer representing the current epoch, or 0 if not set.
@spec get() :: map() | nil
Reads the full store from persistent_term.
Returns
Map with :snapshot, :epoch, and :opts keys, or nil if not set.
@spec last_opts() :: keyword()
Returns the last load options from the store.
Returns
Keyword list of options used in the last load, or [] if not set.
@spec model(atom(), String.t()) :: {:ok, LLMDB.Model.t()} | {:error, :not_found}
Returns a specific model by provider and ID.
Resolves both model aliases and provider aliases. For example, looking up
model(:google_vertex, "claude-haiku-4-5@20251001") will find the model
even if it's stored under :google_vertex_anthropic provider (via alias_of).
Parameters
provider_id- Provider atommodel_id- Model ID string (can be an alias)
Returns
{:ok, model}- Model found{:error, :not_found}- Model not found
@spec models(atom()) :: [LLMDB.Model.t()]
Returns all models for a specific provider.
Includes models from aliased providers. For example, calling models(:google_vertex)
will return models from both :google_vertex AND :google_vertex_anthropic since
google_vertex_anthropic has alias_of: :google_vertex.
Parameters
provider_id- Provider atom
Returns
List of Model structs for the provider and its aliases, or empty list if provider not found.
@spec provider(atom()) :: {:ok, LLMDB.Provider.t()} | {:error, :not_found}
Returns a specific provider by ID.
Parameters
provider_id- Provider atom
Returns
{:ok, provider}- Provider found{:error, :not_found}- Provider not found
@spec providers() :: [LLMDB.Provider.t()]
Returns all providers from the snapshot.
Returns
List of Provider structs, or empty list if no snapshot.
Atomically swaps the store with new snapshot and options.
Creates a new epoch using a monotonic unique integer and stores the complete state.
Parameters
snapshot- The snapshot map to storeopts- Keyword list of options to store
Returns
:ok
@spec snapshot() :: map() | nil
Returns the snapshot portion from the store.
Returns
The snapshot map or nil if not set.