Slide 1

Slide 1 text

GraphRAG: Data 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

Other use cases • Fraud detection • Identity and access management • Recommendations • Supply chain • Logistics

Slide 13

Slide 13 text

Graphs add context and meaning Not just point-to-point, but HOW they connect

Slide 14

Slide 14 text

One model to rule them all… Conceptual = Logical = Physical data model

Slide 15

Slide 15 text

One model to rule them all… Conceptual = Logical = Physical data model

Slide 16

Slide 16 text

Cypher GQL-compliant • Functional and visual • Based on ASCII art • Declarative • Focus on patterns A B LIKES MATCH (A)-[:LIKES]->(B)

Slide 17

Slide 17 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 18

Slide 18 text

Cypher: read All about patterns Jennifer Neo4j WORKS_FOR MATCH (:Person { name: ‘Jennifer’} ) -[:WORKS_FOR]-> ( whom ) RETURN whom

Slide 19

Slide 19 text

A knowledge graph is a specific implementation of a graph database, where information is integrated from many different sources, representing the inherent knowledge of a particular domain.

Slide 20

Slide 20 text

Knowledge graphs

Slide 21

Slide 21 text

Knowledge graphs are • Optimized for relationships • Well suited for complex, interconnected data • Schema-optional • Can readily adapt/evolve as they grow

Slide 22

Slide 22 text

Demo!

Slide 23

Slide 23 text

AI

Slide 24

Slide 24 text

Throw an LLM at it Doesn’t often work • LLM strengths: • human-consumable data • probabilistic answers • LLM weaknesses: • complex logic • recognizing nuances • Solo LLM = great -> integrated LLM = more great?

Slide 25

Slide 25 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 26

Slide 26 text

LLMs take text, not databases And context window limit

Slide 27

Slide 27 text

Lexical to Semantic search • Keyword searches aren’t enough • Data dictionaries are complex and limited • How do we search relevant/contextual info?

Slide 28

Slide 28 text

Embeddings / Vectors Convert data to a point in space • Series of numbers • 100s or 1000s of dimensions • Dimension = interesting feature / characteristic

Slide 29

Slide 29 text

Vectors in the physical realm https://www.mathsisfun.com/algebra/vectors.html

Slide 30

Slide 30 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 31

Slide 31 text

LLMs take text, not databases Vectors

Slide 32

Slide 32 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 33

Slide 33 text

Provide prompt + context to LLM Vectors Text

Slide 34

Slide 34 text

Vector-only RAG Similarity is insu ff i cient for rich reasoning/explainability • Missing context, relationships • Vector similarity != relevance • Lack explainability

Slide 35

Slide 35 text

GraphRAG Graph DB as a data source • More relevant data to provide as context • Quality connected data, higher accuracy • Explainability, veri fi ability

Slide 36

Slide 36 text

GraphRAG

Slide 37

Slide 37 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

Slide 38

Slide 38 text

Knowledge graph as knowledge base Document in KG -> Knowledge Graph

Slide 39

Slide 39 text

Explainability

Slide 40

Slide 40 text

Nothing is a silver bullet LLM is (of sorts) mind of its own • Can’t guarantee a consistent answer • Prompt engineering • Context window limits

Slide 41

Slide 41 text

Let’s code!

Slide 42

Slide 42 text

No content

Slide 43

Slide 43 text

Resources • Github repository (today’s code): github.com/JMHReif/ai-pet-travel • GraphAcademy LLM courses: graphacademy.neo4j.com/categories/llms/ • Docs for Spring AI: docs.spring.io/spring-ai/reference/api/vectordbs/neo4j.html • Knowledge graph ebook: https://neo4j.com/whitepapers/developers-guide-how- to-build-knowledge-graph/ Jennifer Reif [email protected] @JMHReif github.com/JMHReif jmhreif.com linkedin.com/in/jmhreif