Hands-On GraphRAG Workshop
Building Smarter GenAI
Apps with Knowledge
Graphs
Emil Pastor | Head of Solution Engineering
Samko Yun | Sr. Solution Engineer
Darren Wood | Sr. Solution Engineer
Muddassir Zaidi | Sr. Consulting Engineer
Angelo Bueti | Professional Services Manager
● Ask questions straight away, this is an
interactive session
● Raise your hand if you are stuck
● Have fun
Workshop Rules
Before We Start
1. Connect to your Aura instance through
workspace workspace.neo4j.io
2. Open the notebook in Colab (needs a
google account!)
github.com/neo4j-product-examples/
genai-workshop
3. open genai-workshop.ipynb
Agenda
Introduction
1. Introduction to Neo4j & GenAI
2. GenAI App Demo! (what we will build today)
Hands On
1. Knowledge Graph Basics
2. Vector Search
3. Semantic Search with Graph Patterns
4. Enrichment with Graph DS & ML
5. LLM Powered Content Generator
Retrieval-Augmented Generation Is
Becoming an Industry Standard
RAG augments LLMs by
retrieving up-to-date external
data to inform responses:
● Provide domain-specific,
relevant responses
● Reduce hallucinations with
verified data
● Enable traceability back
to sources
Find similar documents
and content
Identify entities associated to
content and patterns in
connected data
Improve & enrich GenAI
insights. Discover new
relationships and entities
Unify vector search, knowledge graph, and data science to
improve RAG quality and effectiveness
Vector
Search
Graph Data
Science
Knowledge
Graph
GraphRAG with Neo4j
Today
We Build an LLM
Chain with
GraphRAG
This is Eva
For her birthday, Eva wants a
Halter Neck Top
How do you choose
what to buy?
For her birthday, Eva wants a
Halter Neck Top
How do you choose
what to buy?
1. Get a list of Halter Neck Top
2. Match the Halter Neck Top
for Eva
3. Accessorize or add
another item
This is Eva
This Requires:
1. Data: Kaggle H&M
2. Search & Retrieval
3. Context for Personalization
4. Recommendation Engine
5. LLM Powered Content
Generator
At Scale: Let’s Build an AI
Fashion Assistant
Solution: LLMs and Knowledge Graphs
Knowledge
Context
Enrichment
Language
Reasoning
Creativity
KGs LLMs
+
BETTER TOGETHER
We'll Build a Targeted, Personalized
Content Generator
Structured
Purchase Data
Neo4j Inc. All rights reserved 2024
13
Demo Architecture
Graph Data Science
Unstructured
Product
Descriptions
INGEST
INGEST
Python Notebook
Journey
1
Knowledge Graph
(Kaggle H&M Dataset)
2
Vector Search
(Initial Retrieval)
3
Semantic Search with
Graph Patterns
(Personalization)
4
Graph DS & ML
(Recommendations)
LLM Powered Content
Generator & Fashion
Assistant
5
Now We Start
1. Connect to your Aura instance through
workspace workspace.neo4j.io
2. Open the notebook in Colab (needs a
google account!)
github.com/neo4j-product-examples/
genai-workshop
3. open genai-workshop.ipynb
1. Knowledge Graph Basics
1
Knowledge Graph
(Kaggle H&M Dataset)
2
Vector Search
(Initial Retrieval)
3
Semantic Search with
Graph Patterns
(Personalization)
4
Graph DS & ML
(Recommendations)
LLM Powered Content
Generator & Fashion
Assistant
5
Neo4j Inc. All rights reserved 2024
Name: “Andre”
Born: May 29, 1970
Twitter: “@dan”
Name: “Mica”
Born: Dec 5, 1975
Brand “Volvo”
Model: “V70”
Description:
Since:
Jan 10, 2011
LOVES
KNOWS
Person
Person
LIVES WITH
O
W
N
S
KNOWS
D
R
I
V
E
S
Nodes represent entities in the
graph
17
Knowledge Graph Components
Relationships represent
associations or interactions
between nodes
Properties represent attributes of
nodes or relationships
Car
Neo4j Inc. All rights reserved 2024
18
Cypher: A Powerful & Expressive Query Language
MARRIED_TO
Person
name: ‘Dan’
spouse
MATCH (p:Person {name:“Dan”} ) -[:MARRIED_TO]-> (spouse)
NODE RELATIONSHIP TYPE
LABEL PROPERTY
NODE
RETURN p.name as husband, spouse
VARIABLE VARIABLE
© 2024 Neo4j, Inc. All rights
reserved.
19
We are turning this:
Into this :
Data Model
customerId
tDat
Color
name
type
group
description
Go to Notebook
Knowledge Graph Basics
2. Vector Search
1
Knowledge Graph
(Kaggle H&M Dataset)
2
Vector Search
(Initial Retrieval)
3
Semantic Search with
Graph Patterns
(Personalization)
4
Graph DS & ML
(Recommendations)
LLM Powered Content
Generator & Fashion
Assistant
5
What are Embeddings?
● A type of data compression
● Transform messy data (text, images, audio,
etc.) into a compact format for ML algorithms
● Most often numeric vectors (a.k.a arrays) with
100s or 1000s of elements
● Preserve information such that “similar” items
have proportionally “similar” embedding
vectors
● Similarity is measured with vector algorithms
(cosine, euclidean, etc.)
Graph Graph Model
Graph Vector
Embeddings
What Does“Similarity” Mean?
It Depends:
● Text Embeddings => Semantic similarity, the meaning behind a text
sequence
● Graph Embeddings => Similarity in position or structure in a graph-
can have semantic meaning too
What will we use embeddings for?
● (Now) Vector search using text embeddings
● (Later) Recommendations using graph node embeddings
Search & Vectors in Neo4j
Neo4j makes search efficient through a variety of indexes including
● Range: General index for predicates based on equality and range.
● Point: Predicts on geospatial points like distance bounding boxes, etc.
● Text: Predicates on strings like contains, ends with, etc.
● FullText: Text search based on tokenization and analyzers
● Vector: ANN (Approximate Nearest Neighbor) search on vectors
How is similarity measured
vector point
query
nearest 4
The vector index allows us to query vectors on larger datasets.
It uses HNSW to perform k-ANN queries
Euclidean
Distance based
Cosine
Direction / angle based
LangChain Why & How
• GenAI orchestration Framework
• Many out-of-the-box components
and integrations
• Prebuilt chains and agents
Go to Notebook
Vector Search
3. Semantic Search with Graph Patterns
1
Knowledge Graph
(Kaggle H&M Dataset)
2
Vector Search
(Initial Retrieval)
3
Semantic Search with
Graph Patterns
(Personalization)
4
Graph DS & ML
(Recommendations)
LLM Powered Content
Generator & Fashion
Assistant
5
Neo4j & Semantic Search
Vector Similarity
Search
Graph Pattern
Matching
Knowledge Graph
DS/ML
Find relevant documents and
content for user queries.
Find entities associated to
content. Identify patterns in
connected data.
Improve search relevance &
insights by enhancing a
Knowledge Graph. Use graph
algorithms and ML to discover
new relationships, entities, and
groups.
Vector Search Graph Database
HNSW
Graph Data Science
Semantic Search + Traversal
Purchases in
common
Customers
Target
Customer
Semantically
Similar
Products
Go to Notebook
Semantic Search with Graph Patterns
4. Graph Data Science & ML
1
Knowledge Graph
(Kaggle H&M Dataset)
2
Vector Search
(Initial Retrieval)
3
Semantic Search with
Graph Patterns
(Personalization)
4
Graph DS & ML
(Recommendations)
LLM Powered Content
Generator & Fashion
Assistant
5
Bring the context of your
connected data into a format that
other pipelines can ingest.
The Largest Catalog of
Graph Algorithms
Native Graph Catalog and
Analytics Workspace
Graph Embeddings for ML
&AI
Pathfinding
& Search Centrality
Community
Detection
Machine
Learning
Link
Prediction Similarity
and
more …
Iterate fast with different data sets,
models, and version trained models.
Over 65 pretuned,
parallelized algorithms.
Neo4j Graph Data Science (GDS)
Node
Embedding
Vector representation of a node
that summarizes it’s position in the
graph, local neighborhood
structure, and/or node features
K-Nearest
Neighbor (KNN)
w/ Node
Embeddings
Draw connections between highly
interconnected nodes and/or those
that have similar roles in the graph 0.2
0.3
0.6
-0.6
0.1
0.4
0.5
-0.4
-0.1
0.5
0.4
-0.4
Go to Notebook
Graph Data Science & ML
5. LLM Powered Content Generator
1
Knowledge Graph
(Kaggle H&M Dataset)
2
Vector Search
(Initial Retrieval)
3
Semantic Search with
Graph Patterns
(Personalization)
4
Graph DS & ML
(Recommendations)
LLM Powered Content
Generator & Fashion
Assistant
5
Prompting the LLM
You are a personal assistant named Sally for a fashion, home, and beauty company called HRM.Write an
engaging email to {customerName} , one of your customers, to promote and summarize products relevant for
them given:
- The current season / time of year: {timeOfYear}
- Recent searches/interests: {customerInterests}
Please only mention the products listed below.Do not come up with or add any new products to the
list.Each product comes with an https `url` field. Make sure to provide that https url with descriptive
name text in markdown for each product.
# RelevantProducts:
These are products from the HRM store the customer may be interested in based
on their recent searches/interests: {customerInterests}
{searchProds}
# Customer May Also Be Interested In the Following
The below candidates are recommended based on the shared purchase patterns of other customers in the HRM
database.
Select the best 4 to 5 product subset from the context that best match the time of year: {timeOfYear}
and to pair with the RelevantProducts above. For example, even if scarfs are listed here, they may not
be appropriate for a summer time of year so best not to include those.
{recProds}
LangChain Chain
customerId
searchPrompt Personalized search
Recommendations
timeOfYear
customerName
prompt llm personalized
email
searchProds
recProds
{
searchProds: (searchPrompt , customer_id)| personalizedSearch
recProds:customer_id | recommendations
customerName:
timeOfYear:
}
prompt | llm | outputParser
Go to Notebook
LLM Powered Content Generator
Integrating AI with
knowledge graphs for
smarter supply chain
management
Merging structured and
unstructured data for
efficient operations
Converting vast amounts of
unstructured data into
actionable knowledge
Leveraging AI
for customized content
at scale
Real-World GenAI Breakthroughs
Powered by Neo4j
Banking & Financial
Services
Technology Telecommunications Energy
E-Commerce
Health & Life
Sciences
1,700+ Organizations Use Neo4j
Thank you!

Hands-On GraphRAG Workshop: GraphSummit Melbourne 2024

  • 1.
    Hands-On GraphRAG Workshop BuildingSmarter GenAI Apps with Knowledge Graphs Emil Pastor | Head of Solution Engineering Samko Yun | Sr. Solution Engineer Darren Wood | Sr. Solution Engineer Muddassir Zaidi | Sr. Consulting Engineer Angelo Bueti | Professional Services Manager
  • 2.
    ● Ask questionsstraight away, this is an interactive session ● Raise your hand if you are stuck ● Have fun Workshop Rules
  • 3.
    Before We Start 1.Connect to your Aura instance through workspace workspace.neo4j.io 2. Open the notebook in Colab (needs a google account!) github.com/neo4j-product-examples/ genai-workshop 3. open genai-workshop.ipynb
  • 4.
    Agenda Introduction 1. Introduction toNeo4j & GenAI 2. GenAI App Demo! (what we will build today) Hands On 1. Knowledge Graph Basics 2. Vector Search 3. Semantic Search with Graph Patterns 4. Enrichment with Graph DS & ML 5. LLM Powered Content Generator
  • 5.
    Retrieval-Augmented Generation Is Becomingan Industry Standard RAG augments LLMs by retrieving up-to-date external data to inform responses: ● Provide domain-specific, relevant responses ● Reduce hallucinations with verified data ● Enable traceability back to sources
  • 6.
    Find similar documents andcontent Identify entities associated to content and patterns in connected data Improve & enrich GenAI insights. Discover new relationships and entities Unify vector search, knowledge graph, and data science to improve RAG quality and effectiveness Vector Search Graph Data Science Knowledge Graph GraphRAG with Neo4j
  • 7.
    Today We Build anLLM Chain with GraphRAG
  • 8.
    This is Eva Forher birthday, Eva wants a Halter Neck Top How do you choose what to buy?
  • 9.
    For her birthday,Eva wants a Halter Neck Top How do you choose what to buy? 1. Get a list of Halter Neck Top 2. Match the Halter Neck Top for Eva 3. Accessorize or add another item This is Eva
  • 10.
    This Requires: 1. Data:Kaggle H&M 2. Search & Retrieval 3. Context for Personalization 4. Recommendation Engine 5. LLM Powered Content Generator At Scale: Let’s Build an AI Fashion Assistant
  • 11.
    Solution: LLMs andKnowledge Graphs Knowledge Context Enrichment Language Reasoning Creativity KGs LLMs + BETTER TOGETHER
  • 12.
    We'll Build aTargeted, Personalized Content Generator
  • 13.
    Structured Purchase Data Neo4j Inc.All rights reserved 2024 13 Demo Architecture Graph Data Science Unstructured Product Descriptions INGEST INGEST Python Notebook
  • 14.
    Journey 1 Knowledge Graph (Kaggle H&MDataset) 2 Vector Search (Initial Retrieval) 3 Semantic Search with Graph Patterns (Personalization) 4 Graph DS & ML (Recommendations) LLM Powered Content Generator & Fashion Assistant 5
  • 15.
    Now We Start 1.Connect to your Aura instance through workspace workspace.neo4j.io 2. Open the notebook in Colab (needs a google account!) github.com/neo4j-product-examples/ genai-workshop 3. open genai-workshop.ipynb
  • 16.
    1. Knowledge GraphBasics 1 Knowledge Graph (Kaggle H&M Dataset) 2 Vector Search (Initial Retrieval) 3 Semantic Search with Graph Patterns (Personalization) 4 Graph DS & ML (Recommendations) LLM Powered Content Generator & Fashion Assistant 5
  • 17.
    Neo4j Inc. Allrights reserved 2024 Name: “Andre” Born: May 29, 1970 Twitter: “@dan” Name: “Mica” Born: Dec 5, 1975 Brand “Volvo” Model: “V70” Description: Since: Jan 10, 2011 LOVES KNOWS Person Person LIVES WITH O W N S KNOWS D R I V E S Nodes represent entities in the graph 17 Knowledge Graph Components Relationships represent associations or interactions between nodes Properties represent attributes of nodes or relationships Car
  • 18.
    Neo4j Inc. Allrights reserved 2024 18 Cypher: A Powerful & Expressive Query Language MARRIED_TO Person name: ‘Dan’ spouse MATCH (p:Person {name:“Dan”} ) -[:MARRIED_TO]-> (spouse) NODE RELATIONSHIP TYPE LABEL PROPERTY NODE RETURN p.name as husband, spouse VARIABLE VARIABLE
  • 19.
    © 2024 Neo4j,Inc. All rights reserved. 19 We are turning this:
  • 20.
  • 21.
  • 22.
  • 23.
    2. Vector Search 1 KnowledgeGraph (Kaggle H&M Dataset) 2 Vector Search (Initial Retrieval) 3 Semantic Search with Graph Patterns (Personalization) 4 Graph DS & ML (Recommendations) LLM Powered Content Generator & Fashion Assistant 5
  • 24.
    What are Embeddings? ●A type of data compression ● Transform messy data (text, images, audio, etc.) into a compact format for ML algorithms ● Most often numeric vectors (a.k.a arrays) with 100s or 1000s of elements ● Preserve information such that “similar” items have proportionally “similar” embedding vectors ● Similarity is measured with vector algorithms (cosine, euclidean, etc.) Graph Graph Model Graph Vector Embeddings
  • 25.
    What Does“Similarity” Mean? ItDepends: ● Text Embeddings => Semantic similarity, the meaning behind a text sequence ● Graph Embeddings => Similarity in position or structure in a graph- can have semantic meaning too
  • 26.
    What will weuse embeddings for? ● (Now) Vector search using text embeddings ● (Later) Recommendations using graph node embeddings
  • 27.
    Search & Vectorsin Neo4j Neo4j makes search efficient through a variety of indexes including ● Range: General index for predicates based on equality and range. ● Point: Predicts on geospatial points like distance bounding boxes, etc. ● Text: Predicates on strings like contains, ends with, etc. ● FullText: Text search based on tokenization and analyzers ● Vector: ANN (Approximate Nearest Neighbor) search on vectors
  • 28.
    How is similaritymeasured vector point query nearest 4 The vector index allows us to query vectors on larger datasets. It uses HNSW to perform k-ANN queries Euclidean Distance based Cosine Direction / angle based
  • 29.
    LangChain Why &How • GenAI orchestration Framework • Many out-of-the-box components and integrations • Prebuilt chains and agents
  • 30.
  • 31.
    3. Semantic Searchwith Graph Patterns 1 Knowledge Graph (Kaggle H&M Dataset) 2 Vector Search (Initial Retrieval) 3 Semantic Search with Graph Patterns (Personalization) 4 Graph DS & ML (Recommendations) LLM Powered Content Generator & Fashion Assistant 5
  • 32.
    Neo4j & SemanticSearch Vector Similarity Search Graph Pattern Matching Knowledge Graph DS/ML Find relevant documents and content for user queries. Find entities associated to content. Identify patterns in connected data. Improve search relevance & insights by enhancing a Knowledge Graph. Use graph algorithms and ML to discover new relationships, entities, and groups. Vector Search Graph Database HNSW Graph Data Science
  • 33.
    Semantic Search +Traversal Purchases in common Customers Target Customer Semantically Similar Products
  • 34.
    Go to Notebook SemanticSearch with Graph Patterns
  • 35.
    4. Graph DataScience & ML 1 Knowledge Graph (Kaggle H&M Dataset) 2 Vector Search (Initial Retrieval) 3 Semantic Search with Graph Patterns (Personalization) 4 Graph DS & ML (Recommendations) LLM Powered Content Generator & Fashion Assistant 5
  • 36.
    Bring the contextof your connected data into a format that other pipelines can ingest. The Largest Catalog of Graph Algorithms Native Graph Catalog and Analytics Workspace Graph Embeddings for ML &AI Pathfinding & Search Centrality Community Detection Machine Learning Link Prediction Similarity and more … Iterate fast with different data sets, models, and version trained models. Over 65 pretuned, parallelized algorithms. Neo4j Graph Data Science (GDS)
  • 38.
    Node Embedding Vector representation ofa node that summarizes it’s position in the graph, local neighborhood structure, and/or node features
  • 39.
    K-Nearest Neighbor (KNN) w/ Node Embeddings Drawconnections between highly interconnected nodes and/or those that have similar roles in the graph 0.2 0.3 0.6 -0.6 0.1 0.4 0.5 -0.4 -0.1 0.5 0.4 -0.4
  • 40.
    Go to Notebook GraphData Science & ML
  • 41.
    5. LLM PoweredContent Generator 1 Knowledge Graph (Kaggle H&M Dataset) 2 Vector Search (Initial Retrieval) 3 Semantic Search with Graph Patterns (Personalization) 4 Graph DS & ML (Recommendations) LLM Powered Content Generator & Fashion Assistant 5
  • 42.
    Prompting the LLM Youare a personal assistant named Sally for a fashion, home, and beauty company called HRM.Write an engaging email to {customerName} , one of your customers, to promote and summarize products relevant for them given: - The current season / time of year: {timeOfYear} - Recent searches/interests: {customerInterests} Please only mention the products listed below.Do not come up with or add any new products to the list.Each product comes with an https `url` field. Make sure to provide that https url with descriptive name text in markdown for each product. # RelevantProducts: These are products from the HRM store the customer may be interested in based on their recent searches/interests: {customerInterests} {searchProds} # Customer May Also Be Interested In the Following The below candidates are recommended based on the shared purchase patterns of other customers in the HRM database. Select the best 4 to 5 product subset from the context that best match the time of year: {timeOfYear} and to pair with the RelevantProducts above. For example, even if scarfs are listed here, they may not be appropriate for a summer time of year so best not to include those. {recProds}
  • 43.
    LangChain Chain customerId searchPrompt Personalizedsearch Recommendations timeOfYear customerName prompt llm personalized email searchProds recProds { searchProds: (searchPrompt , customer_id)| personalizedSearch recProds:customer_id | recommendations customerName: timeOfYear: } prompt | llm | outputParser
  • 44.
    Go to Notebook LLMPowered Content Generator
  • 45.
    Integrating AI with knowledgegraphs for smarter supply chain management Merging structured and unstructured data for efficient operations Converting vast amounts of unstructured data into actionable knowledge Leveraging AI for customized content at scale Real-World GenAI Breakthroughs Powered by Neo4j
  • 46.
    Banking & Financial Services TechnologyTelecommunications Energy E-Commerce Health & Life Sciences 1,700+ Organizations Use Neo4j
  • 47.