Skip to content

[FEATURE]: Add RDFLib-based reasoner for knowledge graph inference #58

@larsgeorge-db

Description

@larsgeorge-db

Is there an existing issue for this?

  • I have searched the existing issues

Problem statement

Ontos already uses RDFLib (ConjunctiveGraph) for the knowledge graph: semantic models (RDFS/SKOS/OWL), semantic links, and app entities. There is no reasoning step today. As a result:

  • PII/sensitivity cannot be inferred from semantic links (e.g. if CustomerEmail is PII and AccountEmail is linked to it, we don’t infer AccountEmail as PII).
  • Discovery and search don’t use subclass/subproperty closure (e.g. “all assets of type X” doesn’t include inferred subclasses).
  • Concept picker and hierarchy only follow explicit triples, so broader/narrower and subclass closure are incomplete.
  • SPARQL/MCP queries can’t rely on inferred triples for compliance or discovery.

This limits compliance automation, semantic discovery, and the value of the knowledge graph.

Proposed Solution

Introduce an optional reasoner that runs over the RDFLib graph and makes implicit relationships explicit:

  1. Technology

    • Keep RDFLib as the store and SPARQL engine.
    • Add a reasoner (e.g. owlrl for OWL 2 RL) that runs on the same graph and adds inferred triples (subclass/subproperty closure, sameAs, etc.).
  2. Integration

    • In SemanticModelsManager.rebuild_graph_from_enabled() (and/or after “Refresh knowledge graph”), run the reasoner on the built graph.
    • Either merge inferred triples into the main graph or store them in a dedicated context (e.g. urn:inferred) and have SPARQL/search operate over asserted + inferred.
    • Prefer materializing inferred triples at rebuild/refresh rather than reasoning on every query.
  3. User-visible outcomes

    • Compliance / PII: Infer PII (and similar classifications) from ontology + semantic links; use in compliance checks, “all PII” discovery, and contract validation (e.g. require access control when linked to PII).
    • Discovery & search: Subclass/subproperty and SKOS closure so concept search, hierarchy, and “all assets of type X” are complete.
    • SPARQL/MCP: Queries see inferred triples (e.g. “all assets with PII”, “all concepts under Customer”) without hand-written inference.
    • Contract/schema guidance: When a field is linked to a concept that (after reasoning) is under PII/sensitive, suggest or require access control.
  4. Scope

    • Start with the existing graph (semantic models + semantic links + app entities).
    • Use owlrl for RDFS/OWL 2 RL; add a small post-pass or ontology design for custom rules (e.g. “linked to PII concept ⇒ PII”) if needed.

Additional Context

  • Mentioned in product narrative: “Knowledge Graph Reasoning: Using the semantic model for inference. If 'CustomerEmail' is PII, and 'AccountEmail' is linked to 'CustomerEmail', then 'AccountEmail' is implicitly PII.” (docs/podcast-narrative-ai-knowledge-systems.md).
  • Relevant code: src/backend/src/controller/semantic_models_manager.py (e.g. rebuild_graph_from_enabled, query(), search_ontology_concepts, get_concept_details, get_child_concepts).
  • Backend already depends on rdflib>=7.1.0; no reasoner dependency yet (e.g. owlrl would be new).

Metadata

Metadata

Assignees

No one assigned

    Labels

    feat/ontologyOntology related featurefeatureFeature requests

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions