RDF backends

The --backend option sets where rudof loads the data and how it queries it. These commands accept it: data, node, query, shacl, shacl-validate, shex-validate and validate. rudof connect also uses it, to select a database engine.

Accepted values

ValueWhat it does
memoryDefault. Parses the input(s) into an in-process OxigraphInMemory graph backed by oxrdf::Graph.
qleverLaunches a local QLever Docker container, builds an on-disk index from the input(s), and serves SPARQL via the container’s HTTP endpoint.
lbugThe connected LadybugDB property graph database (see connect). Accepted, but not functional yet. See below.
endpoint=<URL_OR_NAME>Queries a remote SPARQL endpoint by URL, or by the name of an endpoint registered in the TOML config.

rudof connect uses the same --backend option and values to select a database engine. All commands share one option and one type.

The memory backend (default)

All input files are parsed eagerly into an in-process RDF graph. This is the simplest option and works with local files, remote URLs, and stdin.

rudof data simple.ttl                       # memory is the implicit default
rudof data --backend memory simple.ttl     # same, made explicit

The endpoint backend

Routes all SPARQL queries to an external SPARQL endpoint rather than loading data locally. The endpoint can be given as:

  • a full URL: --backend endpoint=https://query.wikidata.org/sparql
  • a short name registered in the TOML config: --backend endpoint=wikidata
rudof query -q my.sparql --backend endpoint=wikidata
rudof node -n :a --backend endpoint=https://my.sparql.server/sparql

Shortcut: --endpoint / -e

Since the endpoint backend is the most frequently used non-default option, every command that accepts --backend also accepts a dedicated --endpoint <URL_OR_NAME> (short form -e) flag. It is exactly equivalent to --backend endpoint=<URL_OR_NAME> and accepts the same URL-or-named-endpoint values:

rudof query -q my.sparql -e wikidata
rudof node -n :a --endpoint https://my.sparql.server/sparql

--endpoint and --backend are mutually exclusive, passing both is rejected at the command line.

In rudof shell, endpoint <NAME> activates a registered endpoint for the rest of the session, so you do not repeat -e on every line. The name is not case sensitive: wikidata, Wikidata and WikiData are the same endpoint. endpoint FILE.toml registers a new endpoint from a local file. See shell.

Wikidata, DBpedia and UniProt are registered by default. They are defined in rudof_rdf/endpoints/, and rudof registers every file in that folder. To register your own endpoints in rudof.toml, use [rdf.endpoints.<name>] tables. See the configuration reference.

Request rate: --min-request-interval

rudof waits a minimum interval between two requests to the same endpoint, to respect the usage policies of public endpoints. By default, the interval is 1100 ms for a remote host and zero for localhost. The built-in public endpoints keep 1100 ms. For your own endpoint, set a shorter interval with --min-request-interval <MS>. It overrides the configured value for that run. 0 turns off the wait, but rudof still slows down after a 429 Too Many Requests response:

rudof shex-validate -s schema.shex -m shapemap.sm -e https://my.sparql.server/sparql --min-request-interval 0

To make the setting permanent, set min_request_interval_ms per endpoint or under [rdf] in the TOML config (see Request rate limiting).

shex-validate fetches the nodes of the shapemap ahead of validation, up to 20 per SPARQL query. --max-nodes-per-query <N> changes that number (1 disables batching), and --max-concurrent-requests <N> lets up to N of these queries run at once (default 1). See Batching and concurrent requests.

Alternative endpoint access: --strategy (Wikibase instances)

rudof shex-validate has a --strategy sparql|dereference option (default sparql), next to --endpoint/-e. With dereference, rudof does not send SPARQL queries. It fetches the IRI of each node directly over HTTP (GET, Accept: text/turtle, following redirects).

This works because Wikibase instances (Wikidata, MaRDI and others) publish every entity as Linked Data. For example, http://www.wikidata.org/entity/Q80 returns the data of Q80. The response for one entity already has all its statements, qualifiers and references. With SPARQL, the same data needs several requests.

rudof shex-validate -s es:E371 -n wd:Q80 -e wikidata                        # SPARQL (default)
rudof shex-validate -s es:E371 -n wd:Q80 -e wikidata --strategy dereference # HTTP dereferencing

The dereference strategy has these trade-offs:

  • It is faster and puts less load on the SPARQL query service for validation. Each node costs one request, which the cache of the wiki usually serves, instead of the separately limited SPARQL service. But for a referenced entity, rudof sees only its label, not its properties, until it fetches that entity too. Validating a node with many links can still fetch many entities, over plain HTTP.
  • It has no full support for inverse paths (^predicate). A fetched node gives only its outgoing triples, and there is no index of the links that point to a node. Inverse shapes and closed shapes (EXTRA) see only the links from entities that the run already fetched, so their results can be incomplete. For schemas that use them, sparql gives accurate results.
  • It sends no SPARQL. A SPARQL node selector, and the SPARQL parts of query, sparql and node, fail with a clear error. They do not use the query service of the endpoint instead.

The lbug backend (not yet implemented for RDF loading)

rudof can derive a property graph from RDF and copy data into a LadybugDB database (rudof connect, load, ddl). It cannot yet read a property graph back as RDF triples. All commands that load RDF accept --backend lbug, for consistency. But with this value, they fail with a clear error:

$ rudof data --backend lbug
Error: Data error: Data source specification error: the 'lbug' backend cannot supply RDF data yet: ...

A future version will read a LadybugDB graph back as RDF, so that SHACL can validate it like any other backend. Until then, use LadybugDB with rudof connect, load and query --dialect cypher. See the full workflow example.

The qlever backend

The qlever backend loads the data into a local QLever Docker container. QLever builds a compact index on disk once, and then answers SPARQL queries with it. On later runs, the memory use depends on the QLever server cache, not on the size of the dataset. This backend suits large datasets that you query often.

Requirements

  • rudof must be built with the qlever feature:

    cargo install rudof_cli --features qlever
    
  • A running Docker daemon. The first run will pull the adfreiburg/qlever image (~1 GB).

  • Every input must be a file-system path (remote URLs and stdin are not supported for this backend).

  • (Optional, only if you pass compressed dumps) A decompressor binary on $PATH for each compression family you intend to use:

    • bzip2 (.bz2): install lbzip2 (parallel, recommended) or fall back to bzip2 (single-threaded).
    • xz (.xz): xz.
    • gzip (.gz): install pigz (parallel, recommended) or fall back to gzip (single-threaded).

How it works

A QLever run has two phases. It builds the index once, and serves it on each run.

  1. rudof selects the index folder: [rdf.qlever].index_dir from the configuration, or a folder in the platform cache (typically ~/.cache/rudof/qlever/<fingerprint>/). The fingerprint comes from the path, format, graph IRI and compression of each input, so different inputs use different folders.
  2. If the index already exists, rudof skips the build.
  3. rudof connects to Docker and pulls the adfreiburg/qlever image if necessary (about 1 GB on the first run).
  4. A one-shot container builds the index:
    • Turtle, N-Triples and N-Quads files are mounted read-only into the container. rudof does not copy or parse them.
    • Compressed files (.nt.bz2, .ttl.xz and so on) are decompressed on the host and streamed to the container. See Streaming compressed dumps.
    • Other formats (RDF/XML, JSON-LD, TriG, N3) are converted first: TriG and JSON-LD to N-Quads, RDF/XML and N3 to N-Triples.
  5. A long-running container serves the index on a host port (ephemeral, or host_port from the configuration). rudof waits until the SPARQL endpoint answers.
  6. All rudof operations then use SPARQL over HTTP against the container.

The index stays on disk between runs, so the next run with the same inputs starts at step 5. To delete the index at shutdown when the current run created it, set auto_delete_if_created = true in [rdf.qlever].

Streaming compressed dumps

The QLever backend can ingest compressed RDF dumps without ever materialising the decompressed form on disk.

When you pass a compressed file, rudof:

  1. Probes $PATH for a decompressor for that family (preferring parallel implementations).
  2. Spawns it on the host with the compressed file as input.
  3. Pipes its stdout straight into the QLever container’s stdin, where IndexBuilderMain reads it via -f -.

The decompressed data never goes to disk. The decompressor runs on the CPU cores of the host, not of the container. So multi-threaded tools such as lbzip2 and pigz use the full machine.

rudof supports these compression formats. It looks for the decompressors in this order:

ExtensionTries (parallel first)Fallback (single-threaded)
.bz2lbzip2 -dc, lbzcat -dcbzip2 -dc
.xzxz -dc -T0, xzcat -T0(the same tools: -T0 causes no problem for a file that cannot be split)
.gzpigz -dcgzip -dc, zcat

The compressed file must contain a format that QLever reads: .nt, .ttl or .nq. The file name must look like dump.nt.bz2 or data.ttl.xz. rudof rejects other compressed inputs, such as dump.jsonld.bz2, with a clear error. Decompress them, or convert them to a supported format, first.

The commands are the same as for uncompressed files. rudof detects the suffix:

rudof data latest-truthy.nt.bz2 --backend qlever
rudof query -q my.sparql data.nt.xz --backend qlever

On startup, rudof logs which decompressor it picked:

streaming compressed input (bz2) via /usr/bin/lbzip2 (parallel)

Limitations of compressed dumps:

  • One compressed input per index build at most. You can mix one compressed file with any number of uncompressed files in the same run. rudof rejects two compressed inputs in the same build, because the index builder reads only one stream from stdin.
  • Only Turtle, N-Triples and N-Quads inside the compressed file. rudof rejects files such as .jsonld.bz2 or .trig.xz.
  • The decompressor must be on $PATH. If rudof finds no decompressor for the input, the error lists the tools that it tried. Install one of them.

Configuring the QLever backend

QLever-specific settings live in a [rdf.qlever] section of the TOML config file passed via --config-file:

[rdf.qlever]
# Docker image. Defaults: adfreiburg/qlever : commit-a307781.
image_name = "adfreiburg/qlever"
image_tag  = "commit-a307781"

# Where on the host the index lives. If unset, defaults to <XDG_CACHE_HOME>/rudof/qlever/<input-fingerprint>.
# index_dir = "/var/lib/rudof/qlever"

# Index base name (the -i argument to QLever).
index_name = "default"

# Wipe the index on Drop if this run created it. Default: false.
auto_delete_if_created = false

# Pin the host port. If unset, Docker picks an ephemeral one.
# host_port = 7001

# Container-side port the QLever server binds to.
container_port = 7001

# QLever server flags (see IndexBuilderMain -h / ServerMain -h).
memory_max_size           = "5G"  # -m
cache_max_size            = "2G"  # -c
cache_max_size_single_entry = "1G" # -e
# stxxl_memory            = "2G"  # -m on the index builder
# parser_buffer_size      = "10M"
# access_token            = "…"   # -a (for SPARQL UPDATE)
# num_simultaneous_queries = 4    # -j
# default_query_timeout   = "30s" # -s
# no_patterns             = false # -P
# no_pattern_trick        = false # -T
# text                    = false # -t
# only_pso_and_pos_permutations = false # -o
# throw_on_unbound_variables    = false

# Run the container as the host UID/GID so index files end up owned by you
# (Linux only). Default: true.
run_as_host_user = true

# Seconds to wait for the server to answer a SPARQL probe before giving up.
server_readiness_timeout_secs = 60

All [rdf.qlever] fields are optional (an empty [rdf.qlever] section is enough to start QLever with sensible defaults).

Note

rudof reads the [rdf.qlever] section only if it is built with the qlever feature.

Limitations

  • It is read-only. add_triple, remove_triple, add_triples, remove_triples and add_bnode return errors. A staging frame (begin_staging, staging) also fails, because it needs a graph that can change.
  • It accepts only file paths. Remote URLs and stdin are not accepted, and a mix of input types is an error.
  • --data-format pg is rejected: the property-graph format is incompatible with QLever’s indexer.
  • Strict Turtle syntax: QLever’s index builder rejects SPARQL-style prefix declarations (prefix : <…> without @ and without a trailing .) even though oxigraph accepts them. Use Turtle-conformant @prefix : <…> . declarations (or run files through a normalizer) before passing them to --backend qlever.