7. FIBER clauses
FIBER clauses extend a query with reasoning delegated to a registered institution. The specification is in D2 §3.5 + §5.8 + §7.12; the underlying institution model is D14. The implementation is apply_fiber_clause in evaluate.rs.
The pattern: you declare an institution alias, name an OnDemand QueryClass, supply property-shaped param bindings (with optional comorphism coercion in param values), and bind the response resource to a variable that subsequent clauses can match against.
8.1. Anatomy
UsingInstitution ::= 'USING' 'INSTITUTION' StringLit 'AS' ident
FiberClause ::= 'FIBER' institution_ref ':' QueryClass '{' ParamBinding (',' ParamBinding)* '}' 'AS' Variable
ParamBinding ::= Name ':' ParamValueParamValue ::= Expression | ComorphismCoercionComorphismCoercion ::= QualifiedName '(' Expression ')'Where institution_ref is either an alias (ShortName) or an inline full IRI (FullIri). The QueryClass referenced by the clause must declare OnDemand in its dispatch_role set (D14 §7.2).
USING INSTITUTION "urn:eigenius:demo:d14:assay" AS assay
FIBER assay:validate_prediction { candidate: ?p} AS ?checkUSING INSTITUTION introduces the alias at the top of a MatchPart. Aliases are scoped to their MatchPart and must be unique within that scope; re-declaring is a type error (duplicate_using_institution_alias).
FIBER performs the dispatch. Its three parts:
institution:query_class— who to ask and whichOnDemandQueryClass.{ param: value, ... }— the input resource’s property bindings. Avalueis either a regular expression, or a comorphism coercion (comorphism_iri(source)) that runs the four-step extract → transform → reify pipeline inline. See §8.5 below.AS ?var— where to put the response IRI in the current binding.
8.2. Evaluation walk-through
For each binding in the current binding set, apply_fiber_clause:
- Resolves the institution and QueryClass. Alias lookup against the
MatchPart’sUSING INSTITUTIONaliases (or inline IRI). The QueryClass IRI is resolved through theInstitutionIndex; the cited QueryClass’sinstitution_refmust equal the aliased / inline institution (fiber_institution_mismatchif not), andOnDemandmust be among itsdispatch_rolevalues (fiber_query_class_not_on_demandif not). - Builds an input resource. Starts with
is_a: [QueryClass.query_class](the input class declared by the QueryClass). For eachparam:- The param name is resolved to a property IRI by walking the input class’s
requires∪recommendslooking forshort_namematches; full-IRI param names pass through. - If the value is a regular expression, it’s evaluated with the current binding.
- If the value is a comorphism coercion, the kernel runs the four-step pipeline (§8.5) and uses the reified target-class resource as the property’s value.
- The param name is resolved to a property IRI by walking the input class’s
- Dispatches. Looks up the QueryClass’s
institution_refin theInstitutionRuntimeand callsInstitution::query(query_handler, input_resource, ctx)(D14 §8). The institution returns a result resource. - Stamps the response. The response gets a deterministic IRI via
fp.fiber_response_iri(clause_idx, binding_idx)— stable per (query text, clause, binding). Subsequent runs against the same inputs produce the same overlay resource identity. - Attaches to the overlay. The stamped resource is pushed into the
FiberOverlay— visible to all subsequent pattern matching in this query only. - Extends the binding.
?checkis bound to the response IRI as aValue::String.
Step 6 is why subsequent clauses can reference ?check just like any resource:
FIBER assay:validate_prediction { candidate: ?p } AS ?checkWHERE ?check HOLDSThe WHERE clause uses a postfix Verdict predicate (§9.4) to project the bound Verdict response to a Boolean — see chapter 9 for the full Verdict surface.
8.3. Requirements on the runtime
FIBER clauses require the FiberRuntime to carry the D14 dispatch handles:
pub struct FiberRuntime<'a> { pub index: Option<&'a InstitutionIndex>, pub runtime: Option<&'a InstitutionRuntime>, pub components: Option<&'a ComponentRegistry>, pub overlay: Option<&'a [(Iri, Resource)]>, pub ctx: Option<&'a ExecutionContext>,}indexandruntimeare required for any FIBER clause: the index resolves the QueryClass and the runtime answers the dispatch.componentsis required when any FIBER param value uses comorphism coercion (§8.5) — the four-step pipeline applies the comorphism’s transformation Component, which lives in the component registry. v1 restricts the cited transformation toPureorReadcapability levels.ctxis required for any FIBER clause; the institution’s handler may need read access to the layer chain through the execution context.overlayis populated automatically as preceding FIBER clauses add their responses; you don’t pass it in.
Queries executed via the convenience execute(program_str, layer) (no runtime) cannot use FIBER — it constructs a FiberRuntime::default() with all fields None and dispatch errors at the first FIBER clause. Use execute_with(program_str, layer, FiberRuntime { … }) when your query needs FIBER dispatch.
8.4. The transient overlay
The overlay model (D2 §7.12) isolates FIBER responses from the persistent layer:
- Responses live in
FiberOverlayfor the duration of a single query evaluation. - Pattern matching in subsequent clauses scans the overlay in addition to the layer (and derived relations).
- The overlay is discarded when
evaluate()returns. Nothing is committed to the layer.
This lets queries use institution reasoning without side effects. Two successive runs of the same query produce identical results only if the institution’s query() is deterministic — the overlay IRIs themselves are stable because fp.fiber_response_iri is deterministic, but the institution is free to return different responses.
8.5. Comorphism coercion in param values
A FIBER param value can be a comorphism coercion — comorphism_iri(source_expression) — which runs the four-step pipeline (D14 §10.3) inline and uses the reified target-class resource as the property’s value:
USING INSTITUTION "urn:eigenius:demo:d14:assay" AS assay
MATCH DockingResult(?d) { delta_g: ?dg }FIBER assay:validate_prediction { candidate: dock_to_assay(?d)} AS ?checkWHERE ?check HOLDSHere dock_to_assay is a Comorphism resource (D14 §4.5). At evaluation:
- The kernel resolves the comorphism in the
InstitutionIndex(readexport_format,transformation,import_format). - Extract. Calls the source institution’s
Institution::extract_typed(export_format.procedure, ?d, ctx)→ typed payload of the export’spayload_type. - Transform. Applies the transformation Component to the payload via the kernel’s component evaluator → typed payload of the import’s
payload_type. The Component must be registered in theFiberRuntime.componentsand itscapability_levelmust bePureorRead(see §8.3). - Reify. Calls the target institution’s
Institution::reify(import_format.procedure, payload, ctx)→ the target-class resource.
The reified resource is set as the property’s value on the FIBER’s input resource.
Under D14 §10.3, the reified resource also commits to the chain at a deterministic content-hash IRI of the form urn:eigenius:comorphism-output:<comorphism-tail>:<hex16> (SHA-256 over canonical Eigon-CBOR with @id cleared). Re-running the same input dedupes to the same IRI. AutoOnLoad gates bound to the produced class fire on the resulting commit exactly as if the resource had been authored by hand.
The type checker validates that the cited comorphism’s import-side to_class matches (or is a subclass of) the QueryClass’s expected class type for that property (comorphism_coercion_class_mismatch if not), and that the transformation Component is Pure or Read (comorphism_io_not_supported_in_v1 if IO — D2 v1 restriction).
Comorphisms are not available in expression position elsewhere in EigenQL — only inside FIBER param values, and (in ESL) as qualified-name function calls in program bodies. See chapter 9 for the full classification table and ESL §10.5 for the ESL surface.
8.6. INTO — pinning the response IRI
A FIBER clause can name an explicit IRI for its response via the INTO keyword, written after AS ?var:
USING INSTITUTION "urn:eigenius:institutions:symbolics" AS symb
FIBER symb:"urn:eigenius:symbolics:query_classes:qc_symb_to_jump" { "urn:eigenius:symbolics:objective": "urn:…:sse_expr", "urn:eigenius:symbolics:variable_names": ["Ki"], "urn:eigenius:symbolics:framing_variable_bounds": ["urn:…:ki_bound"], "urn:eigenius:symbolics:sense": "Min"} AS ?problem INTO "urn:eigenius:notebook:kinase_demo:fiber_problem"RETURN [] { iri: ?problem }The dispatch is identical to a plain FIBER ... AS ?var clause; the difference is chain reinsertion: the response resource commits to the regular chain at the named IRI, rather than living in a transient overlay. Both surfaces share the same commit_with_validation machinery — AutoOnLoad gates bound to the response’s class fire on commit, the response is reachable by every subsequent query, and the audit trail (Verdict + RuntimeInvocation) is the standard one.
The INTO IRI is mandatory if you want chain reinsertion; without it, the response stays overlay-only (the v0 behaviour). Pinning at a caller-named IRI is the contrast with the comorphism program-invoke form (§8.5 above), where the kernel mints a content-hash IRI for you.
INTO is a hard keyword (D2 v2 §3.5). The full grammar:
FiberClause ::= 'FIBER' institution_ref ':' QueryClass '{' params '}' 'AS' '?'<ident> ('INTO' StringLiteral)?The string after INTO must be a syntactically-valid IRI; the type checker validates it (fiber_into_iri_invalid if not).
8.7. FIBER vs. Decidable vs. comorphism coercion
Three ways an EigenQL query can involve an institution. They have different shapes and semantics:
| Mechanism | Syntax | Returns | When to use |
|---|---|---|---|
| Decidable QueryClass | inst:predicate(args) HOLDS (or FAILS/UNDECIDABLE) in WHERE/RETURN | Verdict projected to Boolean by the postfix predicate | Yes/no filtering with explicit handling of Undecidable |
FIBER clause | FIBER inst:QueryClass { params } AS ?var | Binds an institution-returned response resource (whose class is the QueryClass’s result_class) | Multi-property responses; the bound variable participates in later pattern matching |
| Comorphism coercion | param: comorphism_iri(source) inside a FIBER param block | A target-class resource set on the FIBER’s input | Crossing an institution boundary into the FIBER’s input vocabulary |
A query can mix all three. FIBER is the most powerful shape because the bound variable participates in later pattern matching; Decidable is the simplest call that produces a single Verdict; comorphism coercion is the controlled boundary-crossing form.
8.8. Type-checking rules
The type checker (kernel/src/query/type_check.rs) validates:
undeclared_institution_alias— the alias inFIBER alias:Q { … }wasn’t declared withUSING INSTITUTION.duplicate_using_institution_alias— twoUSING INSTITUTIONclauses in the sameMatchPartuse the same alias.fiber_query_class_not_class— the query class IRI doesn’t resolve, or resolves to something that isn’t aClass.fiber_query_class_not_on_demand— the QueryClass is declared but itsdispatch_roleset doesn’t includeOnDemand.fiber_institution_mismatch— the QueryClass’sinstitution_refdoesn’t match the alias / inline IRI in the FIBER clause.fiber_param_short_name_unresolved— a param short name isn’t a property thatrequiresorrecommendsdeclares on the query class.fiber_missing_required_param— arequiresproperty of the query class wasn’t supplied in the param list.comorphism_coercion_class_mismatch— a comorphism coercion’s import-sideto_classdoesn’t satisfy the FIBER input class’s expected type for that property.comorphism_io_not_supported_in_v1— a comorphism’s transformation Component requiresIOcapability.unknown_comorphism— a comorphism coercion references an IRI that isn’t a registeredComorphism.
The check runs before evaluation, so malformed FIBER clauses fail fast at compile time.
8.9. Determinism and the response IRI
Response IRIs are generated by QueryFingerprint::fiber_response_iri(clause_idx, binding_idx) — a deterministic function of the query text (hashed to a fingerprint), the clause index within the query, and the binding index within the clause’s iteration.
This matters because:
- Reproducibility: re-running the same query over the same layer produces the same overlay IRIs (institution response content may vary if the institution is non-deterministic, but IRIs are stable).
- Caching: higher layers that cache query results can key on both the query text and the overlay IRI scheme.
- Debugging: a response IRI contains the query hash, so error messages reference traceable identities.
The response IRI format is urn:eigenius:query:gen:<8-hex>:fiber:<clause>:<binding>.
8.10. Example: comorphism coercion + Verdict postfix
Drawn from the M8 worked example (kernel/tests/d14_dock_assay_demo.rs) — chains a comorphism coercion through a FIBER OnDemand QueryClass and projects the resulting Verdict to a Boolean filter:
USING "urn:eigenius:demo:d14:DockingResult"USING INSTITUTION "urn:eigenius:demo:d14:assay" AS assay
MATCH DockingResult(?d) { "urn:eigenius:demo:d14:delta_g": ?dg}FIBER assay:validate_prediction { candidate: dock_to_assay(?d)} AS ?checkWHERE ?check HOLDSRETURN [] { docking: ?d, delta_g: ?dg}For each docking result the kernel:
- Runs
dock_to_assay’s four-step pipeline — extract ΔG via the dock institution, apply the Arrhenius transformation Component, reify anAssayPredictionvia the assay institution. - Synthesises the FIBER input as
validate_prediction’s declared input class withcandidateset to that prediction. - Calls
assay’squeryhandler forvalidate_prediction— returns aVerdictresource. - Projects the Verdict via
?check HOLDS— keeps rows where the assay institution accepts the predicted IC₅₀ as physically plausible.
Behaviour notes:
- The Verdict bound to
?checklives in the overlay — it’s referenceable by IRI as a regular resource, not just through the postfix predicate. - If
?dyields N bindings, N four-step pipelines + Nvalidate_predictiondispatches run sequentially. FIBER is not batched yet.
Next: 9. Institutions →