Slide 1

Slide 1 text

Pass or Play What does GenAI mean for the Java developer? 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 • Conference speaker • Tech blogger • Other: geek Jennifer Reif [email protected] @JMHReif github.com/JMHReif jmhreif.com linkedin.com/in/jmhreif

Slide 3

Slide 3 text

Photo by Matt Walsh on Unsplash AI Vector RAG LLM Algorithm Chaining Entity resolution Knowledge graph ML NLP GenAI Hallucination Embedding k-ANN Cosine similarity Euclidean distance Fine-tune Few-shot Grounding Model Prompt Semantic search Similarity Temperature Tokens Natural language ChatGPT Context window Agents GraphRAG

Slide 4

Slide 4 text

Generative Arti fi cial Intelligence Artificial intelligence capable of generating text, images, or other data using generative models, often in response to prompts. Generative AI models learn the patterns and structure of their input training data and then generate new data that has similar characteristics. https://en.wikipedia.org/wiki/Generative_arti fi cial_intelligence

Slide 5

Slide 5 text

Large Language Model (LLM)

Slide 6

Slide 6 text

Are LLMs all that? Worth the hype? • General information • Public domain knowledge • Historical data • Creative / arts • Human assistant • Task delegation Photo by Igor Omilaev on Unsplash

Slide 7

Slide 7 text

LLM issues • Lacking most recent data • Not always natural language • Language complexities, sarcasm, emotion • No sources • Hallucinations / Temperature • IP, bias, privacy

Slide 8

Slide 8 text

“Simply add an LLM” doesn’t work…

Slide 9

Slide 9 text

Strategies to improve LLM accuracy • Custom model • Fine-tuning / Few-shot learning • Retrieval Augmented Generation (RAG) • All of these involve training an LLM on speci fi c data!

Slide 10

Slide 10 text

RAG Pull data from external data sources • Retrieval • Data retrieved from database • Augmented • Augments response with facts • Generation • Response in natural language

Slide 11

Slide 11 text

Explainable AI With RAG + LLM • How did the LLM get this answer? • Grounding LLM answer with veri fi ed data Photo by No Revisions on Unsplash

Slide 12

Slide 12 text

Applying RAG to an LLM

Slide 13

Slide 13 text

LLMs take media, not databases And context window limit

Slide 14

Slide 14 text

What is a vector? Mathematical realm • Line in space • Has length and direction horizontal vertical

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

Vectors to compare things What makes things similar? Length Width

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

LLMs take text, not databases Vectors

Slide 20

Slide 20 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 21

Slide 21 text

Provide prompt + context to LLM Vectors Vectors Vectors Vectors Similarity

Slide 22

Slide 22 text

What is a graph? Natural representation of data • Storing relationships with entities • Documents path • Can answer why • Can fi nd alternates • Understand / fi nd patterns • Web of connections, related info • Bonus: Visual representation of data

Slide 23

Slide 23 text

Book domain • Find authors with reviews for multiple books • Find similar users based on reviews of books and related authors

Slide 24

Slide 24 text

Property graph • Node (vertex) • Relationship (edge)

Slide 25

Slide 25 text

Nodes • Represent objects or entities • Can be labeled • May have properties Book Author title: “Star Wars” isbn: 9756165498 name: “George Lucas” avgRating: 4.72 Review rating: 4.2 reviewText: “Blah” votes: 17

Slide 26

Slide 26 text

Relationships • Must have a type (label) • Must have a direction • May have properties Book Author title: “Star Wars” isbn: 9756165498 name: “George Lucas” avgRating: 4.72 Review rating: 4.2 reviewText: “Blah” votes: 17 AUTHORED WRITTEN_FOR date_added: “Sun Jan 03”

Slide 27

Slide 27 text

GraphRAG Added context • Data + other context • Documenting path • Adding connected context • Logging interactions with data • Network algos • Visualize data + interactions • Analyze performance LLM Responses (pink) and 
 Most Frequently Used Context Documents (red)

Slide 28

Slide 28 text

Example: Agent Neo Chatbot for learning GDS • LLM hallucinating answers • Provide LLM with updated info • Backed by KG of curated documentation • Streamlit + Langchain app • Log conversations with data • Improvements to responses!

Slide 29

Slide 29 text

Provide prompt + context to LLM Vectors Vectors Vectors Vectors Similarity Graph

Slide 30

Slide 30 text

RAG architecture Prompt + Relevant Information LLM API LLM
 Chat API User Database Search Prompt Response Relevant Results / Documents 2 3 1 Database

Slide 31

Slide 31 text

Agentic Workflow Architecture • Uses “agents”/tools • LLM determines next step • Which tool/external source should be called • Uses result from tool as context Prompt + Relevant Information LLM API LLM
 Chat API User Tool Prompt Response Relevant Results / Documents 2 3 1 Source info

Slide 32

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

Slide 33 text

Let’s code! Vector search Data results Prompt phrase+data

Slide 34

Slide 34 text

Demo! Our data model

Slide 35

Slide 35 text

No content

Slide 36

Slide 36 text

Resources • Github repository (today’s code): github.com/JMHReif/springai-goodreads • GraphAcademy LLM courses: graphacademy.neo4j.com/categories/llms/ • Docs for Spring AI: docs.spring.io/spring-ai/reference/api/vectordbs/neo4j.html Jennifer Reif [email protected] @JMHReif github.com/JMHReif jmhreif.com linkedin.com/in/jmhreif