Dala.ML.Model (dala v0.3.2)

Copy Markdown View Source

Model management for Dala ML.

Handles model download, caching, compilation, and versioning. Models are stored in the app's private directory and can be hot-swapped without app restart.

Usage

# Download a model from URL
{:ok, model_info} = Dala.ML.Model.download("https://example.com/model.mlmodel")

# List cached models
models = Dala.ML.Model.cached_models()

# Get model path for loading
path = Dala.ML.Model.path("my_model")

# Delete a cached model
:ok = Dala.ML.Model.delete("my_model")

Summary

Functions

Returns the directory where models are cached.

Returns the total size of all cached models in bytes.

Returns a list of cached model info maps.

Clears all cached models.

Compiles a CoreML model (.mlmodel → .mlmodelc) for faster loading.

Deletes a cached model.

Downloads a model from a URL and caches it locally.

Returns the local path for a cached model by name.

Functions

cache_dir()

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

Returns the directory where models are cached.

cache_size()

@spec cache_size() :: non_neg_integer()

Returns the total size of all cached models in bytes.

cached_models()

@spec cached_models() :: [map()]

Returns a list of cached model info maps.

clear_cache()

@spec clear_cache() :: :ok

Clears all cached models.

compile(model_path)

@spec compile(String.t()) :: {:ok, String.t()} | {:error, term()}

Compiles a CoreML model (.mlmodel → .mlmodelc) for faster loading.

Only relevant on iOS. On other platforms, returns the path unchanged.

delete(name)

@spec delete(String.t()) :: :ok | {:error, term()}

Deletes a cached model.

download(url, opts \\ [])

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

Downloads a model from a URL and caches it locally.

Options

  • :name — Custom name for the model (defaults to filename from URL)
  • :checksum — Expected SHA256 checksum for verification
  • :force — Overwrite existing cached model (default: false)

path(name)

@spec path(String.t()) :: String.t() | nil

Returns the local path for a cached model by name.