In this lesson, you will explore the knowledge graph created by the LLM Graph Builder.
Model
The structure created by the LLM Graph Builder is a good template for a knowledge graph that you can use in your projects.
-
Each
Document
node represents a document or text source uploaded to the LLM Graph Builder. -
The
Document
is split intoChunk
nodes, identified byFIRST_CHUNK
andPART_OF
relationships. -
The LLM processes the chunks and
Entity
nodes extracted. The graph connects theEntity
nodes to theChunk
nodes using theHAS_ENTITY
relationship.
The LLM may also extract relationships between the entities, and the graph will hold relationships between the Entity
nodes.
This model allows you to relate the entities within the knowledge graph to the source documents they refer to.
Explore
Review this Cypher query before running it. What do you expect to see?
MATCH (d:Document
{fileName:'llm-fundamentals_1-introduction_1-neo4j-and-genai.pdf'}
)
MATCH (d)<-[:PART_OF]-(c:Chunk)-[:HAS_ENTITY]->(e)
RETURN e
Click here to reveal the result
Running this query will return all the entities extracted from the document llm-fundamentals_1-introduction_1-neo4j-and-genai.pdf
.
You can modify the query to return the label and ID of the entities.
MATCH (d:Document
{fileName:'llm-fundamentals_1-introduction_1-neo4j-and-genai.pdf'}
)
MATCH (d)<-[:PART_OF]-(c:Chunk)-[:HAS_ENTITY]->(e)
RETURN labels(e) as labels, e.id as entity
The results provide detail of the entities extracted from the document.
labels | entity |
---|---|
|
|
|
|
|
|
|
|
|
By matching a path from the document to the entities, you can see how the entities relate to the document.
MATCH (d:Document
{fileName:'llm-fundamentals_1-introduction_1-neo4j-and-genai.pdf'}
)
MATCH p = (d)-[*0..3]-(e)
RETURN p
[*0..3]
pattern matches paths of up to three relationships between the document and the entities.
Increasing the number will return more complex paths, but the query will take longer.You can see what documents contain a specific entity.
MATCH (e:Concept {id: "Hallucination"})<-[:HAS_ENTITY]-(c:Chunk)-[:PART_OF]->(d:Document)
RETURN DISTINCT d.fileName
Take some time to experiment with the data in your knowledge graph. The final module will teach you more about querying a knowledge graph.
Experiment
Before moving on, experiment with the LLM Graph Builder and explore the knowledge graph.
You could:
-
Generate a knowledge graph for all the PDF documents for the course.
-
Add relevant Wikipedia articles that would supplement the course content.
-
Explore the entities extracted from the documents.
The final module will teach you more about querying a knowledge graph.
When ready, continue to the next module to learn how to create a knowledge graph.
Summary
In this lesson, you explored the knowledge graph.
In the next module, you will explore how to build a knowledge graph using Python, LangChain and OpenAI.