2024-01-02 21:47:11 +00:00
|
|
|
from langchain_community.graphs import Neo4jGraph
|
2023-10-26 01:47:42 +00:00
|
|
|
|
|
|
|
graph = Neo4jGraph()
|
|
|
|
|
2023-10-29 22:50:09 +00:00
|
|
|
# Import sample data
|
2023-10-26 01:47:42 +00:00
|
|
|
graph.query(
|
|
|
|
"""
|
|
|
|
MERGE (m:Movie {name:"Top Gun"})
|
|
|
|
WITH m
|
|
|
|
UNWIND ["Tom Cruise", "Val Kilmer", "Anthony Edwards", "Meg Ryan"] AS actor
|
|
|
|
MERGE (a:Person {name:actor})
|
|
|
|
MERGE (a)-[:ACTED_IN]->(m)
|
|
|
|
"""
|
|
|
|
)
|
|
|
|
|
|
|
|
# Create full text index for entity matching
|
|
|
|
# on Person and Movie nodes
|
|
|
|
graph.query(
|
|
|
|
"CREATE FULLTEXT INDEX entity IF NOT EXISTS"
|
|
|
|
" FOR (m:Movie|Person) ON EACH [m.title, m.name]"
|
|
|
|
)
|