Explore your Knowledge Graph

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.

A graph data model showing Document
  1. Each Document node represents a document or text source uploaded to the LLM Graph Builder.

  2. The Document is split into Chunk nodes, identified by FIRST_CHUNK and PART_OF relationships.

  3. The LLM processes the chunks and Entity nodes extracted. The graph connects the Entity nodes to the Chunk nodes using the HAS_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?

cypher
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.

A graph created from the lesson text

You can modify the query to return the label and ID of the entities.

cypher
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

["Concept"]

"Private Information"

["Concept"]

"Training Data"

["Algorithm"]

"Generative Ai"

["Model"]

"Graph-Based Model"

…​

The results will vary; an LLM extracted the data, and the results have inherent variability.

By matching a path from the document to the entities, you can see how the entities relate to the document.

cypher
MATCH (d:Document
    {fileName:'llm-fundamentals_1-introduction_1-neo4j-and-genai.pdf'}
    )
MATCH p = (d)-[*0..3]-(e)
RETURN p

The [*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.
A graph created from the lesson text

You can see what documents contain a specific entity.

cypher
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.