liveBook · Manning

Metapath

As explained in Knowledge Graphs and LLMs in Action

A metapath is a sequence of node classes and relationship classes describing possible paths between specified source and destination types.

A metapath is an abstract sequence of node classes and relationship classes describing possible paths between specified source and destination types. Unlike a real path, it describes a connection pattern rather than a path instance in the graph. section 4.3

Metapaths turn a graph schema into searchable connection patterns. In Hetionet, they identify routes between compounds and diseases, then support path count and degree-weighted path count (DWPC) calculations. section 4.3 section 10.2.2

A metapath-based analysis typically proceeds as follows:

  • Select source and destination node classes and constrain the maximum path length. section 4.3
  • Enumerate valid node–relationship sequences from the schema, treating them as candidate patterns rather than observed paths. section 4.3
  • Count matching path instances or calculate DWPC, reducing the influence of highly connected intermediate nodes through degree-based damping. section 10.2.2
  • Use the resulting values as interpretable features for each node pair, including pairs without a direct relationship. section 10.2.2 section 10.4

Metformin and type 2 diabetes

For metformin and type 2 diabetes, CbGaD means Compound–binds–Gene–associates–Disease. A query counts matching paths and computes PC and DWPC; longer alternatives include CbGeAlD and CbGpPWpGaD. section 10.2.2

Metagraph (a) and metapath (b) excerpts for Hetionet. A metagraph describes the structure of the database, indicating the types of nodes and the types of relationships. Metapaths describe paths and indicate types of nodes and relationships.
inline figure

Use the metagraph and metapath comparison to distinguish database structure from abstract path patterns. section 4.3

How Knowledge Graphs and LLMs in Action covers it

How deep it goes
Defines abstract path patterns, distinguishes them from instances, and extends them into path counts and degree-weighted scores.
Examples
Uses Hetionet drug–disease patterns such as CbGaD, CbGeAlD, and CbGpPWpGaD with metformin and type 2 diabetes.
What it assumes
Assumes a graph schema with typed nodes and relationships, while distinguishing schema-level patterns from concrete path instances.
What you can do after
Apply it via Neo4j-style graph queries to extract paths and calculate interpretable PC and DWPC features.
How it connects
Connects graph schemas, metagraphs, path count, DWPC, feature engineering, machine learning, and node degree.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Knowledge Graphs and LLMs in Action. The section links point to the parts of the book it draws on.