Adapter boundary for semantic cache lookups.
Configure one of:
semantic_lookup: &MyCache.lookup/2semantic_cache: MyCachesemantic_cache: {MyCache, :lookup}
The adapter should return {:ok, map} for accepted route-like results or
{:error, reason} for misses.
Summary
Functions
Clears semantic-cache state for an agent.
Deletes an online learned example.
Lists semantic-cache examples for an agent.
Fetches one semantic-cache example by id.
Explains whether a resolved route should be learned into the semantic cache.
Convenience boolean form of learn_eligibility/2.
Loads online learned examples and their stored embeddings from a snapshot.
Looks up a message in the configured semantic cache.
Stores a semantic-cache example.
Relabels an online learned example and marks it verified.
Snapshots semantic-cache examples and their stored embeddings.
Edits an online learned example in place.
Marks an online learned example as verified.
Callbacks
Functions
Clears semantic-cache state for an agent.
Spectre's built-in learned cache is always cleared. When a custom
semantic_cache: module is configured, that adapter must also implement
clear/2.
Deletes an online learned example.
Lists semantic-cache examples for an agent.
Fetches one semantic-cache example by id.
@spec learn_eligibility(module(), Spectre.Route.t() | map() | nil) :: :ok | {:skip, atom()}
Explains whether a resolved route should be learned into the semantic cache.
Returns :ok when learning is safe, or {:skip, reason} with one of
:missing_route, :route_not_accepted, :semantic_cache_route (the route
was served from the cache itself), :route_not_found,
:route_not_learnable (the matched rule is not learn: true), or
:protected_action (the route stages a policy-protected action — learning
it would let the cache bypass future consent classification).
case SemanticCache.learn_eligibility(MyApp.Agent, result.route) do
:ok -> SemanticCache.put(text, result.route, opts)
{:skip, _reason} -> :ok
end
@spec learnable?(module(), Spectre.Route.t() | map() | nil) :: boolean()
Convenience boolean form of learn_eligibility/2.
Loads online learned examples and their stored embeddings from a snapshot.
Looks up a message in the configured semantic cache.
Stores a semantic-cache example.
Relabels an online learned example and marks it verified.
Snapshots semantic-cache examples and their stored embeddings.
Edits an online learned example in place.
Supported attrs: :text (re-embedded through the configured embedding
adapter), :label (must name a cacheable route), and :verified.
{:ok, updated} =
Spectre.Router.SemanticCache.update_example(MyApp.Agent, id, %{label: :PRICING})
Marks an online learned example as verified.