Expand description
On-device ML orchestration and the model inventory seam (SSoT: AI/ML Integrations).
This module owns the structure the AI design fixes — independent of which model actually runs:
-
the
registry— the canonical model inventory (one v1-committed row per task) and the embedding-provenance invariant (every embedding carries(model_id, model_version); the vector index refuses inserts from unknown models, while a superseded-but-known version is admitted as a stale-flagged row and excluded from queries until regenerated). It owns the version-bump swap primitive; -
the
regenloop — the background per-asset regeneration orchestration that consumes the staleness a swap creates: it walksstale_embedding_assetsand re-embeds each asset at the new canonical version through an injectedEmbedderseam, resumably and per-asset (never a global truncate). The production implementor isRunnerEmbedder, which rebuilds the derived index by re-reading each original throughAssetSourceand re-running the canonical model throughModelRunner— the same two seams first-time indexing uses, so a regenerated vector equals what a fresh import would produce. -
the
runnerseam — theModelRunnertrait every consumer routes per-task inference over decoded pixels through, and the deterministicFixtureRunnerdouble. Real per-platform runners (ONNX/CoreML/NNAPI, the CLIP runner) ride the default-off, weight-fetchinginferencefeature — a follow-up, never part of the default gate; -
the
orchestrator— the deterministic execution path for the v1-committed slots: run the canonical model over an asset, land semantic + face vectors in the rightvec0partition (platform-partition fallback), and write zero-shot AI tags intotags_aias a signed metadata update through theAiTagSinkseam — implemented byWorkspace, named as a trait somldoes not importlifecycle(which importsml); plus the device-bound batching/thermal policy.
Real per-platform inference is deferred behind the Embedder /
ModelRunner seams (the real runner is a later slice), exactly as live
MLS group state is deferred behind AlbumAuthority
with ReferenceAuthority standing in; the deterministic
DeterministicEmbedder and
FixtureRunner drive every path with no model weights. The local
vector index is the VectorIndex port; its SQLite adapter is capsule-library’s catalog. No model weights are committed to this repository.
Re-exports§
pub use registry::DistanceMetric;pub use registry::EmbeddingDim;pub use registry::ModelId;pub use registry::ModelVersion;pub use registry::RegistryError;pub use registry::TaskKind;
Structs§
- BBox
- A normalized bounding box (coordinates in
[0, 1]). - Detection
- A detection from a detection task (object box, face box + landmarks downstream).
- Deterministic
Embedder - A deterministic reference embedder — no real inference, no model weights. It maps
(asset_id, canonical_version)to a stable L2-normalized vector, so: - Embed
Error - A failure producing an embedding for an asset.
- Embedding
Insert - A provenanced embedding to insert into the index: the subject asset, the producing model
(task, model_id, model_version), theplatformpartition discriminator, and the vector. - Embedding
Record - A stored embedding’s provenance (from the companion table; the vector itself stays in
vec0). - Fixture
Runner - A deterministic, weightless runner for tests. Declares the canonical model versions from a
Registry(so its outputs satisfy the embedding-provenance invariant) and embeds by hashing input bytes — content equality ⇒ vector equality, which makes semantic matches reproducible. - Frame
- One image (or video keyframe) handed to a runner. The offline core passes the asset’s bytes; a real runner decodes + runs the model, the fixture hashes them.
- KnnHit
- A single nearest-neighbour hit.
- Known
Answer - A known-answer probe pinning the deterministic execution path for a task: a fixed input and the
exact embedding a bit-exact device must reproduce. Comparing a runner’s output to
expectedbit-for-bit is the byte-identical known-answer check the contract requires. - Model
Row - One inventory row: the canonical model for a
TaskKind— a v1-committed slot from AI/ML — Pipeline Slots, carrying the model, its function, and its named fallback. - Regen
Report - The outcome of one regeneration invocation.
- Registry
- The model inventory seam and the embedding-provenance gate.
- Runner
Embedder - The production
Embedder: regeneration re-runs inference over the originals. - Store
Error - A failure from the asset store behind the
AssetSource/AiTagSinkseam, type-erased. - Vector
Table Spec - The shape of one task’s
vec0partition table: which task it serves, and the(dim, metric)its vectors are sized and ranked by.
Enums§
- Batch
Mode - Per-asset execution mode, chosen from available memory at task start.
- Orchestrator
Error - Failures from orchestrating inference.
- Regen
Error - Failures from the regeneration loop.
- Runner
Error - Errors a runner can return.
- Task
Output - What a task produces: a stored embedding vector, or detections that feed downstream stages.
- Vector
Index Error - Failures from the vector index.
Constants§
- CANONICAL_
PARTITION - The shared partition every device that reaches bit-exactness on the deterministic execution
path writes into. Devices that cannot fall back to their own
platformtag and are never merged into this partition. - MICRO_
BATCH_ SIZES - The micro-batch sizes that keep the NPU cache hot.
Traits§
- AiTag
Sink - The write side: an asset store that accepts AI tags for an asset.
- Asset
Source - The store the orchestrator reads asset pixels from and indexes vectors into.
- Embedder
- The embedder seam the regeneration loop drives: “produce the canonical embedding for an asset under a task”. Abstracting it keeps the orchestration testable with a deterministic double and independent of any real model runtime.
- Embedding
Provenance - The embedding-provenance gate the vector index calls before it stores or ranks anything —
the seam through which the model inventory reaches the index without the index depending on
ml. - Model
Runner - The inference seam every consumer routes through. Implemented by real per-platform runners
(behind the
inferencefeature) and byFixtureRunnerfor tests. - Vector
Index - The store port the ML layer writes embeddings into and ranks them from.
Functions§
- auto_
tag - Zero-shot tag
asset_id: embed the image and each candidate label with the semantic-search embedder, then add as AI tags every label whose cosine similarity to the image clearsthreshold. The tags land in the asset’stags_aiOR-set as one signed metadata update (never intags_user), each carrying the canonical(model_id, model_version). Returns the labels assigned. No separate classifier — the semantic embeddings are reused. - choose_
batch_ mode - Pick the execution mode: go vertical only when the estimated resident set fits the RAM budget; otherwise stay horizontal to bound peak memory.
- embed_
and_ store - Embed
asset_idundertask’s canonical model over its decoded pixels and store the vector in the task’svec0partition underpartition(resolve it withresolve_partition). Serves both embedding slots —SemanticSearchandFaceRecognition. Refuses a non-canonical runner before touching the index. The index is derived state, so no signed manifest is minted (recovery-first: it is rebuilt by re-running inference). - micro_
batch_ size - The largest micro-batch size (from
MICRO_BATCH_SIZES) that fits both the pending count and the deviceceiling. Always at least 1. - regenerate_
stale - Regenerate stale embeddings for
taskinembedder’s platform partition, re-deriving the work-list fromstale_embedding_assetson each call. - resolve_
partition - Resolve the
vec0partitionrunner’s embeddings forka.taskmust land in. - semantic_
search - Natural-language search: embed
querywith the semantic-search embedder and return theknearest assets inpartition’s current canonical version (stale/other-partition vectors are excluded structurally). - should_
pause_ for_ heat - Whether to pause the pipeline for heat: at or above
threshold_cthe OS may kill the app, so the pipeline pauses until cooldown.
Type Aliases§
- Embedding
- An embedding vector (L2-normalized by convention, so cosine ranks like the inner product).