Skip to content

API Reference parrot.knowledge.ontology.vocabulary.snapshot

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

parrot.knowledge.ontology.vocabulary.snapshot

View source

Read-only SQLite snapshots of one ontology version (FEAT-824).

Alias ClosureFamily

Re-exported from parrot.knowledge.ontology.vocabulary.contracts.ClosureFamily.

Alias ConceptRef

Re-exported from parrot.knowledge.ontology.vocabulary.contracts.ConceptRef.

Class HttpSnapshotSource

SnapshotSource over the vocabulary HTTP routes, using aiohttp.

Parameter Type Default Description
base_url str
headers Mapping[str, str] | None None
session 'aiohttp.ClientSession | None' None

Method HttpSnapshotSource.latest_version

Return version from GET {base}/vocabularies/{id}/version.

latest_version(ontology_id: str) -> int

Parameter Type Default Description
ontology_id str

Returns: int

Raises:

  • aiohttp.ClientError — On transport, HTTP status or malformed-payload errors.

Method HttpSnapshotSource.fetch

Stream GET {base}/vocabularies/{id}/snapshot?version=N to a temp file, then move it into place.

fetch(ontology_id: str, version: int, dest_root: Path) -> Path

Parameter Type Default Description
ontology_id str
version int
dest_root Path

Returns: Path

Method HttpSnapshotSource.close

Close the session only when this source created it.

close() -> None

Alias OntologyContent

Re-exported from parrot.knowledge.ontology.vocabulary.contracts.OntologyContent.

Alias OntologyNotFound

Re-exported from parrot.knowledge.ontology.vocabulary.exceptions.OntologyNotFound.

Alias OntologyStore

Re-exported from parrot.knowledge.ontology.vocabulary.contracts.OntologyStore.

Alias OntologyVersionNotFound

Re-exported from parrot.knowledge.ontology.vocabulary.exceptions.OntologyVersionNotFound.

Alias ParsedConcept

Re-exported from parrot.knowledge.ontology.vocabulary.contracts.ParsedConcept.

Alias ParsedLabel

Re-exported from parrot.knowledge.ontology.vocabulary.contracts.ParsedLabel.

Alias ParsedRelation

Re-exported from parrot.knowledge.ontology.vocabulary.contracts.ParsedRelation.

Alias ParsedStatement

Re-exported from parrot.knowledge.ontology.vocabulary.contracts.ParsedStatement.

Alias Resolution

Re-exported from parrot.knowledge.ontology.vocabulary.contracts.Resolution.

Attribute SNAPSHOT_FORMAT_VERSION

Class SnapshotOntologyStore

Read-only OntologyStore over local snapshot files.

The newest {snapshot_dir}/{ontology_id}/v*.sqlite is the current version. With a source configured the store refreshes once per ontology; when the source is unreachable it keeps serving the newest local file and reports stale=True.

Parameter Type Default Description
snapshot_dir Path | str | None None
source SnapshotSource | None None

Attributes:

Attribute Type Description
backend_name str
TRGM_THRESHOLD float
RRF_K int

Method SnapshotOntologyStore.refresh

Fetch a newer snapshot when reachable; network failure keeps the local file with stale=True.

refresh(ontology_id: str) -> StoreStatus

Parameter Type Default Description
ontology_id str

Returns: StoreStatus

Raises:

  • OntologyNotFound — When no local snapshot exists after the attempt.

Method SnapshotOntologyStore.version

Current snapshot version. Raises OntologyNotFound.

version(ontology_id: str) -> int

Parameter Type Default Description
ontology_id str

Returns: int

Method SnapshotOntologyStore.status

Version, backend name and whether a configured source was unreachable on the last refresh.

status(ontology_id: str) -> StoreStatus

Parameter Type Default Description
ontology_id str

Returns: StoreStatus

Method SnapshotOntologyStore.get

Concept at the snapshot version, or None when the IRI is not in it.

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 SnapshotOntologyStore.resolve

Hybrid lookup (exact, trigram, vector) fused with RRF; deprecated concepts are excluded.

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 SnapshotOntologyStore.expand

Closure of iris at the snapshot 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 SnapshotOntologyStore.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 SnapshotOntologyStore.canonical

Map each IRI to its live replacement (cycle-safe, at most 16 hops); unchanged IRIs are omitted.

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 SnapshotOntologyStore.export

Serialise the asserted graph (inferred relations are not exported) at the snapshot version.

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 SnapshotOntologyStore.close

Close open connections, and the source only when this store created it.

close() -> None

Class SnapshotSource

Where newer snapshots come from.

Method SnapshotSource.latest_version

Return the newest snapshot version the source offers.

latest_version(ontology_id: str) -> int

Parameter Type Default Description
ontology_id str

Returns: int

Method SnapshotSource.fetch

Download one snapshot into dest_root and return its path.

fetch(ontology_id: str, version: int, dest_root: Path) -> Path

Parameter Type Default Description
ontology_id str
version int
dest_root Path

Returns: Path

Alias StoreStatus

Re-exported from parrot.knowledge.ontology.vocabulary.contracts.StoreStatus.

Alias VersionContent

Re-exported from parrot.knowledge.ontology.vocabulary.contracts.VersionContent.

Function build_snapshot

Write the snapshot atomically and return its path.

An existing snapshot is reused only when its checksum matches. The complete replacement database is committed and closed before it is atomically moved into place, so readers never observe a partial transaction.

build_snapshot(content: VersionContent, dest_root: Path) -> Path

Parameter Type Default Description
content VersionContent Fully materialized rows for one published ontology version.
dest_root Path Root directory for ontology snapshot files.

Returns: Path — Path to the completed snapshot.

Raises:

  • ValueError — If the destination exists with a different checksum.

Attribute logger

Alias resolve_ontology_settings

Re-exported from parrot.knowledge.ontology.vocabulary.settings.resolve_ontology_settings.

Function snapshot_path

Return {root}/{ontology_id}/v{version}.sqlite.

snapshot_path(root: Path, ontology_id: str, version: int) -> Path

Parameter Type Default Description
root Path
ontology_id str
version int

Returns: Path

Function trigram_similarity

Return pg_trgm-compatible lower-cased, word-padded set similarity.

trigram_similarity(a: str, b: str) -> float

Parameter Type Default Description
a str
b str

Returns: 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