使用 LangChain 與 Neo4j 的 Graph RAG
Adam Cowley
Manager, Developer Education at Neo4j
列出以下文字中的角色:
{text}
此文字中的角色為:
* Sampson - Capulet 家僕。
* Gregory - Capulet 家僕。
* Abram - Montague 家僕。
* Balthasar - Montague 家僕。
列出以下文字中的角色:
{text}
此文字列出的角色為:
* Sampson - Capulet 家僕
* Gregory - Capulet 家僕
* Abram - Montague 家僕
* Benvolio - Montague 家僕
examples = graph.query("""
MATCH (c:Character)-[:BELONGS_TO]->(f:Family)
RETURN c.id AS id, c.name AS name, f.name AS belongsToFamily
""")
for character in example:
print(character)
{"id": "romeo-montague", "name": "Romeo", "family": "Montague"},{"id": "juliet-capulet", "name": "Juliet", "family": "Capulet"},{"id": "sampson", "name": "Sampson", "family": "Capulet"},...
SystemMessagePromptTemplate.from_template(""" 擷取下列實體所對應的資訊。忽略不在下列清單中的角色:{examples}""",partial_variables={"examples": [ dict(e) for e in examples ]})





MATCH path = (c:Character {id: "romeo-capulet"})-[r]-(inCommon:Character),(inCommon)-[r2]-(other:Character)RETURN c.id AS id, c.name AS name, other.name AS otherName, other.id AS otherId,c.name = other.name AS shareName,EXISTS { (c)-[:BELONGS_TO]->(:Family)<-[:BELONGS_TO]-(other) } AS belongToFamily,count(*) as nodesInCommon,collect(path) AS pathsORDER BY nodesInCommon DESC LIMIT 10

MATCH (:Character {id: 'romeo-montague'})-[:SIMILAR_TO*0..1]-(character),
(character)-[:HAS_LINE]->(line),
(line)-[:SPOKEN_TO]->(target)
RETURN character, line
使用 LangChain 與 Neo4j 的 Graph RAG