mixle.reason.store module¶
Cross-modal retrieval that can condition on raw evidence.
Embedding-only retrieval can lose information for modalities that are too structured to compress safely, such as spectra, images, or spatial volumes. This store treats retrieval as evidence selection for Bayesian assimilation:
index the corpus by a low-cost embedding key (an approximate router, not the answer);
for a query, retrieve the nearest items by embedding;
for each, run a sufficiency test: would the raw payload reduce the query’s uncertainty materially more than its lossy embedding? If not, use the embedding evidence; if so, fetch the raw payload and condition the belief on it through its precise evidence;
fuse each choice into the belief (a product-of-experts update), recording provenance;
optionally retrieve actively by selecting the corpus item that most reduces query entropy.
Domain-neutral: the store knows nothing about seismic or spectra. The application supplies two
callables: coarse(payload) -> Evidence for embedding fidelity and
fine(payload) -> Evidence for raw fidelity. The same machinery can serve a
document corpus or a spatially indexed volume when the application supplies the
appropriate evidence functions.
- class RetrievalStep(index, fidelity, gain)[source]
Bases:
objectProvenance for one assimilated item: which corpus index, at what fidelity, and the nats it removed.
- class CrossModalStore(keys, payloads, *, coarse, fine, metric='euclidean')[source]
Bases:
objectA corpus indexed by embedding keys, with raw payloads conditioned on when embeddings fall short.
- Parameters:
keys (Any) –
(N, d_key)embedding vectors used as the retrieval index.payloads (Sequence[Any]) – length-
Nsequence of raw items (arbitrary; passed tocoarse/fine).coarse (Callable[[Any], LinearGaussianEvidence]) –
payload -> LinearGaussianEvidenceat embedding fidelity (low-cost, lossy).fine (Callable[[Any], LinearGaussianEvidence]) –
payload -> LinearGaussianEvidenceat raw fidelity (precise, “expensive”).metric (str) –
"euclidean"(default) or"cosine"for retrieval.
- retrieve(query_key, k=8)[source]
Return indices of the nearest
kembedding keys toquery_key.
- assimilate(belief, query_key, *, k=8, query=None, epsilon=0.0)[source]
Retrieve neighbors and fold selected evidence into
belief.For each retrieved item the sufficiency test compares how much raw evidence would reduce query entropy relative to embedding evidence. If the surplus exceeds
epsilonthe raw payload is used, else the embedding evidence is. Returns the updated belief and a per-item provenance trail.
- next_evidence(belief, *, query=None, candidates=None, fidelity='fine')[source]
Active retrieval: the corpus item whose evidence most reduces the query entropy (EIG).
Returns
(index, expected_gain_nats).fidelityselects thefine(raw) orcoarse(embedding) evidence builder for the look-ahead.