Graph RAG with LangChain and Neo4j
Adam Cowley
Manager, Developer Education at Neo4j
MATCH
MATCH ( ) ( )
MATCH ( :Person) ( :Movie)
MATCH ( :Person)- ->( :Movie)
MATCH ( :Person)-[ :ACTED_IN]->( :Movie)
MATCH (a:Person)-[r:ACTED_IN]->(m:Movie)
MATCH (a:Person)-[r:ACTED_IN]->(m:Movie)WHERE a.name = 'Tom Hanks'
MATCH (a:Person)-[r:ACTED_IN]->(m:Movie)WHERE a.name = 'Tom Hanks'RETURN a.name, m.title AS movieTitle, r.roles AS roles

The CREATE clause creates a pattern in the graph
CREATE (p:Person {name: "Adam"})CREATE (c:Company {name: "Neo4j"})CREATE (p)-[:WORKS_FOR]->(c)
The MERGE clause will find or create a pattern in the graph
MERGE (p:Person {name: "Adam"})MERGE (c:Company {name: "Neo4j"})
from langchain_neo4j import Neo4jGraph
graph = Neo4jGraph(url=NEO4J_URI, username=NEO4J_USERNAME, password=NEO4J_PASSWORD)
# Execute a Cypher statement graph.query("MATCH (p:Person {name: $name}) RETURN p",{"name": "Your name"})
Graph RAG with LangChain and Neo4j