LLMDB.Loader (LLM DB v2026.2.1)

Copy Markdown View Source

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.

Summary

Functions

Computes a digest for a snapshot configuration.

Loads the packaged snapshot and applies runtime configuration.

Builds an empty snapshot with no providers or models.

Functions

compute_digest(providers, base_models, runtime)

@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(opts \\ [])

@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(opts \\ [])

@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()