Slide 1

Slide 1 text

RAG: Accuracy and Explainability in GenAI Applications Jennifer Reif [email protected] @JMHReif github.com/JMHReif jmhreif.com linkedin.com/in/jmhreif

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

Negative AI stories Even well-respected companies get it wrong • Hallucinating non-existent policy, legal cases • Chatbot produces Python • Legally binding vehicle o ff er • Harmful health advice • Threatening users • Inventing new language • Illegal activities (insider trading + local health laws)

Slide 4

Slide 4 text

Throw an LLM at it Doesn’t often work • LLM strengths: • producing human-consumable output • probabilistic answers • LLM weaknesses: • complex logic • recognizing nuances • evaluating/expressing sensitive topics

Slide 5

Slide 5 text

Demo - chatgpt.com

Slide 6

Slide 6 text

How do hallucinations happen? LLM limitations • Lacking recent data • Too broad / general search • Not enough context • Uncertainty

Slide 7

Slide 7 text

Adding context to the LLM What does it do? • Guides it • Focuses / narrows search area • Adds to LLM knowledge • Reduces margin of error

Slide 8

Slide 8 text

Demo - chatgpt.com

Slide 9

Slide 9 text

How to provide context …that we already have! • Plug and play with existing data • High-quality data • Internal value • Information in new ways

Slide 10

Slide 10 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 11

Slide 11 text

Retrieval source options • Vector database • Relational (+ vectors) • NoSQL (+ vectors) • Graph (+ vectors) • Other: Directories / Websites / etc

Slide 12

Slide 12 text

Our demo Book recommendations • Search terms / topics • Book descrs -> User reviews • Lexical search -> semantic search • Less needle-in-a-haystack • More relevant!

Slide 13

Slide 13 text

Vector dbs

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

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

Slide 16

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

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

Slide 18 text

Pinecone: sample data Document{ id='10609bf6-b358-449e-a4d1-8a6f2a2f805d', text='As always a Page turner. may me think about where we are in our tech evolution.', media='null', metadata={ rating=4.0, book_id=18505765, distance=0.58059925 }, score=0.41940075159072876 }

Slide 19

Slide 19 text

Where do vectors fall flat? How do you… • Verify vector representations? • Explain how it got to answer? • Ensure highest relevance / accuracy?

Slide 20

Slide 20 text

Graph dbs

Slide 21

Slide 21 text

What is a graph? Answers through relationships • Coworkers shared classes/degrees? • Common degree journeys? • Alumni re-enroll for higher degrees? • Who else went to my school? 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 22

Slide 22 text

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

Slide 23

Slide 23 text

What does it solve? Data problems • Documented path (not just data) • Answering how and why • Understanding/ fi nd hidden connections • Find alternates, impacts, etc.

Slide 24

Slide 24 text

Neo4j: sample data Book[ id=18505765, title=Dark Matter (Star Carrier, #5), isbn=0062183990, isbn13=9780062183996, average_rating=3.93, authors=[ Author[name=Ian Douglas] ], reviewList=[ Review[ id=f78b825c122cc5b924957fafc7382bc1, text=As always a Page turner. may me think about where we are in our tech evolution., book_id=18505765, rating=4 ] ] ]

Slide 25

Slide 25 text

Vector vs Graph RAG:

Slide 26

Slide 26 text

How are they similar? • Store and index data for e ffi cient retrieval • Query data with queries • Semantic searches • Retrieve metadata / related data

Slide 27

Slide 27 text

Index differences Vector db vs Graph db • Top unit of vector data • Data upserted into index • Del index = del data • Search vs Semantic indexes • Use explicit proc in Cypher • Del index != del data https://glennas.wordpress.com/2011/03/13/understanding-graph-databases-marko-rodriguez/ https://docs.pinecone.io/guides/indexes/understanding-indexes

Slide 28

Slide 28 text

Storage practices Vector db vs Graph db • Prioritize stats • Some metadata / connections • Avoid large data types / values • Prioritize relationships • Value = metadata / connections • Avoid large types as properties Document{ id='10609bf6-b358-449e-a4d1-8a6f2a2f805d', text='As always a Page turner. may me think about where we are in our tech evolution.', media='null', metadata={ rating=4.0, book_id=18505765, distance=0.58059925 }, score=0.41940075159072876 } Book[ id=18505765, title=Dark Matter (Star Carrier, #5), isbn=0062183990, isbn13=9780062183996, average_rating=3.93, authors=[ Author[name=Ian Douglas] ], reviewList=[ Review[ id=f78b825c122cc5b924957fafc7382bc1, text=As always a Page turner. may me think about where we are in our tech evolution., book_id=18505765, rating=4 ] ] ]

Slide 29

Slide 29 text

Graphs = extra layer • Accuracy: • extra context / related info in connections • Veri fi ability: • check against understandable format • Explainability: • trace path through graph for answer

Slide 30

Slide 30 text

Demo!

Slide 31

Slide 31 text

Resources • Github repository (today’s code): github.com/JMHReif/vector-graph-rag • Docs for Spring AI: https://docs.spring.io/spring-ai/reference/api/vectordbs.html • GraphAcademy LLM courses: graphacademy.neo4j.com/categories/llms/ • 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