mixle.reason.store module¶
Cross-modal RAG with a raw-data fallback: retrieve by embedding, condition on raw evidence.
Embedding-only retrieval (embed everything, fetch top-k, stuff the vectors in) loses information twice for modalities too lossy to compress – a full spectrum, a thin-section image, a seismic sub-volume. This store treats retrieval as evidence selection for Bayesian assimilation instead:
index the corpus by a cheap 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 cheap embedding evidence; if so, fetch the raw payload and condition the belief on it through its full (precise) evidence;
fuse each choice into the belief (a product-of-experts update), recording provenance;
optionally retrieve actively – fetch the corpus item that most reduces the query entropy.
Domain-neutral: the store knows nothing about seismic or spectra. The application supplies two
callables – coarse(payload) -> Evidence (embedding fidelity) and fine(payload) -> Evidence
(raw fidelity) – so the same machinery serves a document corpus or one spatially-indexed volume
(see the mixle_pde spatial-store application).
- class RetrievalStep(index, fidelity, gain)[source]
Bases:
objectProvenance for one assimilated item: which corpus index, at what fidelity, and the nats it removed.
- index: int
- fidelity: str
- gain: float
- 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 – the retrieval index (routers, not answers).payloads (Sequence[Any]) – length-
Nsequence of raw items (arbitrary; passed tocoarse/fine).coarse (Callable[[Any], LinearGaussianEvidence]) –
payload -> LinearGaussianEvidenceat embedding fidelity (cheap, 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]
Indices of the
kcorpus items whose embedding keys are nearestquery_key.
- assimilate(belief, query_key, *, k=8, query=None, epsilon=0.0)[source]
Retrieve
kneighbors and fold each intobelief, fetching raw payloads when the embedding is too lossy for thequery.For each retrieved item the sufficiency test compares how much the raw evidence would reduce the query entropy versus the embedding evidence; if the surplus exceeds
epsilonthe raw payload is used, else the cheap embedding 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.