mixle.represent.api module

fit_embedder – point it at raw heterogeneous data, get back vectors and retrieval.

The one-call product surface over the representation layer: text or records (dicts / tuples of mixed fields) featurize through the task layer’s deterministic hashers, and a generatively-trained autoencoder (mixle.represent.generative.fit_autoencoder()) compresses them into a learned dim-space. The returned Embedder transforms new items into that space and retrieves nearest neighbours over the fitted corpus – model-based retrieval over raw data, no upstream tokenizer or external embedding API:

emb = fit_embedder(tickets, dim=16)          # dict/tuple records or strings
emb.transform(new_items)                     # (N, dim)
emb.retrieve(query, k=5)                     # [(corpus index, similarity), ...]
emb.save(path); Embedder.load(path)          # durable artifact

Deterministic given seed. Needs torch only to FIT; a saved Embedder reloads and transforms anywhere.

class Embedder(featurizer, result, kind, corpus_vectors)[source]

Bases: object

A fitted embedding of raw heterogeneous items: transform to vectors, retrieve neighbours.

Parameters:
  • featurizer (Any)

  • result (AutoencoderResult)

  • kind (str)

  • corpus_vectors (np.ndarray)

property dim: int
transform(items)[source]

Embed items into the learned space, unit-normalized (so dot = cosine similarity).

Parameters:

items (Any)

Return type:

ndarray

retrieve(query, k=5)[source]

Top-k fitted-corpus neighbours of query as (corpus index, cosine similarity).

Parameters:
Return type:

list[tuple[int, float]]

save(path)[source]
Parameters:

path (str)

Return type:

str

classmethod load(path)[source]
Parameters:

path (str)

Return type:

Embedder

fit_embedder(data, dim=32, *, kind=None, feature_dim=256, hidden=(64,), epochs=200, lr=1e-2, seed=0)[source]

Fit a learned embedding of raw text or record items and return an Embedder.

Items featurize deterministically (hashing trick; no fitted vocabulary), then an autoencoder learns a dim-dimensional generative representation of the corpus. retrieve works out of the box over the fitted data; transform embeds anything of the same kind.

Parameters:
Return type:

Embedder