# `AgentDb.ML.ModelManager.Backend`
[🔗](https://github.com/manhvu/agent_db/blob/v0.1.0/lib/agent_db/ml/model_manager/backend.ex#L1)

Runtime that loads embedding and summarization models and runs inference.

`Backend.Exla` is the current Bumblebee + EXLA path. `Backend.Emlx` is the
Apple MLX path (EMLX + EMLXAxon). `ModelManager` selects one at startup and
falls back to EXLA when EMLX is unavailable.

# `config`

```elixir
@type config() :: map()
```

# `model_ref`

```elixir
@type model_ref() :: map()
```

# `embed`

```elixir
@callback embed(model_ref(), [String.t()]) :: {:ok, [Nx.Tensor.t()]} | {:error, term()}
```

# `load_embedding`

```elixir
@callback load_embedding(config()) :: {:ok, model_ref()} | {:error, term()}
```

# `load_llm`

```elixir
@callback load_llm(config()) :: {:ok, model_ref()} | {:error, term()}
```

# `summarize`

```elixir
@callback summarize(model_ref(), String.t(), keyword()) ::
  {:ok, String.t()} | {:error, term()}
```

# `load`

```elixir
@spec load(config(), :embedding | :llm) :: {:ok, model_ref()} | {:error, term()}
```

Loads a role's model through the configured backend, falling back to EXLA
when the EMLX backend fails.

The fallback lives here rather than in the manager because backend selection
is this module's decision: the manager asks for a model to be loaded, not how
the backend that loads it is chosen. A failure is reported, never raised, so
the caller keeps its load-state machine intact.

# `module_for`

```elixir
@spec module_for(:exla | :emlx) :: module()
```

Backend module for a resolved backend name.

# `resolve`

```elixir
@spec resolve(:auto | :exla | :emlx) :: :exla | :emlx
```

Resolves `:auto` to `:emlx` on Apple Silicon macOS, else `:exla`.

---

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