← BACK TO INSIGHTS
AI ENGINEERING2026-05-129 min read

Grounding LLMs in Verified Knowledge with Oxigraph

Large language models are fluent but not factual. Here is how an RDF triple store like Oxigraph turns a knowledge graph into a verifiable source of truth an LLM can query — and why that beats trusting the model's memory.


Grounding LLMs in Verified Knowledge with Oxigraph


Large language models are remarkably fluent — and that fluency is exactly the problem. A model will answer a question about your supplier hierarchy, your IT asset topology, or a tax rule in the same confident tone whether it knows the answer or is reconstructing something plausible from statistical patterns. In enterprise settings, plausible is not good enough. We need answers that are verifiable.


This is where a knowledge graph backed by an RDF triple store changes the equation. Instead of asking the model to recall facts from its parameters, we let it query a curated, explicitly modelled source of truth. Here is why Oxigraph is a pragmatic choice for that source of truth, and how the grounding pattern works in practice.


The Limits of Vector RAG


Retrieval-Augmented Generation with vector embeddings is the default grounding technique today, and it earns its place. But embeddings retrieve text that is semantically similar to a query — not text that is true. A vector index has no concept of an entity, a relationship, or a constraint. Ask "which suppliers are owned by Company X and approved for category Y?" and a vector store returns the chunks that read most like the question. It cannot join facts, guarantee that a relationship holds, or confirm that the answer is complete.


Knowledge graphs solve the other half of the problem:


  • Explicit facts. Every statement is a triple — subject, predicate, object — with formal meaning.
  • Relationships are first-class. Ownership, approval, classification and dependency are edges you can traverse and join.
  • Constraints and semantics. Ontologies (RDFS/OWL) and validation (SHACL) let you encode what must be true.
  • Deterministic queries. SPARQL returns precise result sets, not a similarity ranking.

  • The strongest enterprise systems use both: embeddings to find the right entities, and the graph to retrieve verified facts about them.


    Why Oxigraph


    A triple store does not have to be heavyweight infrastructure. Oxigraph is an open-source graph database, written in Rust, that implements the SPARQL 1.1 standard — Query, Update and the HTTP protocol — over the full RDF model, including named graphs and RDF-star.


    What makes it a good fit for an LLM-grounding layer:


  • Standards-compliant. SPARQL 1.1 and RDF 1.1, with no proprietary query dialect to teach the model.
  • Embeddable anywhere. Use it as a Rust crate, a Python package (pyoxigraph), a JavaScript/WASM module, or a standalone HTTP server — the same engine in each.
  • Persistent or in-memory. RocksDB-backed storage for durability, or a pure in-memory store for tests and ephemeral graphs.
  • Self-hosted and lightweight. Your verified data never leaves your environment — which matters when the domain is tax, procurement or IT security.

  • For a proof of concept you can have a queryable graph running inside a Python service in a handful of lines: no cluster, no licence negotiation.


    The Grounding Pattern


    The architecture I keep returning to has five steps.


    1. Model the domain as an ontology

    Define the classes and properties that matter — Supplier, Category, approvedFor, ownedBy. This schema is what makes the data verifiable: it states what kinds of things exist and how they may relate.


    2. Load verified data as triples

    Ingest your authoritative records — from SAP, a CMDB, a contract repository — and materialise them as RDF. This curation step is where trust is established.


    3. Translate the question to SPARQL

    The model's job is not to know the answer. It is to translate a natural-language question into a SPARQL query, guided by the ontology and a few worked examples. Text-to-SPARQL is a far safer use of an LLM than text-to-answer, because the output is checkable before it ever runs.


    4. Execute against Oxigraph

    The query runs against the triple store and returns an exact result set. This step is deterministic: the same query over the same graph always yields the same facts.


    5. Verbalise the result

    The model turns the result set back into prose — but the facts come from the graph, not from the model. Attach the underlying triples as provenance, and every claim becomes traceable.


    from pyoxigraph import Store, RdfFormat
    
    store = Store()
    store.load(input=open("procurement.ttl", "rb"), format=RdfFormat.TURTLE)
    
    # A query the LLM produced from the user's question
    query = """
    PREFIX ex: <https://oesterwitz-consulting.de/ontology#>
    SELECT ?name WHERE {
      ?supplier a ex:Supplier ;
                ex:name ?name ;
                ex:approvedFor ex:IndirectMaterials ;
                ex:ownedBy ex:CompanyX .
    }
    """
    
    for row in store.query(query):
        print(row["name"].value)   # verified facts, not a guess

    The model never asserts that a supplier is approved — it asks the graph, and the graph answers from data you curated.


    Why the Answer Is "Verified"


    Three properties make this trustworthy in a way a raw model response is not:


  • Traceability. Every answer maps to specific triples you can show an auditor — essential in regulated domains.
  • Determinism. SPARQL has no temperature; given the graph, the result is reproducible.
  • Falsifiability. If a fact is not in the graph, the query returns nothing — an honest "no result" instead of a confident fabrication.

  • You can go further and run SHACL validation over the graph, so the data itself is checked against your business rules before any question is asked.


    Guardrails That Matter


    Letting a model generate queries demands discipline:


  • Read-only. Expose SPARQL Query, never Update — Oxigraph lets you separate the two.
  • Validate before executing. A generated query that does not parse should never run; reject it and let the model retry against the schema.
  • Constrain to the ontology. Give the model the class and property vocabulary, and check that generated queries reference only known terms.
  • Budget every query. Apply timeouts and result limits so a pathological query cannot stall the service.

  • From PoC to Production


    In a recent knowledge-graph proof of concept for IT software asset management, this was exactly the pattern: an ontology over the managed systems, an LLM generating SPARQL, and a triple store answering questions about architecture and component relationships that vector search simply could not express. Oxigraph makes that same pattern cheap to stand up — small enough for an afternoon experiment, standards-based enough to grow into a production grounding layer.


    Conclusion


    The interesting question is no longer "can the model answer?" but "can the model prove its answer?" Grounding an LLM in a knowledge graph — with a standards-compliant, self-hostable triple store like Oxigraph underneath — turns generation from an act of recall into an act of retrieval against verified facts. For any enterprise where a wrong answer carries a cost, that is the difference that matters.


    Paul Oesterwitz

    Paul Oesterwitz

    AI & SAP Consultant · PhD Researcher