Packages
llm_db
2026.2.2
2026.7.3
2026.7.2
2026.7.1
2026.7.0
2026.6.4
2026.6.3
2026.6.2
2026.6.1
2026.6.0
2026.5.2
2026.5.1
2026.5.0
2026.4.8
2026.4.7
2026.4.6
2026.4.5
2026.4.4
2026.4.3
2026.4.2
2026.4.1
2026.4.0
2026.3.3
2026.3.2
2026.3.1
2026.3.0
2026.2.9
2026.2.8
2026.2.7
2026.2.6
2026.2.5
2026.2.4
2026.2.3
2026.2.2
2026.2.1
2026.2.0
2026.1.5
2026.1.4
2026.1.3
2026.1.2
2026.1.1
2026.1.0
2025.12.4
2025.12.3
2025.12.2
2025.12.1
2025.11.18-preview
2025.11.14-preview
2025.11.7-preview
LLM model metadata catalog with fast, capability-aware lookups.
Current section
Files
Jump to
Current section
Files
lib/llm_db/engine/enrich.ex
defmodule LLMDB.Enrich do
@moduledoc """
Lightweight, deterministic enrichment of model data.
This module performs simple derivations and defaults, such as:
- Deriving model family from model ID
- Setting provider_model_id to id if not present
- Ensuring capability defaults are applied (handled by Zoi schemas)
"""
@doc """
Derives the family name from a model ID using prefix logic.
Extracts family from model ID by splitting on "-" and taking all but the last segment.
Returns nil if the family cannot be reasonably derived.
## Examples
iex> LLMDB.Enrich.derive_family("gpt-4o-mini")
"gpt-4o"
iex> LLMDB.Enrich.derive_family("claude-3-opus")
"claude-3"
iex> LLMDB.Enrich.derive_family("gemini-1.5-pro")
"gemini-1.5"
iex> LLMDB.Enrich.derive_family("single")
nil
iex> LLMDB.Enrich.derive_family("two-parts")
"two"
"""
@spec derive_family(String.t()) :: String.t() | nil
def derive_family(model_id) when is_binary(model_id) do
parts = String.split(model_id, "-")
case parts do
[_single] ->
nil
parts when length(parts) >= 2 ->
parts
|> Enum.slice(0..-2//1)
|> Enum.join("-")
end
end
@doc """
Enriches a single model map with derived and default values.
Sets the following fields if not already present:
- `family`: Derived from model ID
- `provider_model_id`: Set to model ID
Note: Capability defaults are handled automatically by Zoi schema validation.
## Examples
iex> LLMDB.Enrich.enrich_model(%{id: "gpt-4o-mini", provider: :openai})
%{id: "gpt-4o-mini", provider: :openai, family: "gpt-4o", provider_model_id: "gpt-4o-mini"}
iex> LLMDB.Enrich.enrich_model(%{id: "claude-3-opus", provider: :anthropic, family: "claude-3-custom"})
%{id: "claude-3-opus", provider: :anthropic, family: "claude-3-custom", provider_model_id: "claude-3-opus"}
iex> LLMDB.Enrich.enrich_model(%{id: "model", provider: :openai, provider_model_id: "custom-id"})
%{id: "model", provider: :openai, provider_model_id: "custom-id"}
"""
@spec enrich_model(map()) :: map()
def enrich_model(model) when is_map(model) do
model
|> maybe_set_family()
|> maybe_set_provider_model_id()
end
@doc """
Enriches a list of model maps.
Applies `enrich_model/1` to each model in the list.
## Examples
iex> LLMDB.Enrich.enrich_models([
...> %{id: "gpt-4o", provider: :openai},
...> %{id: "claude-3-opus", provider: :anthropic}
...> ])
[
%{id: "gpt-4o", provider: :openai, family: "gpt", provider_model_id: "gpt-4o"},
%{id: "claude-3-opus", provider: :anthropic, family: "claude-3", provider_model_id: "claude-3-opus"}
]
"""
@spec enrich_models([map()]) :: [map()]
def enrich_models(models) when is_list(models) do
Enum.map(models, &enrich_model/1)
end
# Private helpers
defp maybe_set_family(%{family: _} = model), do: model
defp maybe_set_family(%{id: id} = model) do
case derive_family(id) do
nil -> model
family -> Map.put(model, :family, family)
end
end
defp maybe_set_provider_model_id(%{provider_model_id: _} = model), do: model
defp maybe_set_provider_model_id(%{id: id} = model) do
Map.put(model, :provider_model_id, id)
end
end