SPARQL

Relata exposes a SPARQL 1.1 basic SELECT read endpoint (/sparql) that translates queries to SQL over the provenance graph's triples view and executes them through the governed query path. Available since v0.9.

Conformance: SPARQL 1.1 basic SELECT — BGP triple patterns + LIMIT. This is a deliberate subset, not a full SPARQL 1.2 processor. Full SPARQL 1.2 processing requires the sparql-rdf feature flag (spargebra), not yet in workspace dependencies. For the full query surface, use SQL.

Endpoint

MethodPathBody / Query
GET/sparql?query=<url-encoded SPARQL>
POST/sparqlContent-Type: application/sparql-query (body is the query)

Both return JSON.

GET

curl "http://localhost:9090/sparql?query=SELECT%20%3Fs%20%3Fp%20%3Fo%20WHERE%20%7B%20%3Fs%20%3Chttp%3A%2F%2Fwww.w3.org%2Fns%2Fprov%23wasAttributedTo%3E%20%3Fo%20%7D%20LIMIT%2010"

Equivalent unencoded query:

SELECT ?s ?p ?o WHERE {
  ?s <http://www.w3.org/ns/prov#wasAttributedTo> ?o
} LIMIT 10

POST

curl -X POST http://localhost:9090/sparql \
  -H "Content-Type: application/sparql-query" \
  -d "SELECT ?s ?o WHERE { ?s <http://www.w3.org/ns/prov#wasDerivedFrom> ?o } LIMIT 5"

Authentication

Same as /query. When RELATA_BEARER_TOKEN is set, include it:

curl -H "Authorization: Bearer $TOKEN" "http://localhost:9090/sparql?query=..."

Response format

{
  "sparql": "SELECT ?s WHERE { ?s ?p ?o } LIMIT 5",
  "sql": "SELECT * FROM triples LIMIT 5",
  "rows": 2,
  "columns": ["s", "p", "o"],
  "data": [
    {"s": "urn:relata:row:...", "p": "...", "o": "..."}
  ],
  "processing_time_ms": 3
}

The translated SQL is echoed in the sql field, and processing_time_ms follows the Meilisearch/Typesense convention.

Supported subset

The translator (relata_query's SPARQL→SQL translator) covers:

ConstructStatus
SELECT ?vars WHERE { ?s <pred> ?o }Supported
Multiple BGP triple patterns (inner join)Supported
LIMIT nSupported
OPTIONAL400 — use LEFT JOIN in SQL
FILTER400 — add the predicate to SQL WHERE
GRAPH, CONSTRUCT, ASK, DESCRIBE400
ORDER BY, OFFSET, DISTINCT, UNION400 — use SQL equivalents
Federated SERVICE400 — Relata is single-source

RDF / PROV-O predicates

The provenance graph is exposed via the PROV-O vocabulary (http://www.w3.org/ns/prov#):

PredicateMeaning
prov:wasGeneratedByActivity that produced the row
prov:wasDerivedFromPrior assertion the row derives from
prov:wasAttributedToActor (human/agent/system/service) that asserted the row
prov:generatedAtTimesystem_from timestamp

RDF-star reified triples (per-triple provenance) require spargebra and are deferred.

Configuration

None required. /sparql is enabled on every deployment profile (free, server, cluster) when RELATA_PROFILE is set. Auth is mandatory on server/cluster and optional on free, identical to /query.

See also

  • SQL Reference — the full dialect (use this for everything beyond basic SELECT)
  • Provenance — the PROV-O model behind the triples view
  • GraphQL — the other query-language door