Skip to content

API Reference parrot.knowledge.ontology.vocabulary.contracts

github-actions[bot] edited this page Dec 2, 2026 · 2 revisions

parrot.knowledge.ontology.vocabulary.contracts

View source

Data models and read/write contracts of the ontology vocabulary store (FEAT-824).

Pure types: no driver imports, so importing this module is cheap and the models are picklable.

Attribute ClosureFamily

Class ClosureRow

One transitive-closure relation.

Fields:

Field Type Default Description
family ClosureFamily
ancestor_iri str
descendant_iri str
depth int

Attribute ConceptKind

Class ConceptRef

A concept as read at one published version.

Fields:

Field Type Default Description
iri str
ontology_id str
kind ConceptKind
pref_label str | None None
definition str | None None
deprecated bool False
replaced_by str | None None
version int

Attribute EmbedFn

Attribute LabelKind

Class OntologyContent

Parsed ontology content ready for a version publication.

Fields:

Field Type Default Description
base_iri str
concepts list[ParsedConcept]
labels list[ParsedLabel]
relations list[ParsedRelation]
statements list[ParsedStatement]

Class OntologyPublisher

Write contract; implemented only by the PostgreSQL backend.

Method OntologyPublisher.ensure_ontology

Register an ontology when it is not already present.

ensure_ontology(ontology_id: str, *, base_iri: str, title: str | None = None) -> None

Parameter Type Default Description
ontology_id str
base_iri str
title str | None None

Method OntologyPublisher.publish

Parse and publish Turtle content.

publish(ontology_id: str, turtle: bytes, *, notes: str = '', shapes: bytes | None = None) -> PublishResult

Parameter Type Default Description
ontology_id str
turtle bytes
notes str ''
shapes bytes | None None

Returns: PublishResult

Method OntologyPublisher.publish_content

Publish already parsed ontology content.

publish_content(ontology_id: str, content: OntologyContent, *, notes: str = '', carry_forward_missing: bool = False) -> PublishResult

Parameter Type Default Description
ontology_id str
content OntologyContent
notes str ''
carry_forward_missing bool False

Returns: PublishResult

Class OntologyStore

Read contract of the ontology vocabulary. Every call reads one published version.

Method OntologyStore.version

Current published version; 0 when registered but never published. Raises OntologyNotFound.

version(ontology_id: str) -> int

Parameter Type Default Description
ontology_id str

Returns: int

Method OntologyStore.status

Version, backend name and whether the data may be behind the central store.

status(ontology_id: str) -> StoreStatus

Parameter Type Default Description
ontology_id str

Returns: StoreStatus

Method OntologyStore.get

Concept visible at as_of (default: current). None when the IRI is not visible.

Raises OntologyVersionNotFound.

get(ontology_id: str, iri: str, *, as_of: int | None = None) -> ConceptRef | None

Parameter Type Default Description
ontology_id str
iri str
as_of int | None None

Returns: ConceptRef | None

Method OntologyStore.resolve

Hybrid lookup at the current version with at most k live results.

resolve(ontology_id: str, term: str, *, lang: str | None = None, k: int = 10, kinds: Sequence[str] | None = None, embedding: Sequence[float] | None = None) -> list[Resolution]

Parameter Type Default Description
ontology_id str
term str
lang str | None None
k int 10
kinds Sequence[str] | None None
embedding Sequence[float] | None None

Returns: list[Resolution]

Method OntologyStore.expand

Closure of iris at one version; it always contains the input IRIs.

expand(ontology_id: str, iris: Sequence[str], *, family: ClosureFamily = 'subclass', direction: Literal['down', 'up', 'both'] = 'down', max_depth: int | None = None, include_deprecated: bool = False, as_of: int | None = None) -> set[str]

Parameter Type Default Description
ontology_id str
iris Sequence[str]
family ClosureFamily 'subclass'
direction Literal['down', 'up', 'both'] 'down'
max_depth int | None None
include_deprecated bool False
as_of int | None None

Returns: set[str]

Method OntologyStore.neighbors

Outbound asserted and inferred (predicate, object_iri) pairs.

neighbors(ontology_id: str, iri: str, predicate: str | None = None, *, as_of: int | None = None) -> list[tuple[str, str]]

Parameter Type Default Description
ontology_id str
iri str
predicate str | None None
as_of int | None None

Returns: list[tuple[str, str]]

Method OntologyStore.canonical

Map each IRI to its live replacement, following replacements safely.

canonical(ontology_id: str, iris: Sequence[str]) -> dict[str, str]

Parameter Type Default Description
ontology_id str
iris Sequence[str]

Returns: dict[str, str]

Method OntologyStore.export

Serialise the asserted graph visible at as_of.

export(ontology_id: str, fmt: Literal['turtle', 'jsonld'] = 'turtle', *, as_of: int | None = None) -> bytes

Parameter Type Default Description
ontology_id str
fmt Literal['turtle', 'jsonld'] 'turtle'
as_of int | None None

Returns: bytes

Method OntologyStore.close

Release connections and file handles.

close() -> None

Class ParsedConcept

A parsed concept awaiting publication.

Fields:

Field Type Default Description
iri str
kind ConceptKind
pref_label str | None None
definition str | None None
deprecated bool False
replaced_by str | None None
extra dict[str, Any]

Class ParsedLabel

A parsed label for a concept.

Fields:

Field Type Default Description
iri str
lang str
kind LabelKind
text str

Class ParsedRelation

A parsed asserted or inferred relation.

Fields:

Field Type Default Description
subject_iri str
predicate str
object_iri str
inferred bool False

Class ParsedStatement

A parsed RDF-like statement.

Fields:

Field Type Default Description
subject_iri str
predicate str
object dict[str, Any]

Class PublishDiff

Changes made by a publication.

Fields:

Field Type Default Description
added_iris list[str]
changed_iris list[str]
deprecated dict[str, str | None]
relations_added int 0
relations_closed int 0

Class PublishResult

The immutable result of a publication attempt.

Fields:

Field Type Default Description
ontology_id str
version int
changed bool
checksum str
diff PublishDiff

Class Resolution

A scored concept match from hybrid vocabulary lookup.

Fields:

Field Type Default Description
concept ConceptRef
score float
matched_by Literal['exact', 'trgm', 'vector']

Class StoreStatus

Published-version and backend health information.

Fields:

Field Type Default Description
ontology_id str
version int
stale bool False
backend str

Class ValidationIssue

One reason an ontology publication was rejected.

Fields:

Field Type Default Description
code str
message str
subject str | None None

Class VersionContent

The complete materialized content of a published ontology version.

Fields:

Field Type Default Description
ontology_id str
version int
checksum str
content OntologyContent
closure list[ClosureRow]
embeddings dict[str, list[float]]

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally