Why Datalog over RDF
RDFox and oxilite both add Datalog rules to an RDF store, but they make opposite bets: RDFox computes everything up front in memory, while oxi-lite compiles rules into SQL and lets an embedded database do the work.
SPARQL is good at asking questions of a graph and weak at stating what follows from it. Property paths such as :locatedIn+ give you recursion over a regular path. They don’t give you rules that join several patterns, derive new triples, or depend on the absence of a fact. Datalog fills that gap with a small declarative rule language, recursion, and well-defined fixpoint semantics.
RDFox is a commercial, in-memory knowledge graph built around Datalog from day one. It materialises every consequence of the rules and keeps that result current as data changes. oxi-lite is an open-source, embedded RDF store built on Oxigraph and SQLite. Its Datalog layer compiles a whole program into one SQL statement where it can, and iterates the rest to a fixpoint inside SQLite itself.
The difference is not just speed. It decides which problems each system fits, and that is what this article is about.
How RDFox does Datalog: materialise, then maintain
RDFox evaluates every rule eagerly, stores the derived facts next to the asserted ones, and updates that result incrementally on every commit.
Everything is a tuple table. The default graph and named graphs live in the in-memory tuple tables DefaultTriples and Quads (concepts). Data source tuple tables expose CSV files, relational databases or a Solr index as virtual relations, and built-in tables hold well-known facts. A rule atom is a lookup into one of these tables, so a single rule can join default-graph triples, a named graph and an external SQL table.
The rule language is Datalog plus pragmatic extensions. Heads come first, Prolog-style:
[?x, :locatedIn, ?z] :- [?x, :locatedIn, ?y], [?y, :locatedIn, ?z] .
[?x, :contractorFor, ?y] :- [?x, :worksFor, ?y], NOT [?x, :employeeOf, ?y] .
[?d, :avgSalary, ?a] :-
[?d, a, :Department],
AGGREGATE([?x, :worksFor, ?d], [?x, :salary, ?s] ON ?d BIND AVG(?s) AS ?a) .RDFox adds stratified negation, stratified aggregation, built-in functions, BIND, FILTER and SKOLEM for minting IRIs (Datalog basics). Programs where negation or aggregation sits inside a recursive cycle are rejected.
Rules come from three domains. User rules are imported directly. OWL axioms in the OWL 2 RL profile are translated into an axioms rule domain, so OWL reasoning runs on the same engine. An internal domain holds rules RDFox needs for its own configuration (concepts).
Evaluation is parallel seminaïve forward chaining. The engine applies rules to a fixpoint across all cores in shared memory. owl:sameAs is handled by rewriting each equivalence class to one representative instead of copying triples to every alias (Nenov et al.).
Updates are incremental, including deletes. Remove :Paul a :Professor and the derived :Paul a :Person disappears too. The backward/forward family of algorithms checks for alternative derivations instead of over-deleting and rederiving, as classic DRed does. Each fact carries a fact domain recording whether it was asserted or derived.
Queries pay almost nothing. Because consequences are already stored, SPARQL runs over explicit and derived triples together with no rewriting. The cost moves to commit time and RAM: the whole store, including every inferred fact, lives in memory.
How oxi-lite does Datalog: compile to SQL, run anywhere SQLite runs
oxi-lite treats a Datalog program the way it treats a SPARQL query: it checks it, plans it, and compiles it to SQL that any SQLite can run, including Cloudflare D1, Turso and a Durable Object’s embedded database (README, v0.9).
Atoms are RDF. An IRI with two arguments is a predicate and one argument is a class, so ex:parent(?x, ?y) is the triple pattern ?x ex:parent ?y and ex:Person(?x) is ?x rdf:type ex:Person. triple(?s, ?p, ?o) and triple(?s, ?p, ?o, ?g) reach the quad table directly, predicate variable and named graph included.
@prefix ex: <http://example.org/> .
ancestor(?x, ?y) :- ex:parent(?x, ?y).
ancestor(?x, ?z) :- ex:parent(?x, ?y), ancestor(?y, ?z).
adult(?x, ?y) :- ancestor(?x, ?y), ex:age(?y, ?a), ?a >= 18.
orphan(?x) :- ex:Person(?x), not ancestor(_, ?x).
lines(?x, COUNT(?y)) :- ancestor(?x, ?y).
?- adult(?x, ?y).SQLite’s limits become Datalog’s safety conditions. WITH RECURSIVE allows one self-reference per recursive term and none under NOT EXISTS. That is exactly “rules are linear” and “negation is stratified”, so the compiler reports violations as rule diagnostics, naming the cycle or the unsafe variable, before any SQL exists. Mutual recursion compiles into one CTE with a discriminant column.
Linear programs are one statement. A stratified, linear program becomes a single SQL query. On D1 that means one network round trip for a recursive rule set, which matters when every call costs milliseconds and is billed per row.
Non-linear rules are iterated, not rejected. path(?x,?z) :- path(?x,?y), path(?y,?z). has no single-statement form, so oxi-lite iterates it to a fixpoint in a datalog_work table, one request per round. The result reports the rounds taken, max_iterations bounds them, and explain_datalog() flags which components had to iterate.
Query-time by default, materialised on request. A program normally runs as a query and its working rows are discarded. datalog_materialize() writes the derived facts into quads_inf, the same table OWL 2 RL materialisation uses, tagged with the rule set that produced them. SPARQL and Cypher then see them with include_inferred. Materialised inferences are not maintained incrementally: you re-run the rule set after data changes, and only that rule set’s conclusions are replaced.
Rules see the rest of the store. The same program can read a past version (@version "HEAD~1" for the whole program, at "HEAD~1" per atom), the commit history (commit, added, removed), vector indexes on Turso, and host functions registered in Rust.
Where they differ
The core split is when the work happens: RDFox pays at write time so queries are free, while oxi-lite pays at query time unless you ask it to materialise.
Where evaluation runs. RDFox runs its own parallel engine over in-memory indexes. oxi-lite hands SQL to SQLite, with its own statistics-driven planner fixing the join order. The SQLite route is slower per rule, but it runs wherever SQLite runs: a phone, a browser worker, an edge database with no native code.
When results are computed. RDFox materialises everything at commit, so every SPARQL query already sees every consequence. oxi-lite runs a program as a query by default, so results are always current and cost nothing until asked for. datalog_materialize() gives you the RDFox-style trade when a rule set is read far more often than the data changes.
How recursion is evaluated. RDFox handles any recursion inside one engine pass. oxi-lite runs linear and mutually recursive programs as one SQL statement and iterates non-linear components round by round. On a local SQLite a round is cheap; on D1 each round is a network request, so linearising a rule is a real optimisation, not a style choice.
What happens when data changes. RDFox maintains its materialisation incrementally, deletions included. oxi-lite’s query-time results never go stale, but its materialised inferences do: you re-run the rule set, and only that rule set’s conclusions are replaced. In exchange, oxi-lite’s rules can read the past. A program can run against HEAD~1, join the present with a past version, or reason over the commit log itself, which RDFox’s rules don’t do.
Provenance of derived facts. RDFox records whether a fact was asserted or derived. oxi-lite records which producer derived it, OWL 2 RL or a named rule set, so you can recompute one rule set without touching the others.
Equality. RDFox rewrites owl:sameAs classes to a representative inside the engine. oxi-lite’s Datalog compares terms by id, and leaves sameAs to its OWL 2 RL materialisation.
What a rule can reach. RDFox rules can join external CSV, SQL and Solr sources through tuple tables, and OWL 2 RL axioms run on the same engine as user rules. oxi-lite rules can call SPARQL’s functions, Rust host functions and, on Turso, vector indexes, and their output is visible to SPARQL and Cypher over the same quads.
Footprint and licence. RDFox is commercial and closed source, and the whole store, inferences included, must fit in RAM. oxi-lite is MIT or Apache-2.0 and lives in one SQLite file, so it backs up, replicates and ships with the tools you already use for SQLite.
One rule set, two engines
The same access-control rules read almost identically in both systems; what differs is when they run and where the results live.
The rules: a person reports to their manager and, transitively, to that manager’s managers. A manager can see every document owned by someone who reports to them, unless the document is revoked. Each manager also gets a count of everyone below them.
RDFox. Rules derive triples, so ex:reportsTo, ex:canSee and ex:orgSize exist in the store as soon as the rules are loaded.
@prefix ex: <http://example.org/> .
[?x, ex:reportsTo, ?m] :- [?x, ex:manager, ?m] .
[?x, ex:reportsTo, ?n] :- [?x, ex:manager, ?m], [?m, ex:reportsTo, ?n] .
[?m, ex:canSee, ?doc] :-
[?x, ex:reportsTo, ?m], [?doc, ex:owner, ?x],
NOT [?doc, ex:status, ex:Revoked] .
[?m, ex:orgSize, ?n] :-
[?m, a, ex:Manager],
AGGREGATE([?x, ex:reportsTo, ?m] ON ?m BIND COUNT(?x) AS ?n) .An application then asks SELECT ?doc WHERE { ex:alice ex:canSee ?doc } and gets an index lookup. When someone changes manager, RDFox retracts and re-derives only the affected reportsTo and canSee facts.
oxi-lite. The same program, with a goal attached:
@prefix ex: <http://example.org/> .
reportsTo(?x, ?m) :- ex:manager(?x, ?m).
reportsTo(?x, ?n) :- ex:manager(?x, ?m), reportsTo(?m, ?n).
canSee(?m, ?doc) :- reportsTo(?x, ?m), ex:owner(?doc, ?x),
not ex:status(?doc, ex:Revoked).
orgSize(?m, COUNT(?x)) :- ex:Manager(?m), reportsTo(?x, ?m).
?- canSee(ex:alice, ?doc).The recursion is linear, so the goal compiles to one statement shaped roughly like this (illustrative; explain_datalog() prints the real SQL):
WITH RECURSIVE reportsTo(x, m) AS (
SELECT s, o FROM quads WHERE p = :manager AND g = 0
UNION
SELECT q.s, r.m FROM quads q JOIN reportsTo r ON r.x = q.o
WHERE q.p = :manager AND q.g = 0
)
SELECT d.s FROM reportsTo r
JOIN quads d ON d.p = :owner AND d.o = r.x
WHERE r.m = :alice
AND NOT EXISTS (SELECT 1 FROM quads st
WHERE st.s = d.s AND st.p = :status AND st.o = :revoked);Nothing is stored, so a manager change is visible on the next query with no maintenance step. If canSee is read on every request, name the heads with IRIs and call datalog_materialize() to write them into quads_inf; you then re-run the rule set when the org chart changes.
One line oxi-lite adds that RDFox has no equivalent for: prefix the program with @version "HEAD~1" . and the same goal answers “what could Alice see before the last commit?”
When RDFox is the right tool
RDFox fits when one large, shared graph is queried constantly, changes continuously, and must always reflect every rule.
Real-time decisions over a hot graph. Fraud screening, compliance checks or network configuration validation, where thousands of queries a second need answers already derived. Materialisation turns each check into an index lookup.
Streams of small updates, deletions included. Logistics, IoT or trading data where a full recompute per change is too slow and a stale inference is a wrong answer. Incremental maintenance is RDFox’s core strength.
Ontology-heavy reasoning. OWL 2 RL axioms, SWRL and user rules running together, with
owl:sameAsfor entity resolution across merged sources. Equality rewriting keeps that tractable where naïve copying would explode.Large recursive programs. Reachability, dependency and supply-chain analysis over big graphs, including non-linear rules. Parallel in-memory seminaïve evaluation is built for exactly this.
Rules across enterprise sources. Data source tuple tables let rules join a SQL database or CSV files with the graph without an ETL step.
The price is a server with enough RAM for the whole store plus its inferences, and a commercial licence.
When oxi-lite is the right tool
oxi-lite fits when you have many small graphs instead of one big one, when the graph must live next to the application, or when history matters as much as the present.
Agent memory. One graph per agent or per user, in a Durable Object or a local SQLite file. Rules derive relevance, permissions and relationships over that memory, vector search narrows the candidates, and time travel answers “what did the agent know when it made that decision?”
Edge and serverless knowledge graphs. On Cloudflare D1 there is no RAM-resident server to hold a materialisation. A linear rule set that compiles to one statement costs one round trip per query.
Local-first, mobile and embedded apps. The graph and its rules ship inside the app’s existing SQLite file and back up with it. No second database, no daemon.
Audit and regulated domains. Rules can run against any past commit and over the commit log itself. “Who could access this record on 1 September, and who granted it?” is a Datalog program, not a forensic project.
Credentials and trust chains. Verifiable Credentials are stored as named graphs, so recursive rules can walk issuer delegation and accreditation chains across them, and re-evaluate as credentials are added or revoked.
Rules that are read rarely or still being written. Query-time evaluation means no materialisation cost for a rule set someone runs once a week. oxilite studio adds a Datalog debugger and notebooks for developing rules against real data.
The price is throughput on very large graphs, and the fact that materialised rule sets must be re-run after changes instead of being maintained for you.
How to choose
Pick by the shape of your workload, not by benchmark numbers: three questions settle most cases.
- 1.
One big graph or many small ones? A single shared graph with heavy query traffic favours RDFox. Thousands of per-user or per-agent graphs favour oxi-lite, because each one is just a SQLite file.
- 2.
How often do rules get read compared with how often data changes? Read constantly and changed continuously, you want RDFox’s incremental maintenance. Read occasionally, or changed in batches, query-time evaluation or periodic
datalog_materialize()is enough. - 3.
Does the past matter? If you need to ask what was true at an earlier commit, or reason over who changed what, oxi-lite does it in the rule language. With RDFox you would model time yourself.
The two systems agree on the essentials: stratified negation, aggregation, recursion, rules over RDF. They disagree on where reasoning belongs. RDFox makes it a property of the database, always computed and always current. oxi-lite makes it a property of the query, compiled to SQL and carried wherever SQLite already goes. For a centralised enterprise graph, the first is hard to beat. For agents, apps and the edge, the second is the one that fits.
Sources
RDFox documentation: concepts, servers and tuple tables, reasoning
Oxford Semantic Technologies: Datalog Basics and RDFox
Nenov et al., RDFox: A Highly-Scalable RDF Store (ISWC 2015)
oxi-lite: README, v0.9, release 0.4.0 notes
Originally published on Sovereign Agentic AI on Substack.