# `LLMDB.Store`
[🔗](https://github.com/agentjido/llm_db/blob/main/lib/llm_db/store.ex#L1)

Manages persistent_term storage for LLM model snapshots with atomic swaps.

Uses `:persistent_term` for fast, concurrent reads with atomic updates tracked by monotonic epochs.

# `clear!`

```elixir
@spec clear!() :: :ok
```

Clears the persistent_term store.

Primarily used for testing cleanup.

## Returns

`:ok`

# `epoch`

```elixir
@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.

# `get`

```elixir
@spec get() :: map() | nil
```

Reads the full store from persistent_term.

## Returns

Map with `:snapshot`, `:epoch`, and `:opts` keys, or `nil` if not set.

# `last_opts`

```elixir
@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.

# `model`

```elixir
@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 atom
- `model_id` - Model ID string (can be an alias)

## Returns

- `{:ok, model}` - Model found
- `{:error, :not_found}` - Model not found

# `models`

```elixir
@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.

# `provider`

```elixir
@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

# `providers`

```elixir
@spec providers() :: [LLMDB.Provider.t()]
```

Returns all providers from the snapshot.

## Returns

List of Provider structs, or empty list if no snapshot.

# `put!`

```elixir
@spec put!(
  map(),
  keyword()
) :: :ok
```

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 store
- `opts` - Keyword list of options to store

## Returns

`:ok`

# `snapshot`

```elixir
@spec snapshot() :: map() | nil
```

Returns the snapshot portion from the store.

## Returns

The snapshot map or `nil` if not set.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
