Neo4j

From G1Joshi/Agent-Skills · View interactive version

Neo4j is an AI agent skill from the GitHub repository G1Joshi/Agent-Skills. Expert Neo4j graph database assistance covering Cypher query language, node/edge labeling, graph algorithms, and APOC. Use when modeling connected data, recommendation engines, fraud detection, or knowledge graphs.

How to use this skill

Skill file

Neo4j

Neo4j is a native graph database. It stores data as nodes and relationships, not tables or documents. It is essential for "connected data" problems where relationships are as important as the data itself.

When to Use

Quick Start

-- Create nodes and relationships
CREATE (alice:Person {name: 'Alice'})
CREATE (bob:Person {name: 'Bob'})
CREATE (alice)-[:KNOWS {since: 2024}]->(bob);

-- Query friends of friends
MATCH (p:Person {name: 'Alice'})-[:KNOWS]->(friend)-[:KNOWS]->(fof)
RETURN fof.name;

Core Concepts

Labeled Property Graph (LPG) Model

Vertices are Nodes with Labels; connections are directed Relationships with Types; both store arbitrary key-value Properties:

(:Person {name: "Alice"}) ──[:MANAGES {since: 2023}]──→ (:Person {name: "Bob"})

Cypher Query Language Graph Matching

Declarative pattern matching queries relationships visually:

// Discover friends of friends who like Graph Databases but Alice does not know yet
MATCH (alice:Person {name: 'Alice'})-[:FRIEND]->(f:Person)-[:FRIEND]->(fof:Person)
WHERE NOT (alice)-[:FRIEND]->(fof) AND alice <> fof
MATCH (fof)-[:INTERESTED_IN]->(:Topic {name: 'Neo4j'})
RETURN fof.name AS recommendation, count(f) AS mutualFriends
ORDER BY mutualFriends DESC
LIMIT 10;

Graph Data Science (GDS) Algorithms

Executes graph algorithms (PageRank, Community Detection, Shortest Path) natively in memory:

// Run PageRank on projected graph projection
CALL gds.pageRank.stream('fraudNetwork')
YIELD nodeId, score
RETURN gds.util.asNode(nodeId).accountNumber AS account, score
ORDER BY score DESC
LIMIT 20;

Common Patterns

Shortest Path and Relationship Scoring with Cypher

Problem: Finding optimal network paths or fraud rings across deeply interconnected entity networks.

Solution:

Use Cypher shortestPath matching:

MATCH (origin:Account {id: 'acc_123'}), (destination:Account {id: 'acc_999'})
MATCH path = shortestPath((origin)-[:TRANSFERRED_TO*..6]->(destination))
RETURN path,
       length(path) as hops,
       reduce(total = 0, r in relationships(path) | total + r.amount) as totalTransferred;

Best Practices

Do:

Don't:

Troubleshooting

| Error | Cause | Solution |

| :-------------------------------------- | :------------------------------------------------------------------------ | :-------------------------------------------------------------------------------------------- |

| Neo.ClientError.Statement.SyntaxError | Invalid Cypher syntax or outdated keyword. | Check query syntax and wrap keywords in backticks if used as property names. |

| OutOfMemoryError: Java heap space | Unbounded Cartesian product (MATCH (a), (b)) loading millions of paths. | Enforce relationship directions and limit variable-length relationship depths (e.g. *1..4). |

| ConstraintValidationFailed | Attempted to create node violating uniqueness constraint. | Use MERGE instead of CREATE when idempotent upsert behavior is required. |

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.