Graph Databases:
Data Storage with Context
Jennifer Reif
[email protected]
@JMHReif
github.com/JMHReif
jmhreif.com
linkedin.com/in/jmhreif
Photo by Tomasz Frankowski on Unsplash
Slide 2
Slide 2 text
Who is Jennifer Reif?
Developer Advocate, Neo4j
• Continuous learner
• Technical speaker
• Tech blogger, podcaster
• Other: geek
Jennifer Reif
[email protected]
@JMHReif
github.com/JMHReif
jmhreif.com
linkedin.com/in/jmhreif
Slide 3
Slide 3 text
What is a graph?
Jennifer Jacob
??
Slide 4
Slide 4 text
What is a graph?
Company
Jennifer Jacob
WORKED_FOR WORKED_FOR
Slide 5
Slide 5 text
What is a graph?
Company
Jennifer Jacob
School
W
ORKED_FOR WORKED_FOR
ATTENDED ATTENDED
Slide 6
Slide 6 text
What is a graph?
Degree Degree
Company
Jennifer Jacob
School
ATTENDED ATTENDED
W
ORKED_FOR WORKED_FOR
EN
RO
LLED_IN
ENROLLED_IN
Slide 7
Slide 7 text
What is a graph?
Adrian
Degree Degree
Company
Jennifer Jacob
School
ATTENDED ATTENDED
W
ORKED_FOR WORKED_FOR
EN
RO
LLED_IN
ENROLLED_IN
ENROLLED_IN
Degree
C
O
M
PLETED
COM
PLETED
Slide 8
Slide 8 text
What is a graph?
Person
Degree Degree
Company
Person Person
School
ATTENDED ATTENDED
W
ORKED_FOR WORKED_FOR
EN
RO
LLED_IN
ENROLLED_IN
ENROLLED_IN
Degree
C
O
M
PLETED
COM
PLETED
Edward Jones
Jacob
Jennifer SIUE
Music
CMIS CS
Adrian
Slide 9
Slide 9 text
What is a graph?
Answers through relationships
• How many coworkers
shared classes/degrees?
• What are common
degree journeys?
• How many alumni re-
enroll for higher
degrees?
• Who else went to a
school and works for
company?
Person
Degree Degree
Company
Person Person
School
ATTENDED ATTENDED
W
ORKED_FOR WORKED_FOR
EN
RO
LLED_IN
ENROLLED_IN
ENROLLED_IN
Degree
C
O
M
PLETED
COM
PLETED
Edward Jones
Jacob
Jennifer SIUE
Music
CMIS CS
Adrian
Slide 10
Slide 10 text
Nodes (vertices)
Objects or entities
• Can have labels
• May have properties
Person
Degree Degree
Company
Person Person
School
Degree
Edward Jones
Jacob
Jennifer SIUE
Music
CMIS CS
Adrian
Slide 11
Slide 11 text
Relationships (edges)
Connect entities
• Must have type (label)
• Must have direction
• May have properties
Person
Degree Degree
Company
Person Person
School
ATTENDED ATTENDED
W
ORKED_FOR WORKED_FOR
EN
RO
LLED_IN
ENROLLED_IN
ENROLLED_IN
Degree
C
O
M
PLETED
COM
PLETED
Edward Jones
Jacob
Jennifer SIUE
Music
CMIS CS
Adrian
Slide 12
Slide 12 text
Example: Logistics
Home
Slide 13
Slide 13 text
Logistics
• Where
fi
rst?
• Depends on when ready to
leave house
Home
School
Opens: 08:00
Donation
Opens: 09:00
Shipping
Opens: 10:00
Grocery
Opens: 07:00
Slide 14
Slide 14 text
Logistics
Criteria
• Where is time critical?
• Personal preferences for
refrigerated food?
• How long at each store?
Music
Home
School
Opens: 08:00
Donation
Opens: 09:00
Shipping
Opens: 10:00
Grocery
Opens: 07:00
WENT_1
W
ENT_2
WENT_3
WENT_4
W
ENT_5
WENT_6
Slide 15
Slide 15 text
Answer questions
Habits/preferences
• E
ffi
ciency improvements?
• Adding stop? Where/time?
• Share load across more people?
• Distance and location
calculations?
Music
Home
School
Opens: 08:00
Donation
Opens: 09:00
Shipping
Opens: 10:00
Grocery
Opens: 07:00
WENT_1
W
ENT_2
WENT_3
WENT_4
W
ENT_5
WENT_6
Slide 16
Slide 16 text
Other use cases
• Fraud detection
• Identity and access management
• Recommendations
• Supply chain
Slide 17
Slide 17 text
Graphs add context and meaning
Not just point-to-point, but HOW they connect
Slide 18
Slide 18 text
Data model
Slide 19
Slide 19 text
One model to rule them all…
Conceptual = Logical = Physical data model
Slide 20
Slide 20 text
One model to rule them all…
Conceptual = Logical = Physical data model
Slide 21
Slide 21 text
Query language
Slide 22
Slide 22 text
Cypher
GQL-compliant
• Functional and visual
• Based on ASCII art
• Declarative
• Focus on patterns
A B
LIKES
MATCH (A)-[:LIKES]->(B)
Slide 23
Slide 23 text
Cypher: write
All about patterns
Jennifer Neo4j
WORKS_FOR
CREATE (:Person { name: ‘Jennifer’}) -[:WORKS_FOR]-> (:Company { name: ‘Neo4j’})
NODE
PROPERTY
NODE
PROPERTY
LABEL LABEL
Slide 24
Slide 24 text
Cypher: read
All about patterns
Jennifer Neo4j
WORKS_FOR
MATCH (:Person { name: ‘Jennifer’} ) -[:WORKS_FOR]-> ( whom )
RETURN whom
Slide 25
Slide 25 text
Let’s explore!
Slide 26
Slide 26 text
Visualization, Data Science, and
more!
Slide 27
Slide 27 text
Integrations
Lots of options!
• Cloud
• Visualization
• Data transportation
• Data science
• Applications
• Administration, ops, monitoring
Slide 28
Slide 28 text
Purchasing system
Orders, products, suppliers, etc
• Easily
fi
nd unusual patterns
• Optimize routes network
• Pass bits on to other systems
• Pinpoint…
• Improvements for inventory
• Weak points in supply chain
• In
fl
uential products/customers
Other
Social, interactions, etc
• Easily navigate human interaction
• Understand collaboration
• Track behavior, journeys
• Pinpoint…
• User journeys, collabs
• Communities
• In
fl
uential people, events
Slide 31
Slide 31 text
What about AI?
Slide 32
Slide 32 text
Throw an LLM at it
Doesn’t often work
• LLM strengths:
• human-consumable data
• general/public info
• LLM weaknesses:
• context/big picture
• private knowledge
• Solo LLM = great -> integrated LLM = more great?
Slide 33
Slide 33 text
RAG architecture
• Retrieval
• Data retrieved from external source
• Augmented
• Augments response with facts
• Generation
• Response in natural language
Prompt + Relevant Information
LLM API LLM
Chat API
User
Database Search
Prompt Response
Relevant Results
/ Documents
2
3
1
Database
Slide 34
Slide 34 text
Embeddings / Vectors
Convert data to a point in space
• Series of numbers
• 100s or 1000s of dimensions
• Dimension = interesting feature / characteristic
Slide 35
Slide 35 text
Vectors in the physical realm
https://www.mathsisfun.com/algebra/vectors.html
Slide 36
Slide 36 text
Vectors in the technical realm
Kings and Queens
king − man + woman ≈ queen
king
man wom
an
1
king
man
wom
an
2
queen?
3
Slide 37
Slide 37 text
How do we search the vectors?
Similarity search
• Expensive queries (compare to every vector)
• Approximate nearest neighbor (k-ANN)
• Example: Library
• Book classi
fi
cation - genre vs location of plot
• Smaller search set = smaller retrieval time!
Photo by Martin Adams on Unsplash
Slide 38
Slide 38 text
GraphRAG
Graph DB as a data source
• Higher accuracy (more relevance in result)
• Using existing, quality data
• Explainability, veri
fi
ability
Slide 39
Slide 39 text
Explainable AI
Why graph with GenAI?
• How did the LLM get this answer?
• Graphs:
• Incorporating siloed data into result
• Add extra context/related info to graph
• Better veri
fi
cation through understandable format
Photo by No Revisions on Unsplash