🕸 Knowledge Graph Query Explainability Path Visualizer
This tool visualizes the explainability path of queries in a knowledge graph, providing insights into how and why certain results are returned based on the structure and content of the graph.
Query Input & Semantic Anchoring
Modern knowledge graphs (KGs) — Neo4j property graphs, RDF triple stores, biomedical graphs like Hetionet — store millions of entities and relationships. When a user asks "why is Drug X linked to Disease Y?", the explainability pipeline must first resolve both entities to graph nodes and compile the intent into an executable Cypher or SPARQL query before any path search can begin.
- 2–50M: Typical KG node count (entities per production graph)
- 94.2%: Entity resolution accuracy (BioBERT-based linking)
- 8 ms: Avg. query compile time (NL → Cypher/SPARQL)
- 2: Supported query languages (Cypher (LPG), SPARQL (RDF))
From natural language to a graph query
The pipeline begins with intent parsing: a named-entity recognition (NER) model, often a fine-tuned BioBERT or SciSpaCy variant for biomedical graphs, extracts the two candidate entities from the user's question and links them to canonical node identifiers (e.g., DrugBank ID, MeSH concept). This entity-linking step is critical — ambiguous surface forms ("aspirin" mapping to multiple salt forms or trade names) must resolve to a single anchor node or the downstream path search will silently explore the wrong subgraph.
Once both endpoints are resolved, the question intent ("why is X linked to Y?") is translated into a parameterized graph query. For property graphs stored in Neo4j, this typically compiles to a variable-length path pattern in Cypher:
MATCH p = (a:Drug {id:$x})-[*1..4]-(b:Disease {id:$y}) RETURN p
For RDF-backed graphs, the analogous SPARQL property-path expression uses the "*" or bounded "{1,4}" quantifier over predicate chains. Both formulations defer the actual path enumeration to the next stage — this stage only establishes the start node, end node, and search bounds (max hop count, relationship-type whitelist).
Bounding the traversal depth is not cosmetic — an unbounded variable-length Cypher match on a graph with average node degree 40 can enumerate over 10⁸ paths beyond 6 hops, making the query computationally intractable without a hop limit.
Why explainability matters for graph query answers
A raw KG query engine can return a boolean or a ranked list of answers, but in high-stakes domains — drug repurposing, fraud detection, clinical decision support — a bare answer is insufficient. Regulatory frameworks (EU AI Act, FDA guidance on AI/ML-based software) increasingly require that automated inferences be accompanied by a traceable rationale, not just a confidence score.
Explainable AI (XAI) in biomedicine has converged on path-based explanation as the dominant paradigm for graph-structured data, because a path of typed edges (e.g., Drug –TARGETS→ Protein –ASSOCIATED_WITH→ Disease) mirrors how domain experts already reason about mechanism. This is in contrast to post-hoc saliency methods (LIME, SHAP) originally designed for tabular or image data, which do not naturally respect graph topology or relation semantics.
The query-input stage therefore also records provenance metadata — which graph snapshot, which source ontologies (DrugBank, Reactome, GO) contributed the entity nodes — so that any later-highlighted explanation path can be traced back to its underlying data sources for audit.
Graph schema and relationship typing
The quality of the eventual explanation depends heavily on how richly the underlying schema types its edges. A schema with only a generic "RELATED_TO" edge produces explanation paths that are structurally valid but semantically empty. Well-designed biomedical KGs (Hetionet: 11 node types, 24 edge types; ROBOKOP; SPOKE) instead use specific predicates — TARGETS, UPREGULATES, TREATS, CONTRAINDICATES — each carrying its own prior confidence derived from the curation source.
During query compilation, the relationship-type whitelist passed to the traversal engine can be narrowed based on the question type: a mechanism question ("why does X treat Y") prioritizes molecular-interaction edges, while a safety question ("why is X contraindicated for Y") prioritizes adverse-event and pathway-overlap edges. This early filtering reduces the candidate path space before the expensive search stage even starts.
Candidate Path Search Across the Graph
With both endpoints anchored, the engine performs a bounded-depth traversal — typically breadth-first with early termination — to enumerate every simple path connecting the start and end nodes within the configured hop limit. On dense graphs this produces dozens to hundreds of candidates, each a plausible but unverified chain of reasoning.
- 40–120: Candidate paths (4-hop, dense node) (before pruning)
- ~40: Avg. node out-degree (biomedical KG) (Hetionet-scale graph)
- BFS: Traversal algorithm (bidirectional, meet-in-middle)
- 110–340 ms: Search wall-clock (4-hop bound) (single query, indexed graph)
Bidirectional breadth-first search
Naive single-direction BFS from the start node has search-space growth O(d^k) where d is average degree and k is hop count — at d≈40 and k=4 this exceeds 2.5 million frontier nodes. Production path-finding engines instead use bidirectional BFS: expanding frontiers simultaneously from the start node and the end node, meeting in the middle. This reduces the effective exponent from k to k/2, cutting the frontier size by several orders of magnitude for the same hop budget.
Neo4j's native variable-length pattern matching and the APOC path-expansion procedures (apoc.path.expandConfig) implement this style of bounded, relationship-type-filtered traversal directly on the storage layer, avoiding the need to materialize the whole graph in application memory. For RDF stores, SPARQL 1.1 property paths combined with engine-specific magic properties (e.g., Blazegraph's GAS API) achieve comparable bounded traversal.
Every simple path discovered — no cycles, no repeated nodes — becomes a candidate explanation. At this stage no scoring has occurred: a path through a well-curated, high-confidence edge and a path through a single noisy text-mined co-occurrence edge are treated identically.
Bidirectional BFS reduces the effective search exponent from k hops to roughly k/2, meaning a 6-hop query explores a frontier comparable in size to a naive 3-hop search — the single largest performance lever in path-based explainability engines.
Pruning strategies to keep the candidate set tractable
Even with bidirectional search, dense hub nodes ("supernodes" like Protein p53 or Disease "cancer" with tens of thousands of edges) can flood the candidate set. Three pruning strategies are standard practice:
• Degree capping: hub nodes above a configurable out-degree threshold (e.g., >5,000 edges) are excluded from intermediate traversal steps, since paths through them tend to be generic and low-information • Relationship-type whitelisting: only edge types relevant to the question intent (see Stage 1) are followed, discarding administrative or provenance edges • Beam-limited frontier expansion: at each hop, only the top-N partial paths by a cheap heuristic score (e.g., edge-source curation tier) are retained for further expansion, rather than exhaustively keeping every partial path
The "Number of Paths Shown" control in this interface mirrors the beam width used in production systems — widening it surfaces more of the raw candidate diversity at the cost of visual and computational clutter, while narrowing it approximates an aggressive early prune.
Representing paths for downstream scoring
Each discovered path is serialized as an ordered sequence of (node, relationship, node) triples, annotated with per-edge metadata pulled from the graph store: curation source, publication count (for text-mined edges), and any pre-computed embedding similarity between endpoint nodes. This structured representation is what the scoring stage consumes — it deliberately avoids collapsing the path into a single opaque score at this point, preserving full auditability of every hop for the eventual human verification step.
Path Scoring & Confidence Ranking
Every candidate path is now scored by a composite function combining per-edge confidence, path-length penalty, and — in learned settings — attention weights extracted from a graph neural network trained on the link-prediction task. The candidate set is sorted, and the score distribution typically shows one or two paths pulling clearly ahead of the rest.
- ~1,800: Scoring throughput (paths/sec, CPU-only)
- 0.85ⁿ: Length-penalty decay factor (per additional hop)
- GAT / R-GCN: GNN attention model (edge-type-aware attention)
- 0.18: Score gap, top-1 vs top-2 (typical) (on 0–1 confidence scale)
Composite path-confidence scoring
A widely used scoring formula treats path confidence as the product of edge confidences, discounted by length:
score(p) = (∏ᵢ conf(eᵢ)) × λ^(len(p)−1)
where conf(eᵢ) is the curated or learned confidence of edge i (e.g., derived from number of supporting publications, curation tier, or a knowledge-graph-embedding plausibility score such as TransE or ComplEx), and λ ∈ (0,1) is a length-decay constant (commonly 0.8–0.9) reflecting the intuition that longer inferential chains compound uncertainty and are individually harder for a human to verify.
An alternative, increasingly common in production explainability systems, replaces the hand-tuned product formula with attention weights read directly off a trained graph neural network. Graph Attention Networks (GAT) and Relational GCNs (R-GCN) assign a learned attention coefficient to each edge during message passing for the link-prediction task; summing or multiplying these coefficients along a path yields a model-native confidence that reflects what the predictive model itself relied on — not just curation metadata.
GNNExplainer and PGExplainer, two of the most-cited GNN explainability methods, formalize this idea: they solve for the minimal edge subset (often exactly the paths shown here) whose removal would maximally decrease the model's predicted link probability — directly linking path visualization to model fidelity.
Length penalty and the interpretability trade-off
Longer paths are not inherently worse explanations, but they impose a real cognitive and epistemic cost: each additional hop is another opportunity for a spurious or noisy edge to enter the chain, and each additional edge is one more claim a human reviewer must independently verify. The length-decay term λ^(len−1) formalizes Occam's-razor-style preference for the shortest sufficient explanation, all else equal.
This creates a genuine ranking trade-off in dense knowledge graphs: a 2-hop path through two only-moderately-confident edges may out-score a 5-hop path built entirely of high-confidence, well-curated edges, because the multiplicative length penalty dominates. The "Max Path Length" control in this interface exposes exactly this trade-off — tightening the bound forces the ranking toward shorter, more interpretable (but potentially lower individual-edge-confidence) explanations.
Comparing path-ranking approaches
No single ranking algorithm dominates across all knowledge graph domains; the choice depends on whether curated confidence metadata exists, whether a trained GNN is available, and how much scoring latency the application can tolerate. The table below compares four approaches used in production and research explainability systems.
Path-ranking algorithm comparison
| Product | Indication | Trial Design | Key Result |
|---|---|---|---|
| Product-of-confidence + length decay | Curated graphs with edge metadata | Multiplies per-edge curation confidence, discounts by λ^hops | Fully interpretable, no model training required |
| GNN attention-based (GAT / R-GCN) | Graphs with a trained link-prediction model | Reads learned attention coefficients along candidate paths | Reflects what the predictive model actually used |
| Random-walk / PageRank-weighted | Large graphs lacking rich edge metadata | Scores paths by stationary visitation probability of a biased random walk | Cheap to compute, scales to 10⁷+ node graphs |
| Embedding-plausibility (TransE / ComplEx) | Graphs with pretrained KG embeddings | Scores each edge by translational/bilinear plausibility in embedding space | Captures latent semantic patterns beyond direct curation |
Explanation Path Highlight & Sequential Trace
The top-ranked path is isolated from the candidate field and rendered as a single glowing route from the start node to the end node. Its edges illuminate one at a time, in traversal order, so the explanation reads like a signal propagating through the graph — each illuminated hop representing one verifiable inferential step.
- 3 hops: Selected explanation length (typical) (after length-penalty ranking)
- ~450 ms: Edge illumination interval (per hop, animated trace)
- 11–27: Rejected candidates (typical run) (dimmed / discarded)
- 0.81–0.94: Top-path confidence (this run) (composite score range)
From ranked list to a single rendered explanation
Once scoring converges, the interface commits to the highest-ranked path as the primary explanation and visually demotes every other candidate — most fade to near-invisibility, while a small number of close runners-up remain faintly visible in red to signal "these were considered and rejected," which is itself important explanatory information. Showing only the winner, with no visible alternatives, risks implying a false certainty that no other explanation was ever considered.
The sequential edge-by-edge illumination is a deliberate interaction-design choice grounded in how humans process causal chains: presenting all edges simultaneously invites the eye to jump around and miss the directional logic, whereas an animated trace from start to end mirrors how a domain expert would narrate the mechanism aloud — "X targets protein P, which regulates pathway R, which is dysregulated in disease Y."
Attaching evidence to each illuminated edge
As each edge lights up, the system attaches its underlying evidence: the curation source (e.g., DrugBank interaction record, a specific PubMed ID for a text-mined relation, or a Reactome pathway annotation), the edge-level confidence score computed in Stage 3, and — where available — the number of independent publications supporting that specific relation.
This is the mechanism by which path-based explainability avoids becoming a black box itself: an explanation is only as trustworthy as the provenance behind its weakest edge, so surfacing that provenance alongside the animated trace lets a reviewer immediately spot the shakiest link in the chain — often the edge with the fewest supporting sources or the oldest curation date.
In audits of biomedical KG explanations, the single weakest edge in an otherwise high-scoring path is disproportionately likely to be a text-mined co-occurrence relation rather than a curated interaction — making edge-level provenance display, not just an aggregate path score, essential for responsible use.
Handling ties and near-ties gracefully
When the top two or three candidate paths score within a small margin (empirically, a composite-score gap below ~0.05 on a 0–1 scale), presenting only a single "winning" path can overstate confidence. Robust explainability interfaces detect this condition and either present a small ranked set of co-equal explanations, or explicitly annotate the highlighted path with a caveat such as "closely rivaled by an alternative mechanism through pathway P2." This mirrors best practice in GNN explainability research, where reporting a fidelity score alongside the explanation — how much the model's prediction would change if this path were removed — is considered more honest than presenting a bare ranked list.
User Verification & Feedback Loop
The final stage returns control to the human reviewer. Each edge of the highlighted explanation can be individually confirmed or rejected against source evidence, and the aggregate verdict — accept, partially accept, or reject — is logged. This closes the loop between automated graph reasoning and accountable, auditable decision-making.
- ~68%: Full-path acceptance rate (clinical review) (across pilot deployments)
- 40–90 sec: Median reviewer time per explanation (3-hop path)
- Yes: Edge-level rejection triggers re-rank (promotes next candidate)
- <200 ms: Feedback loop latency (verdict logged to audit store)
Why the loop cannot end at the machine-ranked answer
Path-based explanation dramatically improves interpretability over a bare confidence score, but it does not eliminate the need for human judgment — it relocates that judgment to a much narrower, well-scoped task. Instead of asking a domain expert to evaluate an entire black-box prediction, the system asks a much more tractable question: "does this specific 3-hop chain of typed relationships, each with attached evidence, plausibly support the claim?"
This reframing is consistent with recommendations from regulatory and standards bodies addressing explainable AI in biomedicine (e.g., FDA's guidance on AI/ML-based Software as a Medical Device, and the EU AI Act's requirements for human oversight of high-risk automated systems): the machine narrows a vast search space to a small, auditable artifact, and a qualified human renders the final judgment on that artifact.
Edge-level confirm/reject and re-ranking
Verification in this interface operates at edge granularity rather than only at the whole-path level. A reviewer can confirm individual hops that are well-supported while flagging a specific weak link — for example, accepting "Drug X targets Protein P" and "Protein P regulates Pathway R" while rejecting "Pathway R is dysregulated in Disease Y" as based on outdated or contradicted literature.
A rejected edge does more than annotate that single explanation: it can trigger a re-ranking pass that either removes the offending edge's confidence contribution from the scoring function (demoting any path relying on it) or promotes the next-best candidate path from Stage 3 that avoids the rejected edge entirely. This feedback is typically persisted back into the graph as a review annotation, so future queries touching the same edge inherit the human judgment.
Systems that log edge-level rejections and feed them back into subsequent scoring runs have been shown to reduce repeat false-positive explanations by roughly 30–40% over successive review cycles — the explainability layer itself becomes a curation signal for the underlying graph.
Closing the loop — audit trails and trust calibration
Every verification decision is timestamped and stored alongside the query, the full candidate path set, the selected explanation, and the composite scores that produced the ranking — forming a complete audit trail from natural-language question to human-confirmed evidence chain. This artifact is what distinguishes a defensible automated inference from an opaque one: in a later audit or dispute, the entire reasoning chain can be reconstructed and re-examined.
Over many review cycles, aggregate acceptance and rejection rates also serve a second purpose beyond individual-query accountability: they calibrate trust in the underlying scoring function itself. A composite score of 0.85 should correspond, empirically, to roughly an 85% chance of full human acceptance — deviations from that calibration signal that the scoring weights (curation confidence, length penalty, GNN attention) need retuning against real reviewer judgment, closing the loop between explainability tooling and the graph reasoning system it explains.
This tool visualizes the explainability path of queries in a knowledge graph, providing insights into how and why certain results are returned based on the structure and content of the graph.
2D · HTML5 Canvas 2D · 60 FPS target · runs fully client-side, no install