polysemic.systems
Documentation

Five minutes to a living seam.

The Rust cores are std-only and dependency-free. Three standalone proofs make their boundary contracts executable.

1 · Install

$ git clone https://github.com/Polysemic-Systems/polysemic.git
$ cd polysemic
$ cargo test --workspace
$ cargo run --quiet -p seam-demo

2 · Run the standalone proofs

# Digest: clarify first, then apply only the requested answer
$ cargo run --quiet -p digest-poc -- demo

# Strata: compare provenance-bound ontology snapshots
$ cargo run --quiet -p strata-poc -- demo
$ python3 examples/strata-poc/verify_commitments.py

# Lethe: erase from PostgreSQL+pgvector and Redis
$ python3 examples/lethe-stores/lethe_poc.py demo

3 · Define the legislated layer

A schema is a floor, not a ceiling: it legislates the fields it names and lets extra meaning pass through.

use digest::{digest, digest_with_answers, Answer, Field, Outcome, Schema};
use polysemic_core::Value;

let schema = Schema::obj([
    Field::req("item", Schema::Str),
    Field::req("qty",  Schema::num_range(1.0, 99.0)),
    Field::opt("gift_wrap", Schema::Bool),
    Field::opt("size", Schema::choice(["small", "double", "triple"])),
]);

4 · Digest the mess

This is real model output — fenced, single-quoted, Pythonic, trailing comma, hedged quantity. A normal Tuesday.

let raw = r#"Sure — here's the order:
```json
{'item': 'espresso', 'qty': '2 or 3', 'gift_wrap': True,}
```"#;

let d = digest(raw, &schema)?;

for repair in &d.repairs {
    println!("repaired: {repair}");
    // stripped markdown fence
    // rewrote Python literals (True/False/None)
    // rewrote single-quoted strings
    // removed trailing commas
}

match d.outcome {
    Outcome::Resolved(order) => commit(order),
    Outcome::Clarify(questions) => {
        // $.qty — "2 or 3" holds two readings [2 | 3]
        ask_user(questions)
    }
}

// Apply only the path Digest asked about; the answer is ledgered.
let answered = digest_with_answers(
    raw, &schema, [Answer::new("$.qty", Value::Num(2.0))]
)?;

5 · For high-stakes calls, reconcile

use digest::reconcile;

let r = reconcile(&[sample_1, sample_2, sample_3], &schema)?;
// field-wise majority commits; dissent becomes a question.
// the model's variance is polysemy, not noise.

6 · Keep provenance attached to meaning

use strata::{Labor, OntologySnapshot, ProvenanceEnvelope, ProvenanceLabel};

let baseline = ProvenanceEnvelope::new(
    "family-support-router", "model-v1",
    "examples/strata-poc/model-v1.artifact.json",
    "c46701df82ea273c52dfbaabb32a6d0ebed76a7b1bb283a28270529da7e0f208",
    ProvenanceLabel {
        corpus: "archived-support-tickets".into(),
        source_uri: "examples/strata-poc/archived-support-tickets.manifest.txt".into(),
        corpus_sha256: "6b8f664ed4b1a1142ab6751a5173a9b54f8f015c009b5a55e8051fa56c73a3c4".into(),
        tokens: 12_500_000,
        vintage: "2018-01..2019-12".into(),
        languages: vec![("en".into(), 1.0)],
        annotator_labor: Labor::Uncredited,
        notes: vec![],
    },
    OntologySnapshot::new("family", "model-v1", [
        ("nuclear", "married parents and their dependent children"),
        ("single_parent", "one parent and dependent children"),
    ]),
);

let observed_label = ProvenanceLabel {
    corpus: "support-policy-workshop-2026".into(),
    source_uri: "examples/strata-poc/support-policy-workshop.manifest.txt".into(),
    corpus_sha256: "09773973f2845e3197046bac6cfda515d41ec44d845dc1fb1a627b9a400f4cdb".into(),
    tokens: 820_000,
    vintage: "2025-10..2026-06".into(),
    languages: vec![("en".into(), 1.0)],
    annotator_labor: Labor::Credited,
    ..baseline.provenance.clone()
};
let observed = ProvenanceEnvelope::new(
    "family-support-router", "candidate-v2",
    "examples/strata-poc/candidate-v2.artifact.json",
    "229f9c92872dcd0adef98e938ea25516538ee1e5fd41fe1dec81478579ac96a3",
    observed_label,
    OntologySnapshot::new("family", "users-2026-07", [
        ("nuclear", "a household's primary care network"),
        ("chosen", "people intentionally recognized as family"),
    ]),
);

let drift = baseline.compare(&observed, "nuclear")?;
assert!(drift.probe.changed());
// +chosen, -single_parent, ~nuclear
// drift.baseline and drift.observed retain both histories

7 · Give memory an exit

use lethe::{Lethe, RetentionPolicy};
use std::time::{Duration, Instant};

let mut memory = Lethe::new(Duration::from_secs(3600), 0.05);
let now = Instant::now();

let policy = RetentionPolicy::new(
    "customer-preference-v1", Duration::from_secs(90 * 24 * 3600)
);
memory.remember_with_policy("user:8842", "prefers oat milk", &policy, now);

memory.recall("oat", now);   // recall is use; use keeps memories alive
memory.sweep_with_receipt(now); // the garden, pruned and receipted

let receipt = memory.forget(|m| m.subject == "user:8842");
// ✓ 1 memory released — lethe://era/…  (deletion you can prove)

API at a glance

CallWhat it guarantees
digest(raw, &schema)A trusted value or explicit questions — never a value you can't trust. All repairs named.
reconcile(&samples, &schema)Majority commits; dissent merges all candidates; empty input is rejected. Per-sample digestions are retained.
ProvenanceEnvelope::compareOntology drift plus a concept probe, with both corpus and labor histories retained.
DriftWatch::compareA 0–1 total-variation result or an explicit error for negative, non-finite, or empty distributions.
Legislature::resolveEvery answer names its layer: grown or legislated-with-reason.
Lethe::rememberTTL is a required argument. Nothing enters without an exit plan.
Lethe::sweep_with_receiptScheduled expiry and salience pruning return a deletion commitment.
ErasureCoordinator::erase_subjectComplete only after every durable-store adapter verifies absence.

Honest limitations

The open-source cores are deliberately small: Digest supports an explicit JSON Schema subset and rejects numbers that cannot round-trip exactly; Strata's ontology diff compares normalized text while its behavior proof executes a committed deterministic router rather than a general model runtime; SHA-256 proves fixture integrity, not signer identity; core receipts use FNV-1a while the Lethe store proof uses SHA-256; and the PostgreSQL+pgvector and Redis adapters shell into version-pinned local containers rather than native drivers. The seams where you'd extend them are marked in the doc comments.