/rete-graph:rete-local-queryfrom rete — cloud-native RDF graphs
Explains how to query local .rete files efficiently using lazy range-reads, avoiding full file loads. Covers tuning knobs (RETE_BLOCK_KB, RETE_LOCAL_LAZY_ABOVE_MB, block-cache cap), cost preview commands (rete cost / rete why), and memory limits at billion-triple scale. Use when local queries are slow or OOM.
Ships in rete — cloud-native RDF graphs. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
.rete file (the lazy range-read path)rete-sparql is about writing a correct query. This skill is about executing
it against a local file efficiently: opening a multi-GB .rete without reading
it whole, knowing which commands are lazy, the knobs that govern I/O and memory, how
to preview a query's cost, and — importantly — the memory limits that still bite at
billion-triple scale.
A .rete is three things (see the format-internals notes):
rete build --permutations 3 carries only SPO/POS/OSP, which route every pattern
identically — rete info / rete stats report which set a file has;So answering a query = resolve the bound terms to ids (a few dictionary lookups) → read the matching slice of one permutation → map result ids back to strings (a few more dictionary lookups). Each of those is a small, addressable byte range. Lazy open reads exactly those ranges on demand through a positional file handle + a bounded block cache, instead of reading the whole file and decoding the whole dictionary up front.
MemAvailable and the cgroup limit's
headroom, so a container's --memory counts), never past 1 GiB, and for sparql at
most 1/4 of --memory-budget-mb; 256 MiB where memory cannot be read (macOS,
Windows). Reading whole costs 3–7x the file and is faster only when the whole graph
will be touched anyway. (Before 0.4.0 the rule was a fixed 1 GiB, which read a
1.07 GB file whole inside a 4 GiB container and got it killed.)
RETE_OPEN_DEBUG=1 prints which way each open went and why.query, bgp, sparql, cypher, why, stats,
search, graphs, summary, predicates, schema, export, reach, shacl,
communities, federate, reason, serve.info and card were the last read-whole commands — fixed in PR #97 (they
now cost two small range reads, ~1 s on a 52 GB file under a 1 GiB cap). On a
binary older than #97 they still slurp the file — don't run them on >10 GB there.FROM <g>: a single-graph FROM borrows the graph's index (no copy, PR #97);
a multi-graph FROM still merges all triples into a temporary index — the
one remaining whole-graph materialization.| var | default | what it does |
|---|---|---|
RETE_LOCAL_LAZY_ABOVE_MB | memory-aware (see above) | file-size threshold to switch to the lazy path, overriding the memory-aware rule. 0 forces lazy for everything; raise it to force read-whole (faster for a full scan you'll consume entirely, if the RAM is there). |
RETE_BLOCK_KB | 64 (auto 128 for files >100 MB) | the range-read block size — the KB fetched per cache miss. The reader coalesces byte-adjacent blocks into one request, so a selective query only pays for the handful of scattered blocks it touches. Keep it near the 64 KiB dictionary-chunk size: bigger blocks over-fetch on scattered faults, smaller blocks add round-trips. |
RETE_QUERY_BUDGET_MB | half the available memory, 256–4096 | the query memory budget when --memory-budget-mb is not given: caps the dictionary-chunk, tile and block caches of a lazy open, in the CLI and every client (0 = unlimited). Since 0.4.2 the default follows the memory (a 4 GiB container gets ~2 GiB, not a fixed 4096). RETE_OPEN_DEBUG=1 prints the figure chosen and why. |
RETE_DICT_RESTART_INTERVAL | build-time | dictionary front-coding restart interval — sets how big the in-memory restart-offset table is (a 50 M-term section's table is ~24 MiB). Larger interval → smaller table, slower term seeks. Set at build, not at query time. |
Not env-configurable: the block cache is capped at 256 MiB resident
(DEFAULT_CACHE_CAP). Old blocks evict, so cache RAM never grows unbounded no matter
how long you keep querying an open file (e.g. rete serve).
rete cost <file> "<sparql>" prints the range-read byte
cost (add --explain for the per-pattern breakdown, --json for machine output).
Use it to decide whether a query is a KB lookup or a GB scan before you pay for it.rete why <file> S P O (with ? for variables) prints which
permutation answered it and the exact byte ranges read. This is how you confirm a
query touched KB, not GB.rete cost web/mydata.rete "SELECT ?o WHERE { <https://ex.org/s> <https://ex.org/p> ?o }"
rete why web/mydata.rete "https://ex.org/s" "?" "?" # ranges actually read
Lazy open fixes the file-load OOM. A huge file / huge dictionary is never
slurped. Validated: a 23.5 GB WikiArt .rete whose dictionary is 23.4 GB of embedded
images went from Cannot allocate memory (wanted ~55 GB) to a 1.8 s point query.
It does not make every query low-RAM. Two things still scale with the data, not the file, so they can use many GB regardless of lazy file access:
predicates, summary, stats, schema load the
summary; on a billion-triple graph that is several GB.COUNT/GROUP BY over a class with hundreds of millions of instances
grows RAM ∝ matches.Proven at scale —
datacite.rete(52 GB, 9.83 B triples, 1.885 B terms), under hard Docker memory caps:LIMIT 1point query → 6 s @ 2 GB;COUNTof a class → 779,399 in 4 s @ 2 GB;GROUP BY ?typeover the full 1.38 B-row type slice → 30 groups in 131 s @ 4 GB (~10.5 M rows/s). Aggregation streams (PR #96); the lazy open reads only directories. Blocking ops (ORDER BY,DISTINCT) still materialize their input — those are the remaining GB-scale risks on huge results.
THE diagnostic that matters — "every query OOMs at any cap": if OOM wall-time scales linearly with the memory cap at a constant ~130–180 MB/s (8 GB→44 s, 16 GB→103 s, 40 GB→301 s…), the binary is reading the whole file — the lazy routing is not active. It is NOT the query, NOT the graph size, NOT "the engine can't do it". Check
strings target/release/rete | grep -c RETE_LOCAL_LAZY_ABOVE_MB(0 = a binary/branch without the lazy-local routing, e.g. a stale checkout from main's broken window before c5944de3, or a botched merge). Rebuild from a tree that has it — and remember cargo can serve a stale binary after 9p-mounted edits:touchthe sources and re-verify withstringsbefore trusting any measurement.
Rule of thumb
| query shape | bytes read | resident RAM |
|---|---|---|
| point lookup (bound S, few results) | hundreds of KB | small |
| selective join, small output | KB–MB | modest |
COUNT / GROUP BY (streaming aggregation) | the matching slice | O(#groups) — proven 4 GB for 1.38 B rows |
ORDER BY with LIMIT | the matching slice | O(offset+limit) — top-k bounded upstream |
DISTINCT | the matching slice | O(distinct rows) seen-set — streams |
plain ORDER BY (no LIMIT) / huge SELECT * / multi-graph FROM | the whole slice | materialized — the remaining risks |
Run under a hard cgroup cap — completes = bounded within N; exit code 137 = OOM:
docker run --rm --memory=8g --memory-swap=8g -v "$PWD:/work" -w //work rete-dev:latest \
//work/target/release/rete sparql //work/web/mydata.rete "<query>"
# or: bash skills/rete-local-query/scripts/memcap_query.sh web/mydata.rete "<query>" 8g
--memory-swap equal to --memory disables swap, so you measure a true RAM bound.
MSYS_NO_PATHCONV=1, mount -v "D:/pro/rete:/work",
workdir -w //work, binary //work/target/release/rete.0x05. Files built pre-1.0
(0x04) error with "unsupported .rete format" — rebuild from RDF with rete build.The -url commands (sparql-url, query-url, why-url, summary-url, card-url)
range-read the file over HTTP — including the dictionary index — so a huge graph
served from R2/HTTP can have a lower memory floor than the same file opened locally.
If a local query on a ~billion-term file is RAM-bound, try it over HTTP:
rete sparql-url https://data.graphplaza.com/<ds>/<ds>.rete "<query>"
.rete files.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
rete, lazy-loading, query-optimization, memory-management, rdf
npx claudepluginhub caviri/rete --plugin rete-graph7 skills in this plugin
/dataset-downloadAcquire and organize a NEW raw dataset under ./data/<name>/ before it becomes a .rete — investigate a source (download page, API, S3/Tigris bucket) to find ALL of its data, scaffold the standard folder layout (raw/ + scripts/ + README + checksums), download robustly (reproducible + resumable + parallel), follow manifest→asset links (nested-JSON URLs, .cif/.png/etc.), and document the schema. Use whenever the task is "download this dataset", "grab all the data from <site>", or "get <source> into ./data" — the step that feeds the rete-from-graph skill./rete-catalogFind, inspect, and open the published .rete datasets from the rete catalog — 60+ public knowledge graphs on range-readable hosting. Use when a task needs an existing dataset (query it, download it, federate it, wire it into an app) rather than building a new one./rete-clientsSet up a rete client in a NEW project — Python, Pyodide/JupyterLite, JavaScript/Node, browser script-tag, your own wasm build, or Rust. Use when wiring .rete querying into an application, notebook, or script; covers install, a verified first query, and the per-runtime gotchas./rete-from-graphBuild a queryable `.rete` file from ANY graph-based data source — an RDF dump (.nt/.nq/.ttl/.rdf/.owl), a SPARQL endpoint, a Wikibase, an OWL ontology, GeoJSON, tabular/CSV, a GBIF Darwin-Core archive, a TEI corpus, or a JSON API. Use whenever the task is "turn this dataset/graph/ontology/endpoint into a .rete" (then hand off to the rete-publish skill to register it in the playground). Covers source→N-Triples conversion, the `rete build` flags, the Docker-only build, and verification./rete-publishPublish a built `.rete` dataset to the rete playground: generate optional Parquet/DuckDB/SQLite companions, upload files to Cloudflare R2, register the dataset in the catalog, and verify the public Range/CORS contract. Use after rete-from-graph has produced and verified a `.rete` whenever the task is to make a dataset explorable in the playground./rete-sparqlWrite correct SPARQL for .rete graphs — the supported SPARQL 1.1 surface, rete's extensions (OWL 2 QL reasoning, RDF-star, SERVICE federation, text index), result formats, and the recurring gotchas that silently return 0 rows. Use whenever authoring or debugging a SPARQL query against a .rete file, the playground, the Space API, or any client.Other plugins' skills for the same job