Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

12 Commits

Repository files navigation

multimind

Multi-Model Mind — a generic ONNX model registry with inference, correction signals, and a retrain pipeline.

Dual implementation: Rust (rust/) and Python (python/). Both expose the same architecture, traits/protocols, and signal stores. Multimind has zero knowledge of any particular product, domain, or storage layer — wire it into your own routing, storage, and deployment systems.

Architecture

┌─────────────────────────────────────────────────┐
│ ModelRegistry │
│ ┌────────────┐ ┌────────────┐ │
│ │ OnnxText │ │ OnnxEmbed │ ...custom... │
│ │ (TF-IDF) │ │ (384-dim) │ │
│ └─────┬──────┘ └─────┬──────┘ │
│ │ ModelBackend │ │
│ └───────┬───────┘ │
│ ▼ │
│ classify(input) → Verdict │
└────────────────┬────────────────────────────────┘
│ correction signals
▼
┌─────────────────────────────────────────────────┐
│ SignalStore │
│ ┌────────────┐ ┌────────────┐ │
│ │ Postgres │ │ SQLite │ ...custom... │
│ └─────────────┘ └────────────┘ │
└────────────────┬────────────────────────────────┘
│ batch export (with signal IDs)
▼
┌─────────────────────────────────────────────────┐
│ RetrainPipeline (optional) │
│ signals → features → learn → export → hot-swap │
└─────────────────────────────────────────────────┘

Repo Layout

Each subdirectory is independently installable with its own README, LICENSE, and build config.

multimind/
├── rust/ # Rust crate (cargo build / crates.io)
│ ├── Cargo.toml
│ ├── README.md
│ ├── LICENSE
│ └── src/
│ ├── lib.rs # Core types, traits (SignalStore, ModelBackend)
│ ├── config.rs # TOML config parsing
│ ├── registry.rs # ModelRegistry
│ ├── backends/ # ONNX inference backends
│ ├── signals/ # SQLite + Postgres signal stores
│ └── retrain/ # Pipeline, weight learning, artifacts
├── python/ # Python package (pip install / PyPI)
│ ├── pyproject.toml
│ ├── README.md
│ ├── LICENSE
│ ├── multimind/ # Package source (mirrors Rust module structure)
│ └── tests/ # pytest suite
├── LICENSE
└── README.md

Install just one language

Python only:

git clone https://github.com/digitalforgeca/multimind.git
cd multimind/python
pip install -e ".[dev]"
pytest -v

Rust only:

git clone https://github.com/digitalforgeca/multimind.git
cd multimind/rust
cargo build --features full
cargo test --features full

Each subdirectory is a complete, self-contained project — no cross-directory dependencies.

Core Concepts

ModelBackend — any inference engine that takes an input and returns a Verdict (label + confidence + per-class scores). Built-in: ONNX text (TF-IDF) and ONNX embedding (384-dim). Implement the trait/protocol for custom backends.

SignalStore — records correction signals (TrainingSignal) and exports them for retraining. Built-in: SQLite and PostgreSQL. Signal consumption is ID-targetedmark_consumed(model_id, signal_ids) only marks the specific rows from the exported batch, preventing race conditions with newly-arrived signals. mark_all_consumed is available for explicit drain operations.

RetrainPipeline — optional background loop that watches signal accumulation, runs retrain cycles (feature extraction → weight learning → artifact export), and hot-swaps models in the registry.


Rust

Features

FeatureDescriptionDefault
sqliteSQLite signal store via rusqlite
postgresPostgreSQL signal store via sqlx
retrainBackground retrain pipeline with artifact export
fullAll of the above

Quick Start

[dependencies]
multimind = "0.1"
use multimind::{ModelRegistry,MultimindConfig,ModelInput};let config = MultimindConfig::from_toml(r#" [[models]] id = "classifier" backend = "onnx-text" path = "models/classifier.onnx" labels = "models/labels.json""#).unwrap();let registry = ModelRegistry::new(config,".");let verdict = registry.classify("classifier",&ModelInput::Text("hello world".into())).unwrap();println!("{}: {:.2}", verdict.label, verdict.confidence);

Custom Backends

use multimind::{ModelBackend,ModelInput,Verdict};structMyApiBackend{/* ... */}implModelBackendforMyApiBackend{fnclassify(&self,input:&ModelInput) -> anyhow::Result<Verdict>{todo!()}fnreload(&self,_path:&std::path::Path) -> anyhow::Result<()>{Ok(())}fnbackend_name(&self) -> &'staticstr{"my-api"}}
registry.register_model("my_model",Box::new(MyApiBackend{/* ... */}));

Signal Collection

use multimind::{TrainingSignal,SignalStore};use multimind::signals::sqlite::SqliteSignalStore;let store = SqliteSignalStore::open("signals.db").unwrap();
store.record(&TrainingSignal{signal_id:None,model_id:"classifier".into(),input_text:"some input".into(),predicted_label:"safe".into(),corrected_label:"unsafe".into(),original_confidence:Some(0.72),}).unwrap();// Export → retrain → targeted consumelet batch = store.export_pending("classifier",Some(100)).unwrap();let ids:Vec<String> = batch.iter().filter_map(|s| s.signal_id.clone()).collect();// ... retrain with batch ...
store.mark_consumed("classifier",&ids).unwrap();

Retrain Pipeline

use multimind::retrain::{RetrainPipeline,RetrainConfig,WeightModel};let pipeline = RetrainPipeline::new(RetrainConfig::default(),"my_classifier",MyWeights{version:0,adjustments:Default::default()},);// Synchronous or background
pipeline.run_retrain(&signal_store,Some(&registry));
pipeline.start_background(signal_store.into(),Some(registry.into()));

Python

Installation

pip install multimind # core + SQLite
pip install multimind[postgres] # + PostgreSQL
pip install multimind[full] # all extras

Quick Start

frommultimindimportModelRegistry, MultimindConfig, ModelInputconfig=MultimindConfig.from_toml(''' [[models]] id = "classifier" backend = "onnx-text" path = "models/classifier.onnx" labels = "models/labels.json"''')
registry=ModelRegistry(config, ".")
verdict=registry.classify("classifier", ModelInput.from_text("hello world"))
print(f"{verdict.label}: {verdict.confidence:.2f}")

Custom Backends

frompathlibimportPathfrommultimindimportModelBackend, ModelInput, VerdictclassMyApiBackend:
defclassify(self, input: ModelInput) ->Verdict: ...
defreload(self, path: Path) ->None: passdefbackend_name(self) ->str: return"my-api"registry.register_model("my_model", MyApiBackend())

Signal Collection

frommultimindimportTrainingSignalfrommultimind.signals.sqliteimportSqliteSignalStorestore=SqliteSignalStore.open("signals.db")
store.record(TrainingSignal(
model_id="classifier",
input_text="some input",
predicted_label="safe",
corrected_label="unsafe",
original_confidence=0.72,
))
# Export → retrain → targeted consumebatch=store.export_pending("classifier", limit=100)
ids= [s.signal_idforsinbatchifs.signal_id]
# ... retrain with batch ...store.mark_consumed("classifier", ids)

Retrain Pipeline

frommultimind.retrainimportRetrainPipeline, RetrainConfigpipeline=RetrainPipeline(RetrainConfig(), "my_classifier", MyWeights())
pipeline.run_retrain(signal_store)
pipeline.start_background(signal_store, registry)

Requirements

  • Python 3.11+
  • numpy + onnxruntime for ONNX inference
  • psycopg2 (optional) for PostgreSQL

Running Tests

# Rustcd rust && cargo test --features full
# Pythoncd python && pip install -e ".[dev]"&& pytest -v

License

MIT — Digital Forge Studios

About

Multi-Model Mind — generic ONNX model registry, inference, signal collection, and retrain pipeline for Rust applications.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages