Provider Contract
View SourceThis document defines the public provider contract for jido_memory.
Core Behaviour
Providers must implement Jido.Memory.Provider.
Required callbacks:
validate_config/1capabilities/1remember/3get/3retrieve/3forget/3prune/2info/2
Optional callback:
child_specs/1
retrieve/3 must return {:ok, %Jido.Memory.RetrieveResult{}}.
Optional Capability Behaviours
Providers can implement these capability behaviours when supported:
Jido.Memory.Capability.IngestionJido.Memory.Capability.ExplainableRetrievalJido.Memory.Capability.Lifecycle
Jido.Memory.Runtime treats CapabilitySet as the source of truth for optional
operations.
That means:
- if the capability is not advertised, runtime returns
{:error, {:unsupported_capability, capability, provider_module}} - if the capability is advertised but the callback is missing, runtime returns
{:error, {:invalid_provider_capability, capability, provider_module}}
Canonical Result Types
Provider implementations should return these canonical structs:
- retrieval:
Jido.Memory.RetrieveResult - capabilities:
Jido.Memory.CapabilitySet - provider metadata:
Jido.Memory.ProviderInfo - ingest:
Jido.Memory.IngestResult - explanation:
Jido.Memory.Explanation - lifecycle:
Jido.Memory.ConsolidationResult
Compatibility note:
Jido.Memory.Runtimewill normalize maps into canonical structs where possible, but providers should return the structs directly.
CapabilitySet is more than a flat atom list. Providers should use it to expose:
- supported flat capability atoms
- a structured capability descriptor
- a canonical provider key when one exists
- provider-specific capability metadata when useful
ProviderInfo is the canonical provider metadata surface. It can describe:
- canonical provider key
- provider style or family
- structured capability descriptor
- topology and resolved defaults
- advanced provider-direct operations
- surface boundaries between runtime, plugin, and provider-native APIs
Runtime.info/3 filters fields locally after normalizing ProviderInfo.
Providers should treat info/2 as the full-metadata callback.
Provider Aliases
Core aliases exposed by Jido.Memory.ProviderRegistry:
:basic
External provider packages can extend the atom alias registry through config:
config :jido_memory, :provider_aliases,
custom_provider: MyApp.Memory.Provider,
mempalace: Jido.Memory.Provider.MemPalaceConfiguration Rules
Provider option precedence is:
- explicit runtime opts
- query or attr map values
- plugin state
- provider defaults
Runtime resolves that precedence before calling the provider. Provider callbacks receive one canonical provider option set as their final argument. They should treat that option list as the resolved provider config input.
Bootstrap
Providers that require supervised infrastructure should expose child_specs/1.
Callers can inspect bootstrap requirements through
Jido.Memory.ProviderBootstrap.child_specs/2.
Core runtime does not start provider infrastructure automatically.
Contract Tests
Provider packages should use Jido.Memory.Testing.ProviderContractCase in their
test suite.
This verifies:
- capability exposure
- provider metadata
- remember/get/retrieve/forget lifecycle
- optional capability wrappers when supported
Minimal Provider Skeleton
defmodule MyApp.Memory.Provider do
@behaviour Jido.Memory.Provider
alias Jido.Memory.{CapabilitySet, ProviderInfo, RetrieveResult}
@impl true
def validate_config(opts), do: :ok
@impl true
def capabilities(_opts) do
{:ok,
CapabilitySet.new!(%{
provider: __MODULE__,
key: :custom,
capabilities: [:remember, :get, :retrieve],
descriptor: %{
retrieval: %{basic: true},
storage: %{durable: false}
}
})}
end
@impl true
def info(_opts, _fields) do
{:ok,
ProviderInfo.new!(%{
name: "custom",
key: :custom,
provider: __MODULE__,
provider_style: :custom,
capabilities: [:retrieve],
capability_descriptor: %{
retrieval: %{basic: true}
},
topology: %{storage: :memory_only},
surface_boundary: %{runtime: [:remember, :retrieve]}
})}
end
@impl true
def retrieve(_target, _query, _opts) do
{:ok, RetrieveResult.new!(%{hits: []})}
end
# implement remaining callbacks...
end