Rozlišování entit

Graph RAG s LangChain a Neo4j

Adam Cowley

Manager, Developer Education at Neo4j

LLM jsou bezstavové

Volání č. 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.

Volání č. 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 s LangChain a Neo4j

Návrhy entit

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 s LangChain a Neo4j

Návrhy entit

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 s LangChain a Neo4j

Rozlišování entit pomocí grafu

entity_resolution1.jpg

Graph RAG s LangChain a Neo4j

Rozlišování entit pomocí grafu

entity_resolution2.jpg

Graph RAG s LangChain a Neo4j

Rozlišování entit pomocí grafu

entity_resolution3.jpg

Graph RAG s LangChain a Neo4j

Rozlišování entit pomocí grafu

entity_resolution4.jpg

Graph RAG s LangChain a Neo4j

Rozlišování entit pomocí grafu

entity_resolution5.jpg

Graph RAG s LangChain a Neo4j

Identifikace podobných osob

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 s LangChain a Neo4j

Využití vztahů podobnosti

diagram grafu s uzly osob: dva uzly osob propojené vztahem podobnosti, oba se vztahy k uzlům replik

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

Pojďme cvičit!

Graph RAG s LangChain a Neo4j

Preparing Video For Download...