Interroger un graphe de connaissances

Graph RAG avec LangChain et Neo4j

Adam Cowley

Manager, Developer Education at Neo4j

Cypher : appariement de motifs en ASCII-art

 

Un motif de graphe Person a joué dans Movie

 

MATCH


Graph RAG avec LangChain et Neo4j

Cypher : appariement de motifs en ASCII-art

 

Un motif de graphe Person a joué dans Movie

 

MATCH (        )               (       )


Graph RAG avec LangChain et Neo4j

Cypher : appariement de motifs en ASCII-art

 

Un motif de graphe Person a joué dans Movie

 

MATCH ( :Person)               ( :Movie)


Graph RAG avec LangChain et Neo4j

Cypher : appariement de motifs en ASCII-art

 

Un motif de graphe Person a joué dans Movie

 

MATCH ( :Person)-            ->( :Movie)


Graph RAG avec LangChain et Neo4j

Cypher : appariement de motifs en ASCII-art

 

Un motif de graphe Person a joué dans Movie

 

MATCH ( :Person)-[ :ACTED_IN]->( :Movie)


Graph RAG avec LangChain et Neo4j

Cypher : appariement de motifs en ASCII-art

 

Un motif de graphe Person a joué dans Movie

 

MATCH (a:Person)-[r:ACTED_IN]->(m:Movie)


Graph RAG avec LangChain et Neo4j

Filtrer les résultats

 

Un motif de graphe Person a joué dans Movie

 

MATCH (a:Person)-[r:ACTED_IN]->(m:Movie)

WHERE a.name = 'Tom Hanks'
Graph RAG avec LangChain et Neo4j

Contrôler la sortie

 

Un motif de graphe Person a joué dans Movie

 

MATCH (a:Person)-[r:ACTED_IN]->(m:Movie)

WHERE a.name = 'Tom Hanks'
RETURN a.name, m.title AS movieTitle, r.roles AS roles
Graph RAG avec LangChain et Neo4j

Fonctionnement de Cypher

un schéma montrant un nœud au centre d’un réseau et ses relations se déployant pour mettre en évidence le chemin parcouru dans le réseau

Graph RAG avec LangChain et Neo4j

La clause CREATE

La clause CREATE crée un motif dans le graphe

CREATE (p:Person {name: "Adam"})

CREATE (c:Company {name: "Neo4j"})
CREATE (p)-[:WORKS_FOR]->(c)
Graph RAG avec LangChain et Neo4j

La clause MERGE

La clause MERGE recherche ou crée un motif dans le graphe

MERGE (p:Person {name: "Adam"})

MERGE (c:Company {name: "Neo4j"})
Graph RAG avec LangChain et Neo4j

Instructions Cypher dans LangChain

from langchain_neo4j import Neo4jGraph

graph = Neo4jGraph(url=NEO4J_URI, username=NEO4J_USERNAME, password=NEO4J_PASSWORD)
# Exécuter une instruction Cypher
graph.query(

"MATCH (p:Person {name: $name}) RETURN p",
{"name": "Your name"}
)
1 Injection Cypher : https://neo4j.com/developer/kb/protecting-against-cypher-injection/
Graph RAG avec LangChain et Neo4j

Passons à la pratique !

Graph RAG avec LangChain et Neo4j

Preparing Video For Download...