Skip to content

Function: bind()

@kortexya/reasoninglayer


@kortexya/reasoninglayer / bind

bind<T>(name, term): T

Defined in: src/builders/psi.ts:151

Name a clause’s own identity, so another clause can refer to the SAME term.

T extends PsiTermInput

string

The binder, e.g. "?C". Must start with ?.

T

The term the binder names, from psi.

T

The same term, carrying the binder.

ValidationError when name does not start with ?.

This is the OSFQL ?C: sort(...) form. Without it a rule can only relate two clauses through their feature VALUES — “an invoice whose number matches this payment’s invoice_number”. With it a clause refers to the identity of the term another clause bound, which is what a rule about a referenced term needs.

Refer to the bound term from elsewhere in the rule with the plain variable "?C"; the engine reads the join from the term ids.

A nested term (a feature value, or the clause of not()) keeps its binder since engine #438, so a nested bind() adds an identity join too.

Only meaningful in an inference context. Term CRUD ignores it.

import { bind, psi } from '@kortexya/reasoninglayer';
// "a line whose order is THIS order" — not "an order with the same number"
await client.inference.addRule({
term: psi('large_order', { order: '?O' }),
antecedents: [
bind('?O', psi('sales_order', { status: 'open' })),
psi('order_line', { order: '?O', amount: '?A' }),
],
});