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

Copy Markdown View Source

Vettore-backed semantic index and embedding acquisition for the learned cache.

Builds and caches per-content collections from embeddings already stored on rows, runs threshold-gated vector search, and resolves embeddings for new online rows through the configured adapter. The index cache table name is the Learned module itself, preserved as an operational contract.

Summary

Functions

Drops the cached collections of one agent, raising if the owner is down.

Embeds text through the configured embedding adapter.

Searches the cached collection for rows semantically close to the text.

Resolves the embedding stored with a learn result, reusing or embedding.

Warms the index for rows that already store embeddings.

Functions

clear(agent)

@spec clear(module()) :: :ok

Drops the cached collections of one agent, raising if the owner is down.

embed(text, opts)

@spec embed(
  String.t(),
  keyword()
) :: {:ok, [float()]} | {:error, term()}

Embeds text through the configured embedding adapter.

search(text, rows, opts)

@spec search(String.t(), [Spectre.Router.SemanticCache.Learned.row()], keyword()) ::
  {:ok, map(), map()} | {:error, term(), map()}

Searches the cached collection for rows semantically close to the text.

stored_embedding(text, result, existing, opts)

@spec stored_embedding(
  String.t(),
  map(),
  Spectre.Router.SemanticCache.Learned.row() | nil,
  keyword()
) ::
  {:ok, [float()] | nil} | {:error, term()}

Resolves the embedding stored with a learn result, reusing or embedding.

warm(rows, opts)

@spec warm(
  [Spectre.Router.SemanticCache.Learned.row()],
  keyword()
) :: {:ok, non_neg_integer()} | {:error, term()}

Warms the index for rows that already store embeddings.