OriginTrail
  • Get started with OriginTrail
  • OriginTrail Ecosystem — Call for Papers (Coming Soon)
  • Key Concepts
    • Decentralized Knowledge Graph (DKG)
    • DKG key concepts
  • TRAC: DKG utility token
  • Build with DKG
    • Quickstart (test drive the DKG in 5 mins)
      • Quickstart with Node.js
      • Quickstart with Python
    • Querying the DKG
    • DKG Edge Node
      • DKG Edge Node architecture
      • Get started with the Edge Node boilerplate
        • Automated setup with the installer
        • Manual setup
        • Usage example
      • Customize & build with the Edge Node
      • Knowledge Mining and dRAG examples
      • Deploy your Edge Node based project
        • Automated deployment with installer
      • DKG Edge Node inception program
      • DKG Edge Node API documentation
    • DKG Core Node
      • Run a V8 Core Node on testnet
        • Preparation for V8 DKG Core Node deployment
        • V8 DKG Core Node installation
      • Run a V8 Core Node on mainnet
        • Preparation for V8 DKG Core Node deployment
        • V8 DKG Core Node installation
      • How to open up your node for publishing
    • DKG toolkit
      • DKG SDK
        • Development environment setup
        • DKG Javascript SDK (dkg.js)
          • Interact with DKG paranets
          • Knowledge submission & curation
          • Paranet's incentives pool implementation
        • DKG Python SDK (dkg.py)
      • DKG paranets
        • Deploying a DKG paranet
        • Building with DKG paranets
        • Syncing a DKG Paranet
        • Initial Paranet Offerings (IPOs)
          • IPO specification
          • Launching your IPO
          • Paranet's incentives pool
          • IPO voting
      • AI agents
        • ElizaOS DKG agent
        • Custom DKG Python agent
        • Custom DKG JavaScript agent
      • Using the DKG with MCP
    • Ecosystem call for papers
  • DKG under the hood
    • Introduction
    • Delegated staking
      • Step-by-step staking
      • Redelegating stake
  • Random Sampling DKG Proof System
    • Random sampling rollout
    • Random Sampling FAQ
  • DKG Sync
  • Integrated Blockchains
    • Base blockchain
      • Connect to Base
    • Gnosis chain
      • Connect to Gnosis
    • NeuroWeb
    • Teleport instructions - NeuroWeb
    • Bridging to Moonbeam
    • Deployed smart contracts
  • Bounties & rewards
    • General bug bounty
    • Code contributions & V8 bug bounty
  • Whitepapers & RFCs
    • OriginTrail whitepaper
    • OriginTrail RFCs
  • Useful Resources
    • What's new with OriginTrail V8
    • DKG V8 guidebook
      • Protocol updates
      • Feature roadmap
      • How to upgrade to V8?
    • Public nodes
    • Tutorials
    • Test token faucet
    • Development principles
    • Community created resources
    • Linked data & knowledge graphs
    • Available networks, network details and RPCs
    • OT Node Engine implementation details
      • Modules
      • Command Executor
    • Contribution guidelines
      • Guidelines for automated test contributions
    • Explore the OriginTrail ecosystem
Powered by GitBook
On this page
  • Introduction
  • Paranets, Knowledge Collections and Knowledge Assets
  • Understanding DKG Connections
  • Query Examples
  • Fetch All KAs by Publisher on a Specific Day
  • Fetch All KAs by Publisher Key in a Paranet
  • Fetch All KAs by Transaction Hash
  • Generic Query Template
  • Learn More

Was this helpful?

Edit on GitHub
  1. Build with DKG

Querying the DKG

PreviousQuickstart with PythonNextDKG Edge Node

Last updated 1 month ago

Was this helpful?

Introduction

If you're just getting started with querying the OriginTrail Decentralized Knowledge Graph (DKG), don't worry — you're in the right place! We use the SPARQL query language to interact with the DKG. At first, SPARQL might seem confusing (we've all been there), but once you get the hang of it, it's actually much simpler than it looks — and incredibly powerful.

Paranets, Knowledge Collections and Knowledge Assets

Paranets are isolated environments within the DKG where participants can publish and query data privately or publicly. Within a paranet, a Knowledge Collection (KC) groups together multiple Knowledge Assets (KAs). A KC acts as a container that maintains a set of KAs, each of which represents a distinct set of information, assertions, or metadata. You can read more about these concepts .

Relationships:

  • A Paranet contains multiple Knowledge Collections (KCs).

  • Each KC contains multiple Knowledge Assets (KAs).

  • Each KA is stored in its own named graph .

Understanding DKG Connections

Before diving into queries, here’s a quick overview of the most important RDF connections you'll encounter in the DKG:

  • <current:graph> dkg:hasNamedGraph <KaGraph> - This tells us which Knowledge Asset graphs are currently considered valid and active. You’ll use this to filter for the current version of a KA.

  • <metadata:graph> <KcUal> dkg:hasNamedGraph <KaGraph> - This connection links a Knowledge Collection (KC) to one or more Knowledge Assets (KAs). It’s used when looking up KAs via their KC metadata (e.g. publisher, timestamp).

  • <metadata:graph> <KcUal> dkg:hasKnowledgeAsset <KaUAL> - This links the KC to the KA’s Universal Asset Locator (UAL). While it doesn’t point to the named graph directly, it’s important for referencing and versioning KAs.

  • <> dkg:hasNamedGraph <KaGraph> - This is used when querying inside a paranet. The paranet graph stores references to all associated KAs within that scope. You can use it to restrict queries to a specific environment.

KaGraph - did:dkg:hardhat1:31337/0xd5724171c2b7f0aa717a324626050bd05767e2c6/4/1/public

KaUal - did:dkg:hardhat1:31337/0xd5724171c2b7f0aa717a324626050bd05767e2c6/4/1

Query Examples

Fetch All KAs by Publisher on a Specific Day

PREFIX dkg: <https://ontology.origintrail.io/dkg/1.0#>

SELECT ?kaGraph
WHERE {
    GRAPH <metadata:graph> {
        ?kc dkg:publishedBy <did:dkg:publisherKey/0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266> .
        ?kc dkg:publishTime ?publishTime .
        FILTER(STRSTARTS(STR(?publishTime), "2025-04-28"))
        ?kc dkg:hasNamedGraph ?kaGraph .
    }
}

Fetch All KAs by Publisher Key in a Paranet

Paranet in which we are searching for the KAs: did:dkg:hardhat1:31337/0xd5724171c2b7f0aa717a324626050bd05767e2c6/3/1

PREFIX dkg: <https://ontology.origintrail.io/dkg/1.0#>

SELECT ?kaGraph
WHERE {
    GRAPH <did:dkg:hardhat1:31337/0xd5724171c2b7f0aa717a324626050bd05767e2c6/3/1> {
        <did:dkg:hardhat1:31337/0xd5724171c2b7f0aa717a324626050bd05767e2c6/3/1> dkg:hasNamedGraph ?kaGraph .
    }
    GRAPH <metadata:graph> {
        ?kc dkg:hasNamedGraph ?kaGraph ;
            dkg1:publishedBy <did:dkg:publisherKey/0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266> .
    }
}

Fetch All KAs by Transaction Hash

PREFIX dkg: <https://ontology.origintrail.io/dkg/1.0#>

SELECT ?kaGraph
WHERE {
    GRAPH <metadata:graph> {
        ?kc dkg:publishTx "0x028cefe6e1a828508c730aeef498117be8e47935619d057d061c203ae2a30b6f" .
        ?kc dkg:hasNamedGraph ?kaGraph .
    }
}

Generic Query Template

This is the go-to pattern for querying across currently active KAs.

PREFIX schema: <http://schema.org/>
PREFIX dkg: <https://ontology.origintrail.io/dkg/1.0#>

SELECT ?subject ?predicate ?object ?containedGraph
WHERE {
    GRAPH <current:graph> {
        ?g dkg:hasNamedGraph ?containedGraph .
    }
    GRAPH ?containedGraph {
        ?subject ?predicate ?object .
        # Optional: FILTER or specific patterns can go here
    }
}

Learn More

Happy querying! You've got this. 🚀

Want to dive deeper into SPARQL? Check out this awesome guide:.

here
SPARQL 1.1 Query Language Overview