Skip to content

RDF

Transactional SQL tables stored as RDF graphs

Connector software
Free and open source
Service credentials
Not needed
Use with an agent

Install the Orchard skill in your project to help your agent find connectors, configure them, and verify SQL results.

npx skills add Query-farm/vgi-skills --skill orchard

Copy this request into your coding agent to get started.

Use https://query.farm/products/orchard/connectors/rdf/index.md to help me query RDF with DuckDB or Haybarn 2.0.1 and VGI protocol 3.4. Ask only for missing details about the result I need or whether I want local execution, self-hosting or Query Farm hosting. Check the connector's actual hosting availability, credentials and input requirements. Read one format of each needed reference and the exact object declarations before writing SQL. Use a released connector, and distinguish a saved example result from anything you actually execute. If you cannot run the query, tell me what remains to verify.

Count RDF statements by graph

Example output · captured
Connector release
v0.3.2
Engine
2.0.1
VGI protocol
3.4.0
SELECT graph, count(*) AS statements
FROM rdf.main.rdf_quads()
GROUP BY graph
ORDER BY graph
Result
graph statements
<urn:vgi:rdf:catalog> 2

Quick start

Choose where to run RDF, then follow the steps below.

The connector runs alongside DuckDB or Haybarn. No Query Farm account is needed.

1. Install the vgi extension

Run this in your SQL client. On DuckDB, keep FROM query_farm on LOAD in later sessions.

setup.sql
SET allow_extension_repositories = 'allowed';

CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
    WITH PREFIX 'https://duckdb-extensions.query.farm';

INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;

2. Attach the connector

Attach with uvx

Needs uv. uvx builds the worker from its release tag on first attach and reuses the cached environment after that.

ATTACH 'rdf' AS rdf (
  TYPE vgi,
  LOCATION 'uvx --from git+https://github.com/Query-farm/[email protected] vgi-rdf-worker'
);

3. Run a query

query.sql
SELECT graph, count(*) AS statements
FROM rdf.main.rdf_quads()
GROUP BY graph
ORDER BY graph
More example queries →
Technical details
Verified connector release
v0.3.2
Engine
2.0.1
VGI protocol
3.4.0
Verified on
December 1, 2026
Release notes on GitHub
Pin a version for production

When running the connector yourself, keep a specific release until you’re ready to upgrade. Replace the ATTACH statement above with this one and follow the same extension and credential setup.

Attach with uvx

Needs uv. uvx builds the worker from its release tag on first attach and reuses the cached environment after that.

ATTACH 'rdf' AS rdf (
  TYPE vgi,
  LOCATION 'uvx --from git+https://github.com/Query-farm/[email protected] vgi-rdf-worker'
);

Overview

Transactional SQL tables stored as RDF in an Oxigraph dataset, so the same data can be queried as ordinary SQL rows or with local SPARQL and graph traversal.

ATTACH options

database
Persistent RDF database directory; empty creates a temporary database.VARCHAR
read_only
Reject every data or schema mutation on this attachment.BOOLEAN

Catalog

Everything rdf exposes once attached — read straight from the worker's released build.

rdf 1 schema
main 6 functions

SQL tables in schema 'main' and RDF inspection tools.

Schema examples (2)
Examples (2)

Count RDF statements by graph

SELECT graph, count(*) AS statements
FROM rdf.main.rdf_quads()
GROUP BY graph
ORDER BY graph;
Result
graph statements
<urn:vgi:rdf:catalog> 2

Return inline SPARQL VALUES as IRI and language-tagged literal terms

SELECT person.value AS person, name.value AS name, name.language AS language
FROM rdf.main.rdf_sparql('SELECT ?person ?name WHERE { VALUES (?person ?name) { (<urn:example:ada> "Ada"@en) (<urn:example:grace> "Grace Hopper"@en) } }')
ORDER BY name;
Table functions
rdf_neighbors (node VARCHAR, direction := VARCHAR, graph_iri := VARCHAR, max_rows := BIGINT, predicate_iri := VARCHAR, timeout_ms := BIGINT) 3 examples

Find outgoing or incoming RDF relationship edges for one node

Positional arguments
node VARCHAR
Starting node as a raw IRI or _:blank-node label.
Named arguments
direction := VARCHAR
Follow outgoing, incoming, or both directions. · default "out"
graph_iri := VARCHAR
Named graph; empty searches all graphs. · default "urn:vgi:rdf:relationships"
max_rows := BIGINT
Maximum returned rows; overflow fails explicitly. · default 10000
predicate_iri := VARCHAR
Relationship predicate IRI; empty accepts every predicate. · default ""
timeout_ms := BIGINT
Execution deadline including subprocess startup. · default 30000
Returns columns
source VARCHAR
Edge subject: raw IRI or _:blank-node label.
predicate VARCHAR
Raw relationship predicate IRI.
target VARCHAR
Edge object: raw IRI or _:blank-node label.
graph VARCHAR
Raw graph IRI or _:blank-node label; NULL for the default graph.
neighbor VARCHAR
Adjacent node relative to the requested starting node.
Examples (3)

An IRI with no stored relationships has no neighbors, so this count is intentionally 0

SELECT count(*) AS edges
FROM rdf.main.rdf_neighbors('urn:example:absent', direction := 'both');
BEGIN;
CREATE TABLE rdf.main.people(id INTEGER PRIMARY KEY, name VARCHAR);
CREATE TABLE rdf.main.orders(id INTEGER PRIMARY KEY, buyer INTEGER REFERENCES rdf.main.people(id));
INSERT INTO rdf.main.people VALUES (1, 'Ada'), (2, 'Grace'), (3, 'Linus');
INSERT INTO rdf.main.orders VALUES (10, 1), (11, 1), (12, 2);
SET VARIABLE ada_iri = (SELECT __rdf_iri FROM rdf.main.rdf_rows('main', 'people') WHERE name = 'Ada');
SELECT count(*) AS referencing_orders FROM rdf.main.rdf_neighbors(getvariable('ada_iri'), direction := 'in');
ROLLBACK;
SELECT count(*) FROM rdf.main.rdf_neighbors('urn:example:absent');
Link
rdf_quads (graph_iri := VARCHAR) 4 examples

Inspect the persisted RDF dataset as subject, predicate, object and graph terms

Named arguments
graph_iri := VARCHAR
Named graph IRI to inspect; empty reads all graphs. · default ""
Returns columns
subject VARCHAR
RDF subject term.
predicate VARCHAR
RDF predicate term.
object VARCHAR
RDF object term with datatype.
graph VARCHAR
Named graph term.
Examples (4)

Count stored RDF statements by named graph

SELECT graph, count(*) AS triples
FROM rdf.main.rdf_quads()
GROUP BY graph
ORDER BY graph;

Count metadata statements by predicate

SELECT predicate, count(*) AS statements
FROM rdf.main.rdf_quads(graph_iri := 'urn:vgi:rdf:catalog')
GROUP BY predicate
ORDER BY predicate;

Count RDF schema resources

SELECT count(*) AS schemas
FROM rdf.main.rdf_quads()
WHERE predicate = '<urn:vgi:rdf:schemaName>';
1 more example
SELECT count(*) AS main_schemas
FROM rdf.main.rdf_quads()
WHERE predicate = '<urn:vgi:rdf:schemaName>' AND object = '"main"';
Link
rdf_reachable (node VARCHAR, direction := VARCHAR, graph_iri := VARCHAR, max_depth := BIGINT, max_rows := BIGINT, predicate_iri := VARCHAR, timeout_ms := BIGINT) 3 examples

Traverse RDF relationships with cycle detection and bounded minimum-depth results

Positional arguments
node VARCHAR
Starting node as a raw IRI or _:blank-node label.
Named arguments
direction := VARCHAR
Follow outgoing, incoming, or both directions. · default "out"
graph_iri := VARCHAR
Named graph; empty searches all graphs. · default "urn:vgi:rdf:relationships"
max_depth := BIGINT
Maximum number of edges to follow, from 1 to 64. · default 8
max_rows := BIGINT
Maximum returned rows; overflow fails explicitly. · default 10000
predicate_iri := VARCHAR
Relationship predicate IRI; empty accepts every predicate. · default ""
timeout_ms := BIGINT
Execution deadline including subprocess startup. · default 30000
Returns columns
node VARCHAR
Reachable node: raw IRI or _:blank-node label.
depth BIGINT
Minimum number of edges from the starting node.
Examples (3)

An IRI with no stored relationships reaches no nodes, so this count is intentionally 0

SELECT count(*) AS nodes
FROM rdf.main.rdf_reachable('urn:example:absent', max_depth := 3);
BEGIN;
CREATE TABLE rdf.main.people(id INTEGER PRIMARY KEY, name VARCHAR);
CREATE TABLE rdf.main.orders(id INTEGER PRIMARY KEY, buyer INTEGER REFERENCES rdf.main.people(id));
INSERT INTO rdf.main.people VALUES (1, 'Ada'), (2, 'Grace'), (3, 'Linus');
INSERT INTO rdf.main.orders VALUES (10, 1), (11, 1), (12, 2);
SET VARIABLE order_10_iri = (SELECT __rdf_iri FROM rdf.main.rdf_rows('main', 'orders') WHERE id = 10);
SELECT depth, count(*) AS nodes FROM rdf.main.rdf_reachable(getvariable('order_10_iri'), direction := 'both', max_depth := 3) GROUP BY depth ORDER BY depth;
ROLLBACK;
SELECT count(*)
FROM rdf.main.rdf_reachable('urn:example:absent', max_depth := 3);
Link
rdf_rows (schema_name VARCHAR, table_name VARCHAR) 3 examples

Read a SQL table with its stable RDF row IRI for graph joins

Arguments
schema_name VARCHAR
Raw SQL schema name.
table_name VARCHAR
Raw SQL table name.
Returns columns
name VARCHAR
Example for a people(name VARCHAR) table; actual names and types come from the selected table.
__rdf_iri VARCHAR
Stable RDF row IRI; underscores are appended if necessary to avoid name collisions.
Returns columns · depends on the arguments
name VARCHAR
Example for a people(name VARCHAR) table; actual names and types come from the selected table.
__rdf_iri VARCHAR
Stable RDF row IRI; underscores are appended if necessary to avoid name collisions.
Examples (3)

Find the RDF row IRI of each person; fails unless a people table with a name column exists, as in the executable examples

SELECT name, __rdf_iri
FROM rdf.main.rdf_rows('main', 'people')
ORDER BY name;
BEGIN;
CREATE TABLE rdf.main.people(id INTEGER PRIMARY KEY, name VARCHAR);
CREATE TABLE rdf.main.orders(id INTEGER PRIMARY KEY, buyer INTEGER REFERENCES rdf.main.people(id));
INSERT INTO rdf.main.people VALUES (1, 'Ada'), (2, 'Grace'), (3, 'Linus');
INSERT INTO rdf.main.orders VALUES (10, 1), (11, 1), (12, 2);
SELECT name, starts_with(__rdf_iri, 'urn:vgi:rdf:table:') AS has_row_iri FROM rdf.main.rdf_rows('main', 'people') ORDER BY name;
ROLLBACK;
BEGIN;
CREATE TABLE rdf.main.people(id INTEGER PRIMARY KEY, name VARCHAR);
CREATE TABLE rdf.main.orders(id INTEGER PRIMARY KEY, buyer INTEGER REFERENCES rdf.main.people(id));
INSERT INTO rdf.main.people VALUES (1, 'Ada'), (2, 'Grace'), (3, 'Linus');
INSERT INTO rdf.main.orders VALUES (10, 1), (11, 1), (12, 2);
SELECT p.name, count(g.source_row) AS incoming_references FROM rdf.main.rdf_rows('main', 'people') AS p LEFT JOIN rdf.main.rdf_sparql('SELECT ?source_row ?target_row WHERE { GRAPH <urn:vgi:rdf:relationships> { ?source_row ?relationship ?target_row } }') AS g ON g.target_row.value = p.__rdf_iri GROUP BY p.name ORDER BY p.name;
ROLLBACK;
Link
rdf_sparql (query VARCHAR, max_rows := BIGINT, timeout_ms := BIGINT, union_default := BOOLEAN) 2 examples

Query RDF with bounded local SPARQL and join the results with SQL tables

Positional arguments
query VARCHAR
Read-only SPARQL query text. Remote federation is disabled.
Named arguments
max_rows := BIGINT
Maximum result rows; exceeding it raises an error. · default 10000
timeout_ms := BIGINT
Wall-clock deadline including query subprocess startup. · default 30000
union_default := BOOLEAN
Use the union of stored graphs as the default graph. · default false
Returns columns
variable STRUCT of 4 fields
Term or NULL.
STRUCT 4 fields
  • kindVARCHAR
  • valueVARCHAR
  • datatypeVARCHAR
  • languageVARCHAR
answer BOOLEAN
Whether the pattern matches.
subject STRUCT of 4 fields
RDF triple subject.
STRUCT 4 fields
  • kindVARCHAR
  • valueVARCHAR
  • datatypeVARCHAR
  • languageVARCHAR
predicate STRUCT of 4 fields
RDF triple predicate.
STRUCT 4 fields
  • kindVARCHAR
  • valueVARCHAR
  • datatypeVARCHAR
  • languageVARCHAR
object STRUCT of 4 fields
RDF triple object.
STRUCT 4 fields
  • kindVARCHAR
  • valueVARCHAR
  • datatypeVARCHAR
  • languageVARCHAR
Returns columns · depends on the arguments
variable STRUCT of 4 fields
Term or NULL.
STRUCT 4 fields
  • kindVARCHAR
  • valueVARCHAR
  • datatypeVARCHAR
  • languageVARCHAR
answer BOOLEAN
Whether the pattern matches.
subject STRUCT of 4 fields
RDF triple subject.
STRUCT 4 fields
  • kindVARCHAR
  • valueVARCHAR
  • datatypeVARCHAR
  • languageVARCHAR
predicate STRUCT of 4 fields
RDF triple predicate.
STRUCT 4 fields
  • kindVARCHAR
  • valueVARCHAR
  • datatypeVARCHAR
  • languageVARCHAR
object STRUCT of 4 fields
RDF triple object.
STRUCT 4 fields
  • kindVARCHAR
  • valueVARCHAR
  • datatypeVARCHAR
  • languageVARCHAR
Examples (2)

Check whether the RDF catalog contains statements

SELECT answer
FROM rdf.main.rdf_sparql('ASK { GRAPH <urn:vgi:rdf:catalog> { ?s ?p ?o } }');

Return inline SPARQL VALUES as IRI and language-tagged literal terms

SELECT person.value AS person, name.value AS name, name.language AS language
FROM rdf.main.rdf_sparql('SELECT ?person ?name WHERE { VALUES (?person ?name) { (<urn:example:ada> "Ada"@en) (<urn:example:grace> "Grace Hopper"@en) } }')
ORDER BY name;
Link
rdf_tables (schema_name := VARCHAR) 5 examples

Discover RDF identifiers for SQL tables, columns and foreign-key relationships

Named arguments
schema_name := VARCHAR
SQL schema to inspect; empty includes all schemas. · default ""
Returns columns
schema_name VARCHAR
SQL schema containing the table.
table_name VARCHAR
SQL table name.
kind VARCHAR
table, column, or foreign_key.
name VARCHAR
Table, column, or constraint name.
iri VARCHAR
Raw RDF resource or predicate IRI.
graph_iri VARCHAR
Graph containing its RDF statements.
target_iri VARCHAR
Foreign-key target table IRI; NULL for other kinds.
Examples (5)

Count mapped tables, columns and foreign keys; a fresh database has none, so this is 0 until you create a table

SELECT count(*) AS mapped_objects FROM rdf.main.rdf_tables();
SELECT count(*) FROM rdf.main.rdf_tables();
BEGIN;
CREATE TABLE rdf.main.people(id INTEGER PRIMARY KEY, name VARCHAR);
CREATE TABLE rdf.main.orders(id INTEGER PRIMARY KEY, buyer INTEGER REFERENCES rdf.main.people(id));
INSERT INTO rdf.main.people VALUES (1, 'Ada'), (2, 'Grace'), (3, 'Linus');
INSERT INTO rdf.main.orders VALUES (10, 1), (11, 1), (12, 2);
SELECT kind, count(*) AS objects FROM rdf.main.rdf_tables() GROUP BY kind ORDER BY kind;
ROLLBACK;
2 more examples
BEGIN;
CREATE TABLE rdf.main.people(id INTEGER PRIMARY KEY, name VARCHAR);
CREATE TABLE rdf.main.orders(id INTEGER PRIMARY KEY, buyer INTEGER REFERENCES rdf.main.people(id));
INSERT INTO rdf.main.people VALUES (1, 'Ada'), (2, 'Grace'), (3, 'Linus');
INSERT INTO rdf.main.orders VALUES (10, 1), (11, 1), (12, 2);
SELECT t.schema_name, t.table_name, count(q.subject) AS statements FROM rdf.main.rdf_tables() AS t LEFT JOIN rdf.main.rdf_quads() AS q ON q.graph = '<' || t.graph_iri || '>' WHERE t.kind = 'table' GROUP BY t.schema_name, t.table_name ORDER BY t.schema_name, t.table_name;
ROLLBACK;
BEGIN;
CREATE TABLE rdf.main.people(id INTEGER PRIMARY KEY, name VARCHAR);
CREATE TABLE rdf.main.orders(id INTEGER PRIMARY KEY, buyer INTEGER REFERENCES rdf.main.people(id));
INSERT INTO rdf.main.people VALUES (1, 'Ada'), (2, 'Grace'), (3, 'Linus');
INSERT INTO rdf.main.orders VALUES (10, 1), (11, 1), (12, 2);
SELECT fk.schema_name, fk.table_name AS referencing_table, target.table_name AS referenced_table, count(q.subject) AS edges FROM rdf.main.rdf_tables() AS fk JOIN rdf.main.rdf_tables() AS target ON target.kind = 'table' AND target.iri = fk.target_iri LEFT JOIN rdf.main.rdf_quads(graph_iri := 'urn:vgi:rdf:relationships') AS q ON q.predicate = '<' || fk.iri || '>' WHERE fk.kind = 'foreign_key' GROUP BY fk.schema_name, fk.table_name, target.table_name ORDER BY fk.schema_name, referencing_table, referenced_table;
ROLLBACK;
Link

Try these queries

Return inline SPARQL VALUES as IRI and language-tagged literal terms

SELECT person.value AS person, name.value AS name, name.language AS language
FROM rdf.main.rdf_sparql('SELECT ?person ?name WHERE { VALUES (?person ?name) { (<urn:example:ada> "Ada"@en) (<urn:example:grace> "Grace Hopper"@en) } }')
ORDER BY name

Uses rdf_sparql

Count mapped tables, columns and foreign keys; a fresh database has none, so this is 0 until you create a table

SELECT count(*) AS mapped_objects FROM rdf.main.rdf_tables()

Uses rdf_tables

An IRI with no stored relationships reaches no nodes, so this count is intentionally 0

SELECT count(*) AS nodes
FROM rdf.main.rdf_reachable('urn:example:absent', max_depth := 3)

Uses rdf_reachable

Count nodes by distance from order 10: its buyer Ada at depth 1 and Ada's other order at depth 2; uses a sample of people (Ada, Grace, Linus) and orders 10 and 11 bought by Ada and 12 by Grace, rolled back after

BEGIN;
CREATE TABLE rdf.main.people(id INTEGER PRIMARY KEY, name VARCHAR);
CREATE TABLE rdf.main.orders(id INTEGER PRIMARY KEY, buyer INTEGER REFERENCES rdf.main.people(id));
INSERT INTO rdf.main.people VALUES (1, 'Ada'), (2, 'Grace'), (3, 'Linus');
INSERT INTO rdf.main.orders VALUES (10, 1), (11, 1), (12, 2);
SET VARIABLE order_10_iri = (SELECT __rdf_iri FROM rdf.main.rdf_rows('main', 'orders') WHERE id = 10);
SELECT depth, count(*) AS nodes FROM rdf.main.rdf_reachable(getvariable('order_10_iri'), direction := 'both', max_depth := 3) GROUP BY depth ORDER BY depth;
ROLLBACK;

Uses rdf_rowsrdf_reachable

Count stored RDF statements by named graph

SELECT graph, count(*) AS triples
FROM rdf.main.rdf_quads()
GROUP BY graph
ORDER BY graph

Uses rdf_quads

An IRI with no stored relationships has no neighbors, so this count is intentionally 0

SELECT count(*) AS edges
FROM rdf.main.rdf_neighbors('urn:example:absent', direction := 'both')

Uses rdf_neighbors

14 more examples in the Catalog, each listed under the table or function it uses.

Questions it can answer

Plain-English questions from the worker's agent test tasks. An AI agent with this catalog attached should answer each one with SQL.

  • Use rdf_sparql to ASK whether urn:vgi:rdf:catalog contains statements. Return answer.
  • Count the SQL-to-RDF mappings returned by rdf_tables. Return one count.
  • Count outgoing edges from urn:example:absent with rdf_neighbors. Return one count.
  • Count nodes reachable from urn:example:absent within three edges using rdf_reachable.
  • Create rdf.main.agent_people(name VARCHAR), insert Ada, then use rdf_rows to return name and whether its __rdf_iri starts with urn:vgi:rdf:table:.

RDF is an independent open-source connector from Query.Farm. It is not affiliated with, endorsed by or sponsored by the services, projects or organisations it works with. Product names, logos and trademarks belong to their respective owners.