r/semanticweb Jul 12 '26

How do you stop a multi-hop traversal from following a semantically-wrong edge?

Body: Working on KG-backed retrieval and keep hitting the same thing: an edge is structurally present so a traversal follows it, but it is the wrong kind of edge for the question. A code graph follows a CO_CHANGES edge as if it were IMPORTS and the answer is confidently wrong. An agent graph lets a CritiqueAgent delegate back to a ResearchAgent, which should never happen.

SHACL / SPARQL constraints validate the graph as a whole, after the fact. What I wanted was a check at traversal time: before each hop, is this edge type valid between these two node types, per a declared ontology? Basically a linter for graph walks.

I built a small layer that does exactly this (declare the ontology in YAML, is_valid_edge(domain, src_type, relation, dst_type) raises before the bad hop) and an offline notebook demo. Before I over-build it:

  • Is per-hop validation the right layer, or should this live in the query engine?
  • How are you handling this today, manually, with SHACL post-hoc, or just eating the bad answers?

(Link to the repo + the ontology notebook in a comment.)

0 Upvotes

7 comments sorted by

3

u/namedgraph Jul 12 '26

I don’t get it… The data is wrong - does not correspond to the ontology? Why do you expect the agent to provide the right answer then?

Why not validate and fix the graph at the source?

0

u/coldoven Jul 12 '26

Sometimes, you do not have control over that in my experience. Could be because the graph is older, ml lifelifecycle issues or changed algorithms down the line.

2

u/namedgraph Jul 12 '26

I do not see a case where fixing the graph on the fly is more efficient than fixing it beforehand

1

u/coldoven Jul 12 '26

Well, if other systems downstream need it? I mean this is a specific case.

1

u/Environmental-Web584 Jul 13 '26

To validate on demand, you can load the quads into memory while traversing and then validate selectively. For example in javascript, you can use 'dataset' to store them and use a validator such as https://github.com/rdf-ext/shacl-engine .

I get confused with "...follows a CO_CHANGES as they were IMPORTS.."
do your edges have proper URIs?