Expand description
Browser bindings: load a .rete file’s bytes (e.g. from fetch) and query
it entirely in the browser — the same engine the native CLI uses, compiled
to wasm. Results come back as JSON strings.
Structs§
- Graph
- A
.reteopened once and kept resident, so a client (the playground’s cached/in-memory mode) can run many queries on a big file without re-copying the whole buffer into wasm and re-decoding its dictionary on every call. The methods mirror the free functions above but operate on the already-openRete. The few index-free readers (schema_packed,progressive_query,check_schema) stay free functions — they read small ranges from the buffer and are called rarely (once at load / on demand), so a handle buys little. - Quad
Cursor - Query
Rows - A lazy, resumable cursor over the quads of an open
.rete— the engine side offor await (const [s, p, o, g] of graph.dump())in the JS client. - Remote
Graph - A remote
.reteopened once over HTTP range and kept resident in the worker, so repeated queries on the same URL reuse (a) the block cache — any 64 KiB block fetched once is served from memory byBlockCacheReader— and (b) the lazily faulted index tiles + decoded dictionary chunks that live inside the residentRete. The freesparql_urlre-opens the file on every call, so its block cache dies after one query; this handle keeps it. The counting reader stays reachable so the worker can read cumulative bytes/requests and show how little a cache-hit query actually fetched. Worker-only (synchronous range-read XHR).
Constants§
- COHERENCE_
CONSTRUCT - The fixed, selective coherence subgraph for
reason_construct_url(Tier-1). A UNION of constant-predicate branches: each routes to exactly one predicate’s index tiles, so the client faults onlyrdf:type+ the class/ equality T-Box predicates over one warm lazy cache — not the whole graph. - JSON_
SCHEMA_ VERSION - Version of Rete-owned JSON object envelopes exposed by the browser API.
Functions§
- __start
- Module init: route Rust panics to
console.errorwith their message and location. In release wasm a panic otherwise aborts as a bareRuntimeError: unreachablewith no clue where — this turns that into arete-wasm panic: panicked at '…', src/…:lineline in the devtools console, so an intermittent first-query crash (e.g. a parser tripping on a flaky range read) can actually be diagnosed. - build
- Build a complete
.retefile image from RDF text, entirely in the browser. - build_
bytes build_with_card_syntaxfor input held as bytes: any text format (UTF-8, astextwould be) or"jelly", the binary Jelly RDF stream format, which has no text form and so cannot go through the&strbuilders. Same card and quoted-triple rules, same file out. The Jelly reader is the onerete builduses (rete_core::ingest::parse_jelly_bytes); the whole file must be in memory, as every browser build is.- build_
with_ card build, but the file carries a Dataset Card written fromcard_json— the same documentrete build --card-filetakes, validated by the same rules (rete_core::card::validate_curated_card), so a card authored in the browser is one the CLI would also have accepted.- build_
with_ card_ syntax build_with_card, reading Turtle/TriG<< … >>in the named surface — the browser half ofrete build --quoted-triple-syntax, same two values:- build_
with_ derived_ card build_with_card, but the card also carries the auto-derived profile — the half a browser build used to have to do without (#152).- card
- The embedded Dataset Card — the file’s own self-description (title,
description, license, provenance, counts, example queries) as the JSON text
it was written with, or
undefinedwhen the file carries none. Reads the metadata section straight out of the buffer. - card_
and_ build card_and_build_urlfor an image already in memory — no I/O at all.- card_
and_ build_ url - The Dataset Card and the build record of a remote
.rete, in the same budget as the card alone: one header read, then one coalesced range covering both sections — the writer lays the kind-7 build-info immediately after the metadata precisely so this holds (rete_core::range::read_card_and_build_info_ranged, pinned by arete-coretest). Reading the two separately would have made the CARD tier cost three requests instead of two, which is why there is one export rather than a secondbuild_info_url. - card_
url - The embedded Dataset Card of a remote
.rete, in two small range requests: the header, then the metadata section it points at — never the dictionary, index, or pyramid. This is the index-free CARD tier: a client learns what a multi-gigabyte graph is for a few KB.undefinedwhen the file carries no card. Worker-only (synchronous XHR). - check_
schema - Index-free schema coherence (Tier-0) over an in-memory
.rete: read only the header + pyramid-meta (never the dictionary or the triple index) and report schema-level incoherent points (subClassOf cycles, unsatisfiable classes). Errors if the file ships no schema pyramid. - check_
schema_ url - Index-free schema coherence (Tier-0) over a remote
.reteURL. Reads only TWO ranges — the header and the trailing schema block (the header records its length) — never the dictionary, the community summary, or the triple index. So it’s a flat ~1–8 KB at any graph size (8.1 KB of a 48.8 MB file; see docs/BENCHMARK.md), making it the cheap “is the ontology coherent?” gate. Worker-only (synchronous XHR); a failed range fetch is an error, never a false “coherent”. - communities
- Recompute the Louvain community decomposition and report, per community, its
member-subject count and triple count. Powers the “split by community”
strategy view in the playground. JSON:
[{ "community": N, "size": M, "triples": K }, ...], ordered by community id. - file_
layout - The file’s byte layout, for the playground’s byte-map view. JSON:
{ "fileLength": N, "segments": [ { "kind", "label", "offset", "len" } ] }— segments sorted by offset; uncovered bytes are container framing. - file_
len_ url - The true byte length of a remote
.rete, in 1–2 tiny range requests — derived from the file’s own header (the issue-#95 probe: sections are back-to-back and the file ends with the 4-byteRETEfooter), never from the transport’s numbers, which may describe a compressed representation (GitHub Pages HEADs a 71 MB file as its 58 MB gzip) or be hidden from cross-origin JS entirely. This is how a UI can say what “download the whole file” actually costs before committing to it. JSON:{ "schemaVersion": 1, "fileLength": <bytes> }. Worker-only (synchronous XHR in the sync build). - forget_
local_ file - Drop a registration made by
register_local_file. Releases this wasm instance’s reference to theBlob; any open handle over it stops working. - graph_
names - The named-graph IRIs of a dataset, as a JSON array.
- header_
ranges - Parse the fixed-size header and report the byte ranges a progressive
client needs for the overview — the dictionary and the pyramid summary — plus
the (large) index range it can skip, and the metadata (Dataset Card) range.
JSON:
{ "dictOffset","dictLen","pyramidOffset","pyramidLen","indexOffset", "indexLen","metadataOffset","metadataLen" }. The browser fetches bytes0..HEADER_LEN, calls this, then range-fetches only the dict + pyramid — never the index. A host with its own byte reader (Node over a local file, say) can usemetadataOffset/metadataLento read just the card. - heap_
bytes - The wasm linear memory’s current size in bytes — the engine’s high-water
mark, since wasm memory grows but never shrinks. Exposed so a host can
measure the streaming-dump memory claim instead of trusting it: sample it
before and after a full
QuadCursordrain and the growth stays flat however many quads went by, where materializing them all does not. - info
- Header summary as JSON:
{ "quads": N, "terms": N, "pyramidLevels": N }. - memory_
budget_ mb - The memory budget files are opened with, in MiB (0 = no cap): see
set_memory_budget_mb. - prefix_
search - Prefix-search the label index of an embedded
.reteimage: the subjects whose label starts withprefix(case-insensitive), as[{"label":…,"subject":…}], capped atlimit. Answers from the LABEL_INDEX section, else from an older file’s pyramid-meta label block, with no literal scan. Empty array without one. - progressive_
query - Answer a conservative subset of SPARQL exactly from the pyramid summary, without opening the triple index. Unsupported query shapes return an error instead of silently falling back to a full scan.
- progressive_
query_ json - Native-testable implementation for
progressive_query. - pyramid_
tree - The full community pyramid as a tree — the “cluster of clusters” view.
Per dendrogram round (index 0 = finest, last = coarsest), every community
with its member-node count, triple count (triples whose subject belongs to
it), and its parent community at the next-coarser round (
nullat the top). JSON:{ "rounds": N, "levels": [ [ { "id", "nodes", "triples", "parent" } ] ] }. - query
- Run any SPARQL form (SELECT / ASK / CONSTRUCT / DESCRIBE) and serialize the
result for the playground. Returns a JSON string the page parses; a
"kind"field ("select"|"ask"|"construct") tells the UI how to render it. - query_
communities - Evaluate a SELECT with the community-split strategy: every basic graph
pattern is decomposed into subject stars, each star is evaluated per
pyramid community (the members pushed in as a VALUES binding), and the
stars are recombined with global hash joins — so multi-hop joins work and
cross-community solutions survive. FILTER / UNION / OPTIONAL / MINUS
recurse; paths and GRAPH blocks evaluate globally inside the split; GROUP
BY / ORDER BY / LIMIT / DISTINCT run once on the merged rows. Answers are
identical to
query’s. Refused only when nothing in the query can split (no BGP with a variable subject) or for FROM / FROM NAMED. JSON: the SELECT envelope plus"communities": [{ "community", "subjects", "rows" }, …](rows contributed per community across all split stars). - query_
sparql - Run a SPARQL SELECT; returns a JSON array of solution objects
(
{ "var": "value", ... }). - query_
triples - Evaluate a triple pattern;
null/undefinedpositions are wildcards. Returns a JSON array of[subject, predicate, object]triples. - reach
- Multi-source transitive reachability over one relation, run serially
(the browser engine is single-threaded — the native CLI’s
rete reach --parallelfans one task per seed). For each seed, the set of nodes it transitively reaches; withreverse, the set that reaches it (impact analysis). - reach_
url - Multi-source reachability over a remote
.reteURL (lazy HTTP range reads): builds adjacency forpredicateby faulting only that predicate’s tiles, then BFS from each seed. Worker-only (synchronous XHR). - reason
- Run the OWL RL / RDFS reasoner over an in-memory
.reteand report the inferred-triple count plus any incoherent points (logical contradictions).graphselects a named graph; the default graph is used when omitted. This is the complete (Tier-2) check — it materializes the whole graph. Returns thereasoning_jsonenvelope (noremoteblock). - reason_
construct_ url - Selective (Tier-1) coherence check over a remote
.rete: evaluate a CONSTRUCT (touching only the tiles its constant-predicate patterns need), then reason over just that subgraph. PassCOHERENCE_CONSTRUCTfor the standard class/equality coherence slice, or a custom CONSTRUCT to scope the check further. Unlikereason_url(which materializes the whole graph), this fetches only the slice the CONSTRUCT selects. Worker-only (synchronous XHR). - reason_
url - Run the reasoner over a remote
.reteURL — the complete (Tier-2) check. It materializes the whole graph, so this faults in the dataset’s chunks/tiles as it reads (≈ the whole file); usereason_construct_urlfor the cheaper selective check. Worker-only (synchronous XHR). A failed range fetch mid-read is an error, never a silently-incomplete (and thus possibly false “coherent”) result. JSON adds"remote": { fileLength, bytes, requests }. - register_
local_ file - Register a local
File/Blobunder arete-local:…URL, so every*_urlentry point can range-read it. - schema
- The ontology profile (the semantic coarse graph), as JSON:
{ "classes": [["<iri>", count], ...], "relations": [["sClass","pred","oClass", count], ...] }. The “overview first” payload — render it before fetching any detail. - schema_
packed - Read the baked schema pyramid (classes + class-level relations) straight
from the file’s schema block via a slice reader — no triple scan. The
in-memory twin of
schema_url: a cached big graph gets its schema from a few KB of the buffer instead of dumping every triple (seconds on a 150 MB file). Errors when the file carries no schema pyramid, so callers fall back to the scanningschema. - schema_
url - The schema summary (classes + relations) read from the schema pyramid over
HTTP range — a Schema view of a remote graph without downloading it.
Worker-only (synchronous XHR). JSON:
{ "kind":"schema", "classes":[[iri,count]], "relations":[[s,p,o,count]], "remote":{…} }. - set_
memory_ budget_ mb - Set the memory budget of every remote (lazily read) file opened from now
on, in MiB. It caps the caches of decoded dictionary chunks, decoded index
tiles and raw file blocks; what is evicted is read again when a query
touches it, so the budget trades speed for memory and never changes an
answer.
0removes the cap. The default is 1024. - shacl
- Validate a
.retegraph against SHACL Core shapes written in Turtle. - shacl_
construct_ url - Chain a SPARQL subset, then SHACL over it. Evaluates a
CONSTRUCTover the remote.rete(touching only the tiles its patterns need), then validates the resulting subgraph against the Turtleshapes. Whereshacl_urlselects by shape target (validate every Person…), this selects by an explicitCONSTRUCT— “validate just the slice this query carves out, in place”. Worker-only (synchronous XHR). - shacl_
url - Validate a remote
.retegraph (lazy HTTP range reads) against SHACL Core shapes written in Turtle. Validating the default graph routes every lookup as a range read (ReteGraph), so a targeted shape faults only the tiles holding its targets — not the whole graph. A named graph (graph) still materializes (the routed view is default-graph only). Worker-only (sync XHR). - sparql_
url - summary_
overview - Build the coarse-graph overview from a buffer in which only the header,
dictionary, and pyramid-summary ranges are populated — the index region may be
absent (zero-filled), because the summary path provably never reads it (see
the
rangedtest in rete-core). Returns JSON:{ "round", "communities", "predicateTotals": [["<iri>", count], ...] }. This is the “overview first, drill down later” payload, fetched in ~3 ranges. - text_
search - Full-text (word/CONTAINS) search over an embedded
.reteimage: the subjects whose literals contain every word inwords(whole-word, case-insensitive — AND), optionally also a word starting withcontains_prefix, as[{"subject":…}], capped atlimit. Answers from the TEXT_INDEX section. Empty array when the file has none (build --text-index). - validate_
card - Check a curated card document without building anything — so an editor can
report the exact error
rete build --card-filewould report, while the author is still typing. Returns the empty string when the document is valid, otherwise the error message. - why_
triples - Explain why each triple-pattern match is present in the
.retefile. - why_
triples_ json - Native-testable implementation for
why_triples. - why_url
- Triple-pattern provenance over a remote
.reteURL (lazy range reads): which permutation/section/byte-ranges answer the pattern. Worker-only.