Compositionality
Beta in docs/STATUS.md. Mnemosyne is alpha, on the 3.6.x line, and the API
can still change within 3.x.
A composition rule says: when a recall returns memories that match this
pattern, derive this statement. The engine is a forward-chaining matcher over
the hits of a recall (packages/core/src/cognitive/compositionality.ts). It
makes no model call.
There are no built-in rules. A workspace starts with none and registers its own.
A rule
A rule has a condition and an action, both validated against a fixed schema
(packages/types/src/compositionality.ts).
curl -X POST http://localhost:3939/composition/rules \
-H "Authorization: Bearer mns_live_..." \
-H "Content-Type: application/json" \
-d '{
"name": "firmware-live-during-audit",
"description": "Flag a safety audit recalled together with the live firmware version.",
"conditionDsl": {
"all": [
{ "op": "text_contains", "needle": "runs firmware", "bind": "$firmware" },
{ "op": "text_contains", "needle": "safety audit", "bind": "$audit" }
]
},
"actionDsl": {
"op": "derive_warning",
"statementTemplate": "Check the audit scope against the live firmware. $firmware $audit",
"baseConfidence": 0.8
}
}'Conditions
conditionDsl.all holds 1 to 8 clauses, and all of them must match. A bind
names the matched hit so later clauses and the template can refer to it. Bind
names start with $.
op | Matches a hit when |
|---|---|
fact_kind | Its kind or its fact subtype equals kind |
topic_key_in | One of its tags is in topicKeys |
text_contains | Its content contains needle, ignoring case |
relation | The hit bound to from has a relation with verb to the hit bound to to |
fact_value | A number or duration parsed from the content of subject passes compare (lt, gt, lte, gte, against a number or another bind) |
The relation verbs are related, compatible, scoped, conflicts_with,
supersedes, not_conflict, derived_from, part_of and member_of.
Actions
op | Effect |
|---|---|
derive_fact | Derives a statement that can be stored as a fact with the attribution inferred |
derive_warning | Derives a warning. A warning is never stored as a fact |
In statementTemplate, a bind name is replaced by the content of the hit it
is bound to, and $ws by the workspace id. baseConfidence defaults to 0.7
and sensitivity to internal. The derived statement takes the lowest
sensitivity among the action’s sensitivity and the matched hits.
How rules run
After the cold tier of a recall has its page of hits, the engine evaluates the
active rules, highest priority first:
- A derived statement can feed another rule, up to 4 hops and 50 derivations per recall.
- Confidence is
baseConfidencetimes the average worth of the matched hits. A derivation with a confidence of 0.5 or less is dropped. Because a fact that was never rated has a worth of 0.5, a rule whose premises are all unrated does not clear that floor on the recall path. - When two derivations say opposite things, the one from the higher-priority rule is kept.
- Each derivation is appended to the inference log and the rule’s
executionCountgoes up.
POST /recall does not return the derived statements in its response today,
and no REST parameter asks recall to store derived facts. To see what a rule
derives, use the dry run. To see which rules fired, and on which memories,
read the log.
Trying a rule
POST /composition/dry-run evaluates one rule against hits you supply. It
never stores anything and applies no confidence floor, so you see every
derivation with its confidence.
curl -X POST http://localhost:3939/composition/dry-run \
-H "Authorization: Bearer mns_live_..." \
-H "Content-Type: application/json" \
-d '{
"ruleId": "RULE_ID",
"hits": [
{ "id": "f1", "primitive": "fact", "content": "The warehouse fleet runs firmware 4.2.1.", "score": 0.8, "worth": 0.7 },
{ "id": "f2", "primitive": "fact", "content": "The safety audit covers firmware 4.1 only.", "score": 0.7, "worth": 0.7 }
]
}'Pass rule in place of ruleId to try a rule that is not saved yet.
Routes
GET /composition/rules List; filter with isActive
POST /composition/rules Create
GET /composition/rules/{id}
PATCH /composition/rules/{id} Change or deactivate
POST /composition/dry-run Preview
GET /composition/inferences The inference log; filter with ruleId, derivedIdFrom MCP, memory_compose takes action: list, create, get, patch,
dry_run or inferences.