AgentDb.Core.Inference behaviour (agent_db v0.1.0)

Copy Markdown View Source

The local model capabilities the store depends on.

Split by capability rather than by "run a model", so a workflow asks for exactly what it needs and a provider need only supply part of the surface. Embedding and summarization are separate callbacks because they have different failure modes: a document's embedding is what makes it findable by meaning, while a summary is a compression of something already readable.

Invariants an implementation must uphold

  • embed/1 returns vectors that are comparable with each other and stable for identical input, so an index built from them stays meaningful.
  • A model that is still loading is reported as loading, distinctly from a load that failed. {:error, :model_loading} is safe to repeat; a failure is not, and must not be disguised as one.
  • Neither an unavailable model nor a failed inference terminates the calling process or leaves the provider permanently unusable.

Summary

Types

A query or document embedding, as float32 bytes.

Callbacks

Supervised children the provider needs.

Embeds texts, returning one comparable vector per input.

Describes the state of both models, including a load in progress.

Summarizes prompt. An empty answer is an error, not an empty summary.

Types

embedding()

@type embedding() :: binary()

A query or document embedding, as float32 bytes.

Callbacks

child_specs(keyword)

@callback child_specs(keyword()) :: [
  Supervisor.child_spec() | module() | {module(), term()}
]

Supervised children the provider needs.

embed(list)

@callback embed([String.t()]) :: {:ok, [embedding()]} | {:error, term()}

Embeds texts, returning one comparable vector per input.

model_status()

@callback model_status() :: map()

Describes the state of both models, including a load in progress.

Answerable while a load is running, so a caller can tell "still coming" from "not there".

summarize(t, keyword)

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

Summarizes prompt. An empty answer is an error, not an empty summary.