← 返回 Skills 市场
fisa712

Knowledge Graph - Multi Hop Reasoning Query Builder

作者 Muhammad Asif · GitHub ↗ · v1.0.0 · MIT-0
cross-platform ✓ 安全检测通过
35
总下载
0
收藏
0
当前安装
1
版本数
在 OpenClaw 中安装
/install multi-hop-reasoning-query-builder
功能描述
Generate graph queries that perform multi-hop traversal and reasoning across relationships in graph databases and knowledge graphs.
使用说明 (SKILL.md)

Multi-Hop Reasoning Query Builder

Construct graph queries that explore indirect relationships through multiple hops in a graph.

This skill helps developers generate queries that traverse several relationships to discover hidden connections and complex patterns within graph datasets.

Multi-hop reasoning is commonly used in:

  • knowledge graph exploration
  • recommendation systems
  • fraud detection
  • supply chain analysis
  • social network analysis

The skill produces queries that traverse multiple edges to identify connections between entities.


📋 Quick Start

When To Use This Skill

Use this skill when a user wants to:

  • build multi-hop graph queries
  • explore indirect relationships
  • perform reasoning across graph paths
  • discover connections through several relationships
  • construct path traversal queries
  • find hidden patterns across hops
  • analyze relationship chains

Example Requests

  • "Find friends of friends of Alice."
  • "Find suppliers connected to a company within three hops."
  • "Discover customers linked through purchase chains."
  • "Find entities connected to a node within multiple relationships."
  • "Show me the path from Product A to Product B."
  • "Find all paths between two companies."

🎯 What This Skill Produces

The skill generates graph queries capable of:

  • Multi-hop traversal - Traverse multiple relationship hops
  • Path discovery - Find paths between entities
  • Indirect relationship detection - Discover hidden connections
  • Graph reasoning queries - Complex reasoning patterns
  • Variable-length path exploration - Flexible traversal patterns
  • Performance-optimized queries - Efficient multi-hop queries

Outputs include:

  • Cypher traversal queries
  • SPARQL property path queries
  • Graph path exploration queries
  • Parameterized multi-hop templates

🔍 Multi-Hop Query Types

1. Fixed Depth Multi-Hop

Pattern: Traverse exactly N relationships

Cypher:

MATCH (start:$startLabel {id: $startId})-[:$relType*2]->(target)
RETURN target

Example - Friends of Friends:

MATCH (alice:Person {name:"Alice"})-[:FOLLOWS*2]->(fof:Person)
RETURN fof

Use Cases:

  • Exactly 2 hops from Alice
  • Precise distance queries
  • Specific relationship chain discovery

2. Variable Depth Multi-Hop

Pattern: Traverse between MIN and MAX relationships

Cypher:

MATCH (start:$startLabel {id: $startId})-[:$relType*1..$maxHops]->(target)
RETURN target
LIMIT $limit

Example - Up to 3 Hops:

MATCH (company:Company {id:"C123"})-[:SUPPLIES*1..3]->(supplier)
RETURN supplier
LIMIT 50

Use Cases:

  • Within N hops
  • Range-based discovery
  • Flexible connection finding

3. Path Discovery

Pattern: Return actual path structures

Cypher:

MATCH path = (start:$startLabel)-[*1..$maxHops]-(target:$targetLabel)
RETURN path, LENGTH(path) as hops
LIMIT $limit

Example - Path from Alice to Bob:

MATCH path = (alice:Person {name:"Alice"})-[*1..4]-(bob:Person {name:"Bob"})
RETURN path, LENGTH(path) as hops
LIMIT 10

Returns: Full traversal paths showing relationships


4. Filtered Multi-Hop

Pattern: Multi-hop with relationship type filtering

Cypher:

MATCH (start:$startLabel)-[:$relType*1..$hops]->(target:$targetLabel)
WHERE start.id = $startId AND target.$property = $value
RETURN target
LIMIT $limit

Example - Specific Relationship Chain:

MATCH (source:Person)-[:KNOWS|:WORKS_WITH*1..3]->(target:Person)
WHERE source.name = "Alice" AND target.active = true
RETURN target
LIMIT 25

5. Undirected Multi-Hop

Pattern: Follow relationships in any direction

Cypher:

MATCH (start:$startLabel)-[:$relType*1..$maxHops]-(target)
RETURN target

Example - Undirected Network:

MATCH (node:Entity)-[*1..3]-(connected)
RETURN connected
LIMIT 100

6. SPARQL Property Paths

Pattern: SPARQL+ operator for one or more hops

SPARQL:

SELECT ?target
WHERE {
  ?start ex:$property+ ?target .
}

Example - Property Path:

PREFIX ex: \x3Chttp://example.org/>
SELECT ?person
WHERE {
  :Alice ex:knows+ ?person .
}

7. Aggregated Multi-Hop

Pattern: Multi-hop with aggregation

Cypher:

MATCH (start:$startLabel)-[:$relType*1..$hops]->(target)
RETURN target, COUNT(*) as path_count
GROUP BY target
ORDER BY path_count DESC

Example - Count Paths:

MATCH (alice:Person {name:"Alice"})-[:FOLLOWS*1..3]->(person)
RETURN person, COUNT(*) as num_paths
GROUP BY person
ORDER BY num_paths DESC
LIMIT 10

8. Conditional Multi-Hop

Pattern: Multi-hop with WHERE conditions

Cypher:

MATCH path = (start:$startLabel)-[:$relType*1..$hops]->(target)
WHERE ALL(n in nodes(path) WHERE n.$property \x3C> $excludeValue)
RETURN target

Example - Avoid Specific Nodes:

MATCH path = (alice:Person {name:"Alice"})-[:KNOWS*1..3]->(person)
WHERE ALL(n in nodes(path) WHERE n.status = "active")
RETURN person
LIMIT 50

📊 Multi-Hop Complexity

Hop Depth Impact:

Depth 1: O(n)
  ├─ 1 hop from start node
  └─ Direct relationships only

Depth 2: O(n²)
  ├─ 2 hops from start node
  └─ Friends of friends

Depth 3: O(n³)
  ├─ 3 hops from start node
  └─ Can be expensive

Depth 4+: O(n^4+) ⚠️ EXPENSIVE
  ├─ Exponential growth
  └─ Use only with filtering/limits

Performance Guidelines:

  • Keep depth ≤ 3 for open queries
  • Use depth ≤ 4 with strong filters
  • Avoid depth > 4 without restrictions
  • Always include LIMIT clause

🏢 Real-World Examples

Social Network: Friends of Friends

MATCH (user:User {id: $userId})-[:FOLLOWS*2]->(fof:User)
WHERE NOT (user)-[:FOLLOWS]->(fof)
RETURN DISTINCT fof
LIMIT 50

E-Commerce: Product Recommendations

MATCH (customer:Customer {id: $customerId})-[:PURCHASED*1..2]->(recommended:Product)
RETURN recommended, COUNT(*) as relevance
GROUP BY recommended
ORDER BY relevance DESC
LIMIT 10

Supply Chain: Supplier Network

MATCH (company:Company {name: $companyName})-[:SUPPLIES*1..3]->(supplier:Company)
RETURN supplier, COUNT(*) as connections
GROUP BY supplier
ORDER BY connections DESC
LIMIT 20

✅ Best Practices

When building multi-hop queries:

  1. Limit Traversal Depth

    • Depth ≤ 3 for unrestricted queries
    • Depth ≤ 4 with heavy filtering
    • Always bound depth
  2. Restrict Relationship Types

    • Specify exact relationships
    • Avoid wildcard traversal
    • Filter by direction
  3. Use Result Limits

    • Always include LIMIT clause
    • Prevents memory issues
    • Controls response size
  4. Start from Specific Nodes

    • Use indexed properties for entry
    • Filter by specific IDs/properties
    • Avoid full scans
  5. Filter Within Paths

    • Use WHERE with ALL/ANY
    • Exclude specific nodes
    • Filter by node properties
  6. Apply Indexes

    • Index starting node properties
    • Index relationship types
    • Index filter properties
  7. Test Performance

    • Profile with real data
    • Monitor execution time
    • Optimize entry points
  8. Document Assumptions

    • Expected path lengths
    • Relationship cardinality
    • Performance characteristics

🔗 Integration with Other Skills

This skill integrates with:

  • graph-query-debugging-tool - Debug multi-hop queries
  • graph-query-optimization-assistant - Optimize multi-hop patterns
  • graph-template-query-generator - Generate multi-hop templates
  • nl-to-graph-query-translator - Translate natural language to multi-hop
  • graph-schema-validation - Validate multi-hop against schema

📋 Output Formats

The skill returns:

1. Multi-Hop Query

Executable Cypher or SPARQL query with specified hop depth.

2. Path Query

Returns relationship paths showing traversal chains.

3. Parameterized Template

Reusable template with hop parameters.

4. Complexity Analysis

Performance metrics and recommendations.


💡 Reasoning Patterns

Pattern 1: Find Connections

Discover all entities within N hops.

MATCH (start)-[:RELATIONSHIP*1..$n]->(end)
RETURN end

Pattern 2: Find Paths

Return actual paths showing relationship chains.

MATCH path = (start)-[*1..$n]-(end)
RETURN path

Pattern 3: Count Paths

Count number of different paths.

MATCH (start)-[:REL*1..$n]->(end)
RETURN end, COUNT(*) as paths

Pattern 4: Shortest Path

Find shortest connection.

MATCH path = shortestPath((start)-[*]-(end))
RETURN path

Pattern 5: Circular Detection

Find cycles in relationships.

MATCH path = (start)-[:REL*2..]->(start)
RETURN path

📖 Summary

This skill generates multi-hop graph queries that traverse multiple relationships to uncover indirect connections and hidden patterns in graph datasets.

It enables developers to perform advanced graph reasoning using Cypher or SPARQL for social networks, recommendation systems, fraud detection, and knowledge graph exploration.


Status: Enterprise-Grade Multi-Hop Reasoning

Comprehensive multi-hop query generation and reasoning system for professional knowledge graph development.

安全使用建议
Install only if you need help drafting graph traversal queries. Review generated queries before running them on real databases, especially in healthcare, finance, fraud, or account datasets, and add your own authorization checks, masking, limits, and audit controls for sensitive data.
能力评估
Purpose & Capability
The artifacts consistently describe and implement a multi-hop graph query builder for Cypher and SPARQL, with scripts that generate and analyze query strings rather than executing queries against live databases.
Instruction Scope
The instructions are purpose-aligned and include performance limits, but the healthcare contact-tracing example returns patient identifiers, locations, and contact chains without privacy or authorization guidance.
Install Mechanism
No package dependencies, install hooks, setup scripts, or automatic execution mechanisms are declared in the metadata or artifacts.
Credentials
The executable Python files use standard-library dataclasses, enums, and typing only; no file system mutation, network access, subprocess calls, credential access, or external service calls were found.
Persistence & Privilege
No persistence, background workers, privilege escalation, credential storage, or long-running behavior is present.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install multi-hop-reasoning-query-builder
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /multi-hop-reasoning-query-builder 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.0
Initial release of Multi-Hop Reasoning Query Builder. - Generates graph queries for multi-hop traversal and reasoning in graph databases and knowledge graphs. - Supports Cypher and SPARQL query generation for indirect relationship exploration. - Provides multiple multi-hop query templates: fixed/variable depth, path discovery, directionality, filtering, aggregation, and conditional traversal. - Offers real-world examples and best practice guidelines for performance and scalability. - Integrates with related graph query, optimization, and translation skills.
元数据
Slug multi-hop-reasoning-query-builder
版本 1.0.0
许可证 MIT-0
累计安装 0
当前安装数 0
历史版本数 1
常见问题

Knowledge Graph - Multi Hop Reasoning Query Builder 是什么?

Generate graph queries that perform multi-hop traversal and reasoning across relationships in graph databases and knowledge graphs. 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 35 次。

如何安装 Knowledge Graph - Multi Hop Reasoning Query Builder?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install multi-hop-reasoning-query-builder」即可一键安装,无需额外配置。

Knowledge Graph - Multi Hop Reasoning Query Builder 是免费的吗?

是的,Knowledge Graph - Multi Hop Reasoning Query Builder 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

Knowledge Graph - Multi Hop Reasoning Query Builder 支持哪些平台?

Knowledge Graph - Multi Hop Reasoning Query Builder 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 Knowledge Graph - Multi Hop Reasoning Query Builder?

由 Muhammad Asif(@fisa712)开发并维护,当前版本 v1.0.0。

💬 留言讨论