LLMDB.Snapshot (LLM DB v2026.7.3)

Copy Markdown View Source

Canonical snapshot artifact helpers.

Snapshots are the immutable unit of metadata publication and runtime loading. They are stored as a single snapshot.json file, addressed by snapshot_id, and optionally mirrored to GitHub Releases.

Summary

Functions

Returns the local build output directory for snapshots.

Returns the default build artifact path for snapshot-meta.json.

Returns the default build artifact path for snapshot.json.

Returns provider/model counts for a snapshot document.

Decodes, verifies, migrates, and validates a snapshot document from JSON.

Encodes a snapshot or metadata document as deterministic compact JSON.

Builds a canonical snapshot document from an engine snapshot.

Builds snapshot metadata suitable for snapshot-index.json and latest.json.

Returns the packaged snapshot file path.

Reads, verifies, migrates, and validates a snapshot document from disk.

Returns the canonical snapshot schema version.

Computes the content-addressed snapshot ID for a snapshot document.

Returns the source-tree packaged snapshot path used for release packaging.

Returns the opt-in sparse snapshot schema version.

Returns every snapshot schema version accepted by the reader.

Converts a canonical v1 snapshot to the deterministic sparse v2 wire shape.

Verifies snapshot checksum consistency and document safety.

Writes a snapshot or metadata document to disk.

Types

integrity_policy()

@type integrity_policy() :: :strict | :warn | :off

Functions

build_dir()

@spec build_dir() :: String.t()

Returns the local build output directory for snapshots.

build_meta_path()

@spec build_meta_path() :: String.t()

Returns the default build artifact path for snapshot-meta.json.

build_path()

@spec build_path() :: String.t()

Returns the default build artifact path for snapshot.json.

counts(snapshot)

@spec counts(map()) :: %{
  provider_count: non_neg_integer(),
  model_count: non_neg_integer()
}

Returns provider/model counts for a snapshot document.

decode(content, opts \\ [])

@spec decode(
  binary(),
  keyword()
) :: {:ok, map()} | {:error, term()}

Decodes, verifies, migrates, and validates a snapshot document from JSON.

The optional :integrity_policy controls checksum mismatch handling. A snapshot ID detects accidental corruption or content mismatch; it does not authenticate the snapshot publisher.

encode(document)

@spec encode(map()) :: String.t()

Encodes a snapshot or metadata document as deterministic compact JSON.

Object keys are sorted recursively. Array order and every encoded value are preserved. Schema v2 documents are normalized to the sparse wire shape before encoding; schema v1 and non-snapshot metadata documents only lose insignificant JSON whitespace.

from_engine_snapshot(map, opts \\ [])

@spec from_engine_snapshot(
  map(),
  keyword()
) :: map()

Builds a canonical snapshot document from an engine snapshot.

history_archive_filename()

@spec history_archive_filename() :: String.t()

history_meta_filename()

@spec history_meta_filename() :: String.t()

latest_filename()

@spec latest_filename() :: String.t()

metadata(snapshot, attrs \\ %{})

@spec metadata(map(), map()) :: map()

Builds snapshot metadata suitable for snapshot-index.json and latest.json.

packaged_path()

@spec packaged_path() :: String.t()

Returns the packaged snapshot file path.

read(path, opts \\ [])

@spec read(
  String.t(),
  keyword()
) :: {:ok, map()} | {:error, term()}

Reads, verifies, migrates, and validates a snapshot document from disk.

schema_version()

@spec schema_version() :: pos_integer()

Returns the canonical snapshot schema version.

snapshot_filename()

@spec snapshot_filename() :: String.t()

snapshot_id(snapshot)

@spec snapshot_id(map()) :: String.t()

Computes the content-addressed snapshot ID for a snapshot document.

snapshot_index_filename()

@spec snapshot_index_filename() :: String.t()

snapshot_meta_filename()

@spec snapshot_meta_filename() :: String.t()

source_packaged_path()

@spec source_packaged_path() :: String.t()

Returns the source-tree packaged snapshot path used for release packaging.

sparse_schema_version()

@spec sparse_schema_version() :: pos_integer()

Returns the opt-in sparse snapshot schema version.

Sparse snapshots are readable in this release, but the packaged and published default remains schema v1 for backwards compatibility.

supported_schema_versions()

@spec supported_schema_versions() :: [pos_integer()]

Returns every snapshot schema version accepted by the reader.

to_sparse(snapshot)

@spec to_sparse(map()) :: map()

Converts a canonical v1 snapshot to the deterministic sparse v2 wire shape.

Only schema-known provider/model nulls and defaults are omitted. Unknown keys, nested extra data, explicit values, and array order are preserved. The content-addressed snapshot ID is recalculated for the v2 representation.

verify(snapshot)

@spec verify(map()) :: :ok | {:error, term()}

Verifies snapshot checksum consistency and document safety.

Snapshot IDs detect corruption or mismatched content. They are not an authenticity or trust guarantee.

write!(path, document)

@spec write!(String.t(), map()) :: :ok

Writes a snapshot or metadata document to disk.