mixle.substrate.core moduleΒΆ
Core substrate store and item model.
The substrate is a filesystem-backed, queryable surface for typed items with
provenance, scope, freshness metadata, tags, and links. Raw data, documents,
model artifacts, traces, simulation outputs, ontology triples, and context
packets can all be represented as SubstrateItem records.
Text and document items rank by cosine similarity over a learned embedding when available. Structured records and other items fall back to lexical, tag, and provenance matching. Higher-level retrieval and context assembly build on this single local store.
- class SubstrateItem(kind, text='', payload=<factory>, provenance=<factory>, scope='local', tags=<factory>, links=<factory>, id=<factory>, created_at=<factory>)[source]
Bases:
objectOne typed, provenanced, scoped item in the substrate.
- Parameters:
- kind: str
- text: str = ''
- scope: str = 'local'
- id: str
- created_at: float
- class Substrate(root=None)[source]
Bases:
objectA local shard of the knowledge substrate: a filesystem-backed store with typed retrieval.
put/get/remove/allmanage items;searchretrieves thekmost relevant items for a query, filtered by kind and scope, ranking text items semantically (a learned embedding over the current text corpus) and everything else lexically.save/loadpersist the shard as oneitems.jsonlunderroot.- Parameters:
root (str | None)
- put(item)[source]
Add or replace an item; returns its id. Marks the semantic index dirty for text items.
- Parameters:
item (SubstrateItem)
- Return type:
- add(kind, text='', **kw)[source]
Convenience: build a
SubstrateItemandput()it.
- all(*, kind=None, scope=None)[source]
- reindex()[source]
(Re)fit the embedding index over the current text-bearing items. Idempotent, lazy-called.
- Return type:
None
- search(query, k=5, *, kind=None, scope=None)[source]
The
kmost relevant items toqueryas(item, score), filtered by kind/scope.Text-bearing items rank by cosine similarity in the learned embedding space; when there are too few items to learn one (or for a non-text query), ranking falls back to a lexical token overlap. Structured items with no text always rank lexically over their serialized payload + tags.
- save(root=None)[source]
Persist the shard to
{root}/items.jsonl(one item per line).