Spectre.Router.SemanticCache.Learned.Rows (Spectre v0.3.0)

Copy Markdown View Source

Row and label vocabulary for the built-in learned semantic cache.

Normalizes row shapes and text, deduplicates merged row sets with a stable source ranking, validates embeddings, and resolves route labels against the agent's cacheable rules. Intended to be imported by the Learned cache modules.

Summary

Functions

Returns true for nil or empty strings.

Requires the label's route to allow semantic caching.

Returns true when the label's route allows semantic caching.

Returns the rules that allow semantic caching.

Splits dataset text into trimmed, non-comment lines.

Deduplicates merged rows by normalized text with a stable source rank.

Validates and coerces an embedding to a list of finite floats.

Fills defaults and normalizes text fields of a row.

Normalizes lookup text to its trimmed, lowercase key.

Builds a unique online row id.

Puts one metadata key on a row.

Resolves a label against declared route rules, or nil.

Resolves a label against the agent routes, tagging unknown labels.

Coerces a rule struct or map to a plain map.

Compares a source label with a rule label case-insensitively.

Builds a short stable hash for deterministic static row ids.

Fixed timestamp used for immutable static rows.

Requires non-blank text.

Functions

blank?(arg1)

@spec blank?(term()) :: boolean()

Returns true for nil or empty strings.

cacheable_label(label, opts)

@spec cacheable_label(
  atom(),
  keyword()
) :: :ok | {:error, term()}

Requires the label's route to allow semantic caching.

cacheable_label?(label, opts)

@spec cacheable_label?(
  atom(),
  keyword()
) :: boolean()

Returns true when the label's route allows semantic caching.

cacheable_rules(opts)

@spec cacheable_rules(keyword()) :: [Spectre.Rule.t()]

Returns the rules that allow semantic caching.

dataset_lines(text)

@spec dataset_lines(String.t()) :: [String.t()]

Splits dataset text into trimmed, non-comment lines.

dedupe(rows)

Deduplicates merged rows by normalized text with a stable source rank.

normalize_embedding(embedding)

@spec normalize_embedding(term()) :: {:ok, [float()] | nil} | {:error, term()}

Validates and coerces an embedding to a list of finite floats.

normalize_row(row)

@spec normalize_row(map()) :: Spectre.Router.SemanticCache.Learned.row()

Fills defaults and normalizes text fields of a row.

normalize_text(text)

@spec normalize_text(String.t()) :: String.t()

Normalizes lookup text to its trimmed, lowercase key.

online_id()

@spec online_id() :: String.t()

Builds a unique online row id.

put_metadata(row, key, value)

Puts one metadata key on a row.

route_label(label, rules)

@spec route_label(term(), [Spectre.Rule.t() | map()]) :: atom() | nil

Resolves a label against declared route rules, or nil.

routeable_label(label, opts)

@spec routeable_label(
  term(),
  keyword()
) :: {:ok, atom()} | {:error, term()}

Resolves a label against the agent routes, tagging unknown labels.

rule_to_map(rule)

@spec rule_to_map(Spectre.Rule.t() | map()) :: map()

Coerces a rule struct or map to a plain map.

same_label?(source_label, label)

@spec same_label?(term(), atom()) :: boolean()

Compares a source label with a rule label case-insensitively.

stable_hash(term)

@spec stable_hash(term()) :: String.t()

Builds a short stable hash for deterministic static row ids.

static_timestamp()

@spec static_timestamp() :: DateTime.t()

Fixed timestamp used for immutable static rows.

valid_text(text)

@spec valid_text(String.t()) :: {:ok, String.t()} | {:error, term()}

Requires non-blank text.