Skip to content

Governed Vocabulary

client.vocabulary manages a tenant’s governed controlled vocabulary: concept schemes, concepts, definitions, labels in several languages, scheme memberships and their evidence. A change never edits the active vocabulary in place. It goes through a reviewable workflow:

create candidate ─▶ save revisions ─▶ assess ─▶ submit ─▶ review ─▶ approve ─▶ release ─▶ activate
(author) (author) (author) (author) (steward) (steward) (steward) (steward)
  • A candidate holds immutable revisions of a change set. Each revision has a contentHash; every decision cites the revision and its hash.
  • An assessment checks the revision against a criteria set (assessment.criteriaId, for example vocabulary-assessment/v4) and reports findings. Only a complete, passed assessment admits an approval.
  • Approval and release change neither the active release nor the knowledge base. A release is an immutable snapshot.
  • Activation swaps the tenant’s active-release pointer (compare-and-set) and writes the release’s records as Psi-terms of the com.kortexya.knowledge-organization plugin, in one transaction.

Nothing in the vocabulary creates a sort, a parent edge or a rule: a definition’s genus text stays text (definitionGuidance.parentEdgeCreated is always false).

  • The first-party knowledge-organization plugin is installed system-wide. client.vocabulary.status() reports it; every other route except getRequestOutcome refuses with 409 vocabulary_plugin_unavailable without it.
  • The tenant holds the authorization facts: the engine re-proves author_vocabulary, assess_vocabulary, review_vocabulary, approve_vocabulary, release_vocabulary and activate_vocabulary at each step. A deployment’s gateway provisions them.
  • Each mutation is made by the client’s authenticatedUser (user:<uuid>). An author may not review, reject or approve a revision they authored, so the author and the steward are two clients.
import { ReasoningLayerClient } from '@kortexya/reasoninglayer';
const config = {
baseUrl: 'https://platform.ovh.reasoninglayer.ai',
tenantId,
auth: { mode: 'cookie' as const },
};
const author = new ReasoningLayerClient({ ...config, authenticatedUser: `user:${authorId}` });
const steward = new ReasoningLayerClient({ ...config, authenticatedUser: `user:${stewardId}` });
const status = await author.vocabulary.status();
if (!status.plugin.available) throw new Error(`plugin: ${status.plugin.finding?.observed}`);

Every mutation takes a required idempotencyKey. The SDK never invents one: create it once per intended change, bind it to a variable before the call, and pass the same variable on every retry. A key created inside the call ({ idempotencyKey: crypto.randomUUID() }) changes on each attempt, so a retry becomes a new request.

  • An identical repeat answers the committed outcome with replayed: true and writes nothing.
  • The same key with a different request throws IdempotencyKeyReusedError (422).
  • A key is 1 to 128 characters of [A-Za-z0-9._:-].

Records refer to each other by id ({ by: 'record', recordId }) or, inside one request, by a client reference ({ by: 'client_ref', clientRef }). The response maps each client reference to the id the engine minted.

const createKey = crypto.randomUUID();
const revision = await author.vocabulary.createCandidate(
{
title: 'Production Approval Gate',
changeReason: 'Create the concept',
operations: [
{
op: 'upsert',
record: {
kind: 'scheme',
clientRef: 'mwg',
displayName: 'Manufacturing Workflow Governance',
purpose: 'Name the workflow-governance concepts.',
languages: [
{ language: 'en', obligation: 'required', rank: 1 },
{ language: 'fr', obligation: 'display_fallback', rank: 2 },
],
},
},
{ op: 'upsert', record: { kind: 'concept', clientRef: 'pag', status: 'accepted' } },
{
op: 'upsert',
record: {
kind: 'definition',
concept: { by: 'client_ref', clientRef: 'pag' },
language: 'en',
text: 'A workflow step that requires an authorized approval before a production deployment can proceed.',
genusText: 'Workflow Step',
differentiaText: 'requires authorization before a production deployment can proceed',
},
},
{
op: 'upsert',
record: {
kind: 'label_use',
concept: { by: 'client_ref', clientRef: 'pag' },
scheme: { by: 'client_ref', clientRef: 'mwg' },
text: 'Production Approval Gate',
language: 'en',
role: 'preferred',
},
},
{
op: 'upsert',
record: {
kind: 'membership',
concept: { by: 'client_ref', clientRef: 'pag' },
scheme: { by: 'client_ref', clientRef: 'mwg' },
status: 'accepted',
topConcept: true,
},
},
],
},
{ idempotencyKey: createKey },
);
const conceptId = revision.mintedIds.pag;

A later edit saves a new revision on the head: pass the head revision id (or the candidate’s ETag) as ifMatch. If someone saved in between, the call throws PreconditionFailedError and nothing is written; currentEtag names the new head.

const saveKey = crypto.randomUUID();
const next = await author.vocabulary.saveRevision(
revision.candidateId,
{ changeReason: 'Add an alternative label', operations },
{ idempotencyKey: saveKey, ifMatch: revision.revisionId },
);

A revision answer counts its records by kind (recordCounts, wire kind spelling → count); it does not carry the records. Read them page by page (by id, limit 1 to 500, engine default 50), optionally of one kind:

console.log(next.recordCounts.concept); // e.g. 5
let cursor: string | undefined;
do {
const page = await author.vocabulary.listRevisionRecords(next.revisionId, {
kind: 'concept',
limit: 200,
...(cursor === undefined ? {} : { cursor }),
});
for (const record of page.items) console.log(record.recordId);
cursor = page.nextCursor;
} while (cursor !== undefined);

Two more operations fit in any createCandidate or saveRevision request:

  • definition_policy (one per scheme, definition-policy/v1) states whether the scheme’s accepted concepts need a definition (required or optional).
  • accept_proposals is a unit operation. It sets each draft concept and each proposed membership, concept relation, concept mapping and collection of the change set, as it stands at that operation, to accepted. Deprecated, rejected and baseline records do not change.
import type { Vocabulary } from '@kortexya/reasoninglayer';
// Appended to the operations of the create request above.
const policyAndAcceptance: Vocabulary.VocabularyRecordOperation[] = [
{
op: 'upsert',
record: {
kind: 'definition_policy',
scheme: { by: 'client_ref', clientRef: 'mwg' },
definitions: 'required',
},
},
{ op: 'accept_proposals' },
];
// One key per intended change, bound before the call that uses it.
const keys = {
assess: crypto.randomUUID(),
submit: crypto.randomUUID(),
review: crypto.randomUUID(),
approve: crypto.randomUUID(),
};
const assessment = await author.vocabulary.assess(
next.candidateId,
{ revisionId: next.revisionId, contentHash: next.contentHash },
{ idempotencyKey: keys.assess },
);
await author.vocabulary.submit(
next.candidateId,
{ revisionId: next.revisionId, contentHash: next.contentHash },
{ idempotencyKey: keys.submit },
);
const cite = {
revisionId: next.revisionId,
contentHash: next.contentHash,
assessmentId: assessment.assessmentId,
};
await steward.vocabulary.review(
next.candidateId,
{
...cite,
disposition: 'endorse',
// Every review_required finding needs an accepted disposition, with a reason.
findingDispositions: assessment.findings
.filter((finding) => finding.severity === 'review_required')
.map((finding) => ({
findingId: finding.findingId,
disposition: 'accepted',
rationale: 'Kept distinct on purpose',
})),
},
{ idempotencyKey: keys.review },
);
const { decision: approval } = await steward.vocabulary.approve(next.candidateId, cite, {
idempotencyKey: keys.approve,
});

An incomplete assessment (it stopped at a record limit or a deadline) has outcome not_established and admits no approval (409 assessment_incomplete); a blocked one is refused 409 assessment_blocked. A complete assessment whose outcome is not_established (no blocking finding, but a question the engine could not determine, for example) is refused 409 assessment_not_established: the assessment is complete but did not establish its outcome. Read its cq_undetermined findings and the cq detail rows, fix the candidate and assess again.

const releaseKey = crypto.randomUUID();
const { release } = await steward.vocabulary.release(
next.candidateId,
{
revisionId: next.revisionId,
contentHash: next.contentHash,
approvalDecisionId: approval.decisionId,
},
{ idempotencyKey: releaseKey },
);
const active = await steward.vocabulary.active();
const activateKey = crypto.randomUUID();
const activation = await steward.vocabulary.activate(
release.releaseId,
{ expectedActiveReleaseId: active.releaseId, expectedActiveRevision: active.activeRevision },
{ idempotencyKey: activateKey },
);

The activation states the pointer the caller read. If another activation happened in between, it throws 409 active_release_changed and error.current names the new pointer.

Reads use the active release unless you pass a view: { view: 'release', releaseId } for an older release, or { view: 'candidate', revisionId } for a draft (view.draftNotActive is true; show it as “Draft — not active”).

const page = await author.vocabulary.listConcepts({ language: 'en' });
const { concept } = await author.vocabulary.getConcept(conceptId, { language: 'fr-CA' });
if (concept.displayLabel?.fallback) {
// A label in another language, never a translation.
console.log(`fallback from ${concept.displayLabel.language}`, concept.displayLabel.fallbackPath);
}
const hits = await author.vocabulary.search({
q: 'Production',
roles: ['preferred', 'alternative'],
});

A refusal throws VocabularyRefusedError with a closed code. Branch on the code: one status carries several codes.

import {
MutationOutcomeUnconfirmedError,
PreconditionFailedError,
VocabularyRefusedError,
} from '@kortexya/reasoninglayer';
// Bind the key once: every attempt below sends the same request identity.
const approveKey = crypto.randomUUID();
try {
await steward.vocabulary.approve(candidateId, cite, { idempotencyKey: approveKey });
} catch (error) {
if (error instanceof MutationOutcomeUnconfirmedError) {
// The outcome is unknown: never assume nothing was written.
// Read the committed outcome; if nothing committed, repeat with the SAME key.
try {
const outcome = await steward.vocabulary.getRequestOutcome('approve', approveKey);
if (outcome.operation === 'approve') console.log(outcome.body.decision.decisionId);
} catch (missing) {
if (missing instanceof VocabularyRefusedError && missing.code === 'no_committed_outcome') {
await steward.vocabulary.approve(candidateId, cite, { idempotencyKey: approveKey });
} else throw missing;
}
} else if (error instanceof VocabularyRefusedError) {
switch (error.code) {
case 'vocabulary_separation_of_duties': // the actor authored this revision
case 'review_missing': // no standing endorsement
case 'stale_baseline': // rebase first
break;
}
} else if (error instanceof PreconditionFailedError) {
// a stale ifMatch on save or rebase
}
}

getRequestOutcome(operation, key) answers the committed status and body, or throws 404 no_committed_outcome (repeating the identical request is then safe). The body is decoded as the operation’s own typed result: narrow on outcome.operation (create_candidate, save_revision and rebase give a candidate revision; assess an assessment; submit, review, approve, reject and withdraw a decision; release a release; activate an activation). It is the body of the first commit, so body.replayed is false. Read it with the same authenticatedUser that sent the mutation.

Metadata profiles, conformance and crosswalks

Section titled “Metadata profiles, conformance and crosswalks”

The same workflow governs model records: metadata profiles and their layers, elements and uses, vocabulary bindings, source schemas and fields, crosswalks and their rules, formal links to the sort theory, theory changes, competency-question specs and trace links. They are record kinds like a concept, so they travel in a candidate, are assessed (the profiles, crosswalks, formal_links, theory and competency criteria) and are released and activated with it. Read them with listRevisionRecords, listReleaseRecords and lookupRecords; narrow a VocabularyRecordView on kind.

Four run families judge data against the active release. Each run is an immutable stored record, started with an idempotency key.

const key = crypto.randomUUID();
const run = await steward.vocabulary.createConformanceRun(
{
view: { kind: 'active' },
profileId,
layerId,
selection: { kind: 'sort_extent' },
maxTargets: 10_000,
deadlineMs: 60_000,
},
{ idempotencyKey: key },
);
// `conformant` needs a complete run with no violation, undetermined or not-checked finding.
if (run.outcome !== 'conformant') {
const page = await steward.vocabulary.listConformanceFindings(run.runId, { verdict: 'violated' });
for (const finding of page.findings) console.log(finding.code, finding.targetId);
}
  • Outcomes are not booleans. A conformance run is conformant, nonconformant or not_established; a competency-question run is passed, failed or not_established. A single question is passed, failed, undetermined or not_run. A quality report group is not_run, stale, failed, unresolved, incomplete or accepted. Never read an incomplete or unresolved result as success.
  • A stopped run says why. complete: false comes with a stopReason (target_limit or deadline for conformance, source_incomplete or deadline for crosswalks). Page a long run with cursor and limit; a cursor used with another run or filter throws cursor_mismatch.
  • Resume, do not recompute. resumeFrom: previousRunId on createConformanceRun and createCrosswalkRun creates a new run that reuses the committed items of the earlier chain (run.resumption.reusedItems, computedItems, origins). When any component of the binding differs, the engine throws 409 run_resume_mismatch and error.refusal.resumeMismatches lists every differing component with both values. A complete run, or a crosswalk run stopped by source_incomplete, is run_not_resumable. Competency-question runs cannot be resumed.
  • Unknown is not absent. A competency question that compared an uninstantiated stored value reports reason: 'unknown_comparison' and execution.unknownFilterRows; its verdict is undetermined, never a quiet passed.

A crosswalk run transforms uploaded source records (oai_dc_xml or json_records, uploaded with the sources API) into output terms. It goes through review before anything is written, and the reviewer is never the executor of the run or of a run it resumed from:

const active = await steward.vocabulary.active();
const crosswalk = await author.vocabulary.createCrosswalkRun(
{ view: { kind: 'active' }, inputs: [{ crosswalkId, sourceFileId }] },
{ idempotencyKey: crypto.randomUUID() },
);
for (const item of (
await author.vocabulary.listCrosswalkItems(crosswalk.runId, { disposition: 'unresolved' })
).items) {
console.log(
item.disposition,
item.notes.map((note) => note.code),
);
}
const check = await author.vocabulary.createConformanceRun(
{
view: { kind: 'active' },
profileId,
layerId,
selection: { kind: 'crosswalk_run', runId: crosswalk.runId },
},
{ idempotencyKey: crypto.randomUUID() },
);
await author.vocabulary.submitCrosswalkRun(
crosswalk.runId,
{ conformanceRunId: check.runId },
{ idempotencyKey: crypto.randomUUID() },
);
await steward.vocabulary.reviewCrosswalkRun(
crosswalk.runId,
{ disposition: 'endorse', rationale: 'Conformant; unresolved items reviewed.' },
{ idempotencyKey: crypto.randomUUID() },
);
const admission = await steward.vocabulary.admitCrosswalkRun(
crosswalk.runId,
{ expectedActiveReleaseId: active.releaseId },
{ idempotencyKey: crypto.randomUUID() },
);
console.log(admission.written.length, 'terms written');

A source value, a JSON pointer or a note keeps its spelling: the SDK never rewrites a data key. An output of an unresolved, rejected or unavailable item is never written. A refusal carries its detail on error.refusal: crosswalkProblems for crosswalk_invalid, outputRefusals for output_declaration_refused, repeatedInputs for a repeated run input.

One file, one input position. A crosswalk run reads each uploaded file once. A request that names the same sourceFileId at two or more positions of inputs throws 422 invalid_request before anything runs, and error.refusal.repeatedInputs lists each repeated file with all its positions (0-based, ascending):

try {
await author.vocabulary.createCrosswalkRun(
{
view: { kind: 'active' },
inputs: [
{ crosswalkId, sourceFileId: fileA },
{ crosswalkId, sourceFileId: fileB },
{ crosswalkId, sourceFileId: fileA },
],
},
{ idempotencyKey },
);
} catch (error) {
if (error instanceof VocabularyRefusedError) {
console.log(error.refusal.repeatedInputs); // [{ sourceFileId: fileA, positions: [0, 2] }]
}
}

Remove the repeated positions and send the corrected request. The refusal stored nothing, so the same idempotency key still serves it.

Find a run without a link. listCrosswalkRuns, listConformanceRuns and listCqRuns page the tenant’s runs, newest first (creation time, then run id, descending). Filter a crosswalk run by state (previewed, submitted, endorsed, rejected, admitted), complete and resumed; a conformance run by outcome, complete and resumed; a competency-question run by outcome. Each also takes releaseId or revisionId (the release or candidate revision the run read; both together throw 400 invalid_request), cursor and limit (1 to 500, default 50). A page is { runs, nextCursor, complete }; follow nextCursor while it is set. A run on a page is the single-run read without replayed and without the part that has no bound: decisions for a crosswalk run, results for a competency-question run. A conformance run keeps a bounded selection (see below). Read the run (getCrosswalkRun, getCqRun) or its paged reads for those. A cursor is bound to the tenant, the listing and the filters; used with another it throws cursor_mismatch.

Find the conformance runs over a crosswalk run. listConformanceRuns({ crosswalkRunId }) keeps the runs whose selection is the outputs of that crosswalk run; a run over a sort extent or a list of term ids never matches. Each run on a page carries its selection in a bounded form: { kind: 'crosswalk_run', runId }, { kind: 'sort_extent', sortId } or { kind: 'term_ids', count }. A term_ids selection is counted, never listed; read the run with getConformanceRun for its ids. A cursor is bound to the crosswalkRunId too: reuse it with another value, or with none, and it throws cursor_mismatch. A cursor issued by an older engine build also throws cursor_mismatch; list again from the first page.

const page = await steward.vocabulary.listConformanceRuns({ crosswalkRunId: run.runId });
for (const check of page.runs) console.log(check.runId, check.outcome, check.selection);
let page = await steward.vocabulary.listCrosswalkRuns({ state: 'submitted', limit: 50 });
for (;;) {
for (const run of page.runs) console.log(run.runId, run.state, run.createdAt);
if (page.nextCursor === undefined) break;
page = await steward.vocabulary.listCrosswalkRuns({
state: 'submitted',
limit: 50,
cursor: page.nextCursor,
});
}

Competency questions (createCqRun, getCqRun, listCqResults) run the cq_spec records of a suite on a private clone of the tenant’s data and compare each answer with its expected rows. Assessment details (listAssessmentDetails(assessmentId, { kind })) page the theory, formal-target, question and suite rows behind the theory and competency criteria. A row is a union on kind: a cq row has a decoded body: VocabularyCqComparisonReport, the type the CQ run routes answer (body.execution.prove is [{ solutions, complete }], body.execution.chain is [{ iterations, fixpointReached }]); the other kinds keep their JSON object body.

Reads for a profile. getProfile, getProfileDocumentation (Markdown) and exportProfile (Turtle: DCAT-AP and a SHACL Core subset) come from one view; the export manifest lists every statement SHACL Core cannot state as a loss. getQualityReport returns the four quality groups with an explicit state; counts are metrics only. getRecordImpact(recordId, { maxNodes }) walks the references backward and reports complete with a stopReason of node_limit or deadline.

Theory activation. Activating a release whose records carry theory changes publishes the sorts and theory terms in one transaction (activation.materialized.theory). The engine refuses with theory_not_assessed, theory_baseline_stale, theory_statement_refused, theory_publication_mismatch (409) or theory_activation_incomplete (503), and then publishes nothing. While a release governs a sort, every sort write door (the sort routes, OSFQL, RDF ingest, ontology import, bulk creation) refuses a change of its declaration with sort_governed_by_release (409) or vocabulary_unavailable (503); read the code with errorBodyCode(error) (Sorts.SortGovernanceErrorCode) or, for OSFQL, OsfqlError.errorType.

migrationPreview() shows how the tenant’s domain sorts would become governed concepts: classification, proposed labels and definition, and what would not be converted (a sort’s parent is never proposed as a broader link). It is read-only: writes is always 0, and no candidate is created.