Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 98 additions & 0 deletions skills/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# MAGE Algorithm Skills for GitHub Copilot

This directory contains [Agent Skills](https://agentskills.io/) that provide GitHub Copilot with expertise in Memgraph's MAGE (Memgraph Advanced Graph Extensions) algorithms.

## What are Agent Skills?

Agent Skills are folders of instructions that GitHub Copilot can load when relevant to perform specialized tasks. Each skill teaches Copilot how to use specific graph algorithms with Memgraph.

## Using These Skills

These skills work automatically with:
- **GitHub Copilot coding agent** (in VS Code and other editors)
- **GitHub Copilot CLI**
- **VS Code Insiders agent mode**

When you ask Copilot about graph algorithms, it will automatically discover and use these skills to help you write correct Cypher queries and understand algorithm usage.

## Available Skills

### Graph Analytics & Centrality
- **pagerank** - Measure node influence based on connections
- **betweenness-centrality** - Find bridge nodes and connectors
- **degree-centrality** - Count node connections
- **katz-centrality** - Influence based on all paths

### Community & Clustering
- **community-detection** - Louvain algorithm for finding communities
- **leiden-community-detection** - Improved community detection
- **weakly-connected-components** - Find connected groups

### Path Finding & Traversal
- **shortest-path** - Find optimal paths between nodes
- **bfs** - Breadth-first search traversal
- **tsp** - Traveling Salesman Problem solver

### Graph Structure
- **bridges** - Detect critical edges
- **cycles** - Find cycles in graphs
- **graph-analyzer** - Graph statistics and profiling

### Similarity & Machine Learning
- **node-similarity** - Calculate node similarity
- **node2vec** - Generate node embeddings

### Optimization
- **max-flow** - Maximum flow in networks

### Utilities
- **collections** - List manipulation utilities
- **json-util** - JSON import/export

## Example Usage

Simply ask Copilot natural language questions like:

```
"Find the most influential nodes in my graph using PageRank"
"Detect communities in the social network"
"What's the shortest path between node A and node B?"
"Calculate betweenness centrality to find bridge nodes"
```

Copilot will:
1. Recognize the request matches a skill
2. Load the skill instructions
3. Generate appropriate Cypher queries
4. Help you understand and use the results

## Skill Structure

Each skill follows the [Agent Skills specification](https://agentskills.io/specification):

```
skill-name/
└── SKILL.md # Skill definition with frontmatter + instructions
```

The `SKILL.md` file contains:
- **YAML frontmatter** with name, description, and metadata
- **Detailed instructions** on when and how to use the algorithm
- **Cypher query examples** with Memgraph MAGE procedures
- **Common edge cases** and tips

## Requirements

- GitHub Copilot Pro, Pro+, Business, or Enterprise
- Memgraph database with MAGE library installed
- These skills are specifically designed for Memgraph's Cypher dialect and MAGE procedures

## Learn More

- [Agent Skills Specification](https://agentskills.io/)
- [GitHub Copilot Skills Documentation](https://docs.github.com/en/copilot/concepts/agents/about-agent-skills)
- [Memgraph MAGE Documentation](https://memgraph.com/docs/advanced-algorithms/available-algorithms)

## License

Apache-2.0
115 changes: 115 additions & 0 deletions skills/betweenness-centrality/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
---
name: betweenness-centrality
description: Calculate betweenness centrality to find nodes that act as bridges or connectors in the graph by measuring how often they appear on shortest paths between other nodes. Use when finding bridge nodes, connectors, bottlenecks, or nodes that control information flow.
license: Apache-2.0
metadata:
author: memgraph
version: "1.0"
algorithm_type: centrality
complexity: "O(V * E)"
---

# Betweenness Centrality

Betweenness centrality measures the extent to which a node lies on paths between other nodes. Nodes with high betweenness centrality act as bridges or gatekeepers in the network.

## When to Use This Skill

Use betweenness centrality when:
- Finding bridge nodes that connect different parts of a network
- Identifying bottlenecks or critical points
- Detecting nodes that control information flow
- Finding connectors between communities
- Analyzing network resilience (removing high-betweenness nodes)

## Basic Usage

### Calculate Betweenness Centrality

```cypher
CALL betweenness_centrality.get()
YIELD node, betweenness_centrality
RETURN node, betweenness_centrality
ORDER BY betweenness_centrality DESC
LIMIT 10;
```

### Normalized Betweenness Centrality

```cypher
CALL betweenness_centrality.get(True, True)
YIELD node, betweenness_centrality
RETURN node, betweenness_centrality
ORDER BY betweenness_centrality DESC;
```

**Parameters:**
- `directed` (default: True) - Whether to treat the graph as directed
- `normalized` (default: True) - Normalize scores to [0, 1] range

## Advanced Usage

### Betweenness on Subgraph

```cypher
MATCH (n:Person)-[r:WORKS_WITH]->(m:Person)
WITH collect(n) + collect(m) AS nodes, collect(r) AS rels
CALL betweenness_centrality.get_subgraph(nodes, rels)
YIELD node, betweenness_centrality
RETURN node.name AS name, betweenness_centrality
ORDER BY betweenness_centrality DESC;
```

### Filter by Label

```cypher
CALL betweenness_centrality.get()
YIELD node, betweenness_centrality
WHERE node:Router
RETURN node.name AS router, betweenness_centrality
ORDER BY betweenness_centrality DESC;
```

### Compare with Other Centralities

```cypher
CALL betweenness_centrality.get() YIELD node, betweenness_centrality
WITH node, betweenness_centrality
CALL pagerank.get() YIELD node AS pr_node, rank
WHERE node = pr_node
RETURN node.name, betweenness_centrality, rank AS pagerank
ORDER BY betweenness_centrality DESC;
```

## Output Format

| Column | Type | Description |
|--------|------|-------------|
| node | Node | The graph node |
| betweenness_centrality | Float | Centrality score (higher = more important as bridge) |

## Example Results

```
╔════════════════════╦═══════════════════════════╗
║ name ║ betweenness_centrality ║
╠════════════════════╬═══════════════════════════╣
║ "Gateway_Router" ║ 0.892 ║
║ "Central_Hub" ║ 0.734 ║
║ "Bridge_Node" ║ 0.651 ║
╚════════════════════╩═══════════════════════════╝
```

## Common Edge Cases

1. **Disconnected graphs**: Nodes in separate components have 0 betweenness relative to each other
2. **Star topology**: Central node has maximum betweenness
3. **Complete graphs**: All nodes have equal (low) betweenness
4. **Linear chains**: Middle nodes have highest betweenness

## Interpretation Tips

- High betweenness = critical for connectivity
- Removing high-betweenness nodes may fragment the network
- Compare normalized scores across different graphs
- Often complements PageRank (different aspects of importance)
126 changes: 126 additions & 0 deletions skills/bfs/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
---
name: bfs
description: Perform breadth-first search traversal starting from a node, visiting neighbors level by level. Use when exploring graphs layer by layer, finding shortest unweighted paths, or discovering all nodes within a certain distance.
license: Apache-2.0
metadata:
author: memgraph
version: "1.0"
algorithm_type: traversal
complexity: "O(V + E)"
---

# Breadth-First Search (BFS)

Traverse a graph starting from a source node, exploring all neighbors at the current depth before moving to nodes at the next depth level. Fundamental for shortest paths in unweighted graphs.

## When to Use This Skill

Use BFS when:
- Finding shortest path in unweighted graph
- Exploring nodes level by level
- Finding all nodes within N hops
- Discovering connected components
- Web crawling or social network exploration

## Basic Usage

### BFS Shortest Path

```cypher
MATCH p = (a:Person {name: "Alice"})-[*BFS]-(b:Person {name: "Bob"})
RETURN p, length(p) AS distance;
```

### BFS with Depth Limit

```cypher
MATCH p = (a:Person {name: "Alice"})-[*BFS..3]-(b)
RETURN b.name AS reachable_node, length(p) AS distance
ORDER BY distance;
```

### BFS with Relationship Filter

```cypher
MATCH p = (a:Person {name: "Alice"})-[:KNOWS|WORKS_WITH *BFS]-(b)
RETURN b, length(p) AS distance;
```

## Advanced Usage

### Find All Nodes at Specific Distance

```cypher
MATCH p = (a:Person {name: "Alice"})-[*BFS]-(b)
WHERE length(p) = 2
RETURN b.name AS two_hops_away;
```

### BFS with Filter Lambda

```cypher
MATCH p = (a:Person {name: "Alice"})-[*BFS (e, n | n.active = true)]-(b)
RETURN b;
```

### Count Nodes by Distance

```cypher
MATCH p = (a:Person {name: "Alice"})-[*BFS..5]-(b)
WHERE a <> b
RETURN length(p) AS distance, count(b) AS nodes_at_distance
ORDER BY distance;
```

### BFS for Finding Shortest Path Length

```cypher
MATCH p = shortestPath((a:Person {name: "Alice"})-[*]-(b:Person {name: "Bob"}))
RETURN length(p) AS shortest_distance;
```

## Output Format

| Column | Type | Description |
|--------|------|-------------|
| path | Path | The BFS path from source |
| node | Node | Discovered node |
| distance | Integer | Number of hops from source |

## BFS vs DFS

| Aspect | BFS | DFS |
|--------|-----|-----|
| Strategy | Level by level | Deep first |
| Shortest path | Yes (unweighted) | No guarantee |
| Memory | O(width) | O(depth) |
| Use case | Shortest paths, nearby nodes | Full exploration, cycles |

## Example Results

```
╔════════════════════╦═══════════════╗
║ reachable_node ║ distance ║
╠════════════════════╬═══════════════╣
║ "Bob" ║ 1 ║
║ "Charlie" ║ 1 ║
║ "David" ║ 2 ║
║ "Eve" ║ 2 ║
║ "Frank" ║ 3 ║
╚════════════════════╩═══════════════╝
```

## Common Edge Cases

1. **No path exists**: Empty result
2. **Source equals target**: Returns empty path (distance 0)
3. **Cycles**: BFS naturally handles cycles (visits each node once)
4. **Disconnected graph**: Only reaches nodes in same component

## Tips

- Use `*BFS` for guaranteed shortest unweighted path
- Add depth limit (`..N`) to avoid exploring entire graph
- Filter relationship types to constrain traversal
- Use filter lambda for property-based traversal rules
- Consider indexes on starting node properties
Loading