mixle.represent.posterior module¶
Posterior retrieval by fitted-model affinity rather than raw-feature cosine.
Fit a mixture to heterogeneous records and retrieval similarity becomes
posterior affinity: two records are close when the model’s
field-restricted latent posteriors agree. The implementation uses the per-field
Bhattacharyya-style balanced affinity from mixle.utils.hvis, with an
evidence cap so one inconsistent field can contribute negative evidence without
dominating every other field. Raw-feature cosine has neither property: it
weights fields by numeric scale, and one high-variance field can dominate the
dot product:
m = mixle.propose(records, fit=True)
r = PosteriorRetriever(m.fitted, records) # any mixture over the records works
r.retrieve(query, k=5) # [(corpus index, log-affinity), ...]
Cost note: affinities are computed jointly over corpus + queries through
the model’s per-field likelihoods. Model passes are linear in rows, while the
affinity block is quadratic, so this is intended for moderate corpora. For
large-corpus first-stage recall, use mixle.represent.fit_embedder() and
rerank the shortlist here.
- class PosteriorRetriever(model, corpus, *, evidence_cap=1.0, field_weights=None)[source]
Bases:
objectRetrieve over raw heterogeneous records by the fitted mixture’s posterior affinity.
- Parameters:
model (Any)
corpus (Any)
evidence_cap (float | None)
field_weights (Any)
- affinity_matrix()[source]
The corpus’s dense
(n, n)log-affinity matrix (diagonal-inf).- Return type:
- retrieve(query, k=5)[source]
Top-
kcorpus records for one query:[(corpus_index, log_affinity), ...]best first.