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

Handles loading and merging of packaged snapshots with runtime customization.

Phase 2 of LLMDB: Load the packaged snapshot, apply custom overlays,
compile filters, and build indexes for runtime queries.

This module encapsulates all snapshot loading logic, keeping the main
LLMDB module focused on the query API.

# `compute_digest`

```elixir
@spec compute_digest(list(), list(), map()) :: integer()
```

Computes a digest for a snapshot configuration.

Used to detect if a reload would result in the same snapshot,
enabling idempotent load operations.

## Parameters

- `providers` - List of provider maps
- `base_models` - List of all models before filtering
- `runtime` - Runtime configuration map

## Returns

Integer digest (phash2 hash)

# `load`

```elixir
@spec load(keyword()) :: {:ok, map()} | {:error, term()}
```

Loads the packaged snapshot and applies runtime configuration.

This is the main entry point for Phase 2 (runtime) loading. It:
1. Loads the packaged snapshot
2. Normalizes providers/models from v1 or v2 format
3. Merges custom providers/models overlay
4. Compiles and applies filters
5. Builds indexes for O(1) queries
6. Returns snapshot ready for Store

## Parameters

- `opts` - Keyword list passed to Runtime.compile/1

## Returns

- `{:ok, snapshot}` - Successfully loaded and prepared snapshot
- `{:error, :no_snapshot}` - No packaged snapshot available
- `{:error, term}` - Other errors

## Examples

    {:ok, snapshot} = Loader.load()

    {:ok, snapshot} = Loader.load(
      allow: [:openai],
      custom: %{
        local: [
          models: %{"llama-3" => %{capabilities: %{chat: true}}}
        ]
      }
    )

# `load_empty`

```elixir
@spec load_empty(keyword()) :: {:ok, map()}
```

Builds an empty snapshot with no providers or models.

Used as a fallback when no packaged snapshot is available.

## Examples

    {:ok, snapshot} = Loader.load_empty()

---

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