Rozwiązywanie encji

Graph RAG z LangChain i Neo4j

Adam Cowley

Manager, Developer Education at Neo4j

LLM-y są bezstanowe

Wywołanie nr 1

List the characters in the following text:

{text}
The characters in this text are:

* Sampson - A servant of the Capulet household.
* Gregory - Another servant of the Capulet household.
* Abram - A servant of the Montague household.
* Balthasar - A servant of the Montague household.

Wywołanie nr 2

List the characters in the following text:

{text}
The characters listed in this text are:

* Sampson - Servant Capulet
* Gregory - Servant of Capulet
* Abram - Servant of the Montague
* Benvolio - Servant of the Montague
Graph RAG z LangChain i Neo4j

Sugestie encji

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"},
...
Graph RAG z LangChain i Neo4j

Sugestie encji

SystemMessagePromptTemplate.from_template("""
Extract the information that corresponds to the following entities.


Ignore any characters that aren't included in the following list:
{examples}
""",
partial_variables={"examples": [ dict(e) for e in examples ]}
)
Graph RAG z LangChain i Neo4j

Rozwiązywanie encji na grafie

entity_resolution1.jpg

Graph RAG z LangChain i Neo4j

Rozwiązywanie encji na grafie

entity_resolution2.jpg

Graph RAG z LangChain i Neo4j

Rozwiązywanie encji na grafie

entity_resolution3.jpg

Graph RAG z LangChain i Neo4j

Rozwiązywanie encji na grafie

entity_resolution4.jpg

Graph RAG z LangChain i Neo4j

Rozwiązywanie encji na grafie

entity_resolution5.jpg

Graph RAG z LangChain i Neo4j

Wyszukiwanie podobnych postaci

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 paths
ORDER BY nodesInCommon DESC LIMIT 10
Graph RAG z LangChain i Neo4j

Relacje podobieństwa w praktyce

diagram grafu z węzłami postaci — dwa węzły postaci połączone relacją podobieństwa, obie powiązane z węzłami kwestii

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

Czas na praktykę!

Graph RAG z LangChain i Neo4j

Preparing Video For Download...