Building Narrative Context via Path Descriptors: Connecting the Dots

Building Narrative Context via Path Descriptors: Connecting the Dots

Tell the story of the connection. Learn how to describe multi-hop paths to an LLM so it understands the 'Chain of Evidence' between two distant entities.

Building Narrative Context via Path Descriptors

A fact is rarely a single dot. In advanced Graph RAG, the answer is the Path. If a user asks "How is Sudeep related to the server crash?", the answer isn't "Sudeep." The answer is: "Sudeep pushed code to Repo X, which was deployed by Service Y, which is hosted on Server Z, which crashed." To deliver this, you must build Path Descriptors.

In this lesson, we will look at how to serialize a Chain of Thought from the graph. We will learn how to turn the r1, n1, r2, n2 sequence into a paragraph that the LLM can easily reason over. We will explore the "Evidence Chain" pattern and see how it prevents the AI from "Jumping to Conclusions" without evidence.


1. The Anatomy of a Path Descriptor

A path descriptor should have three parts:

  1. The Origin: Where the story starts.
  2. The Bridge: Why the nodes are linked.
  3. The Destination: Where it leads.

Bad Context: Sudeep -> Repo X. Repo X -> Service Y. Good Context: Sudeep (Person) is a CONTRIBUTOR to the repository Repo X. This repository is DEPLOYED through Service Y.


2. Handling "Relationship Properties" in Narratives

Many relationships have properties like date, amount, or reason. These must be included in the descriptor.

  • Triplet: (Person)-[:PAID {amount: 500}]->(Store)
  • Narrative: "The Person made a payment of $500 to the Store."

If you omit the $500, the LLM might hallucinate a different amount or assume it was a donation rather than a purchase.


3. The "Meta-Path" Prompting Technique

Sometimes the exact path is too long. We can use Meta-Paths to summarize.

  • Raw Path: Sudeep -> Commit -> PR -> Merge -> Deploy -> Cluster (6 hops).
  • Meta-Path Context: "Sudeep is indirectly responsible for the Cluster via his recent code changes."

This uses the graph's structure to create a high-level summary that is easier for the LLM's brain to hold.

graph LR
    A[Sudeep] -->|Push| B[Repo]
    B -->|Deploy| C[Server]
    C -->|Status| D[CRASHED]
    
    subgraph "Narrative Chain"
    A --- B --- C --- D
    end
    
    style D fill:#f44336,color:#fff
    note[The AI should 'See' the full logic chain]

4. Implementation: Building a Multi-Hop Descriptor in Python

def describe_path(path):
    tokens = []
    for i, element in enumerate(path):
        if i % 2 == 0: # It's a Node
            tokens.append(f"[{element['name']}]")
        else: # It's a Relationship
            tokens.append(f"--({element.type.lower().replace('_', ' ')})-->")
    
    return " ".join(tokens)

# Result: "[Sudeep] --(pushed code to)--> [Repo X] --(deployed by)--> [Service Y]"

5. Summary and Exercises

Path descriptors are the "Logical Glue" of Graph RAG.

  • Contextual linking prevents the "Islands of Text" problem.
  • Relationship properties add the necessary metadata for accurate synthesis.
  • Naming the transitions (using verbs) helps the AI understand the nature of the link.
  • Meta-paths simplify deep traversals into usable summaries.

Exercises

  1. Narrative Task: You have a 3-hop path: Doctor -> Hospital -> City -> Country. Write a narrative sentence that connects the Doctor directly to the Country using the bridges.
  2. Verb Choice: If the relationship is [:FOLLOWS], what is a better natural language word for a "Twitter Bot" RAG system? What about for a "Stalker Detection" RAG system?
  3. Visualization: Draw a 4-hop path and write a "One Sentence Summary" of the entire chain.

In the next lesson, we will look at technical limits: Handling Token Limits in Graph Expansion.

Subscribe to our newsletter

Get the latest posts delivered right to your inbox.

Subscribe on LinkedIn