How to Decipher User Uncertainty with GenAI and Vector Search

A presentation at CityJS Athens in November 2024 in Athens, Greece by Ben Greenberg

Slide 1

Slide 1

Slide 2

Slide 2

@hummusonrails ‹#›

Slide 3

Slide 3

Sometimes, you really love your chair @hummusonrails ‹#›

Slide 4

Slide 4

@hummusonrails ‹#›

Slide 5

Slide 5

I’m looking for my old chair, it’s leg part went up when I pressed a button but not too high! The leather was comfortable but not too expensive. It was brown, but like an earthy kind of brown, not brown brown. @hummusonrails ‹#›

Slide 6

Slide 6

Will Joey find his chair? @hummusonrails ‹#›

Slide 7

Slide 7

61% say that if they don’t find what they’re looking for within , they’ll go to another site. 5 seconds @hummusonrails ‹#›

Slide 8

Slide 8

@hummusonrails ‹#›

Slide 9

Slide 9

No brown chairs No earthy brown chairs No manual recliners No automatic recliners … at least there were chairs? @hummusonrails ‹#›

Slide 10

Slide 10

But, this is not really about @hummusonrails ‹#›

Slide 11

Slide 11

@hummusonrails ‹#›

Slide 12

Slide 12

@hummusonrails ‹#›

Slide 13

Slide 13

Hello, my name is Ben. @hummusonrails

Slide 14

Slide 14

What we’re going to talk about • What’s a vector? (i.e. Demystifying the jargon) • (i.e. How vector search works. What’s it got to do with GenAI?) • When would you use it? • Ben, show me an example! @hummusonrails ‹#›

Slide 15

Slide 15

What’s a vector? ‹#›

Slide 16

Slide 16

Warning: It involves NUMBER ‹#›

Slide 17

Slide 17

A vector is a list of numbers that represents words, phrases, images and more. Each number in the list holds some information about the meaning of the text. @hummusonrails ‹#›

Slide 18

Slide 18

A vector embedding turns words or sentences into short, dense lists of numbers. Embeddings are compact and efficient, making tasks like searching and organizing text easier. “lowerdimensional” @hummusonrails ‹#›

Slide 19

Slide 19

I’m looking for my old chair, it’s leg part went up when I pressed a button but not too high! The leather was comfortable but not too expensive. It was brown, but like an earthy kind of brown, not brown brown. @hummusonrails ‹#›

Slide 20

Slide 20

Moments later using an embeddings API… @hummusonrails ‹#›

Slide 21

Slide 21

@hummusonrails ‹#›

Slide 22

Slide 22

Your application data transforms from… @hummusonrails ‹#›

Slide 23

Slide 23

@hummusonrails ‹#›

Slide 24

Slide 24

Into vector representations, unlocking more accurate search, content recommendations and document comparisons @hummusonrails ‹#›

Slide 25

Slide 25

Is this really magic? It’s time to discuss EMBEDDING MODELS @hummusonrails ‹#›

Slide 26

Slide 26

Joey [ Needs A New Embedding Model ] 2.5, 1.1, 2.0, 0, 2.0, 2.1 … Chair @hummusonrails ‹#›

Slide 27

Slide 27

What are these embedding models? @hummusonrails ‹#›

Slide 28

Slide 28

Neural Networks @hummusonrails ‹#›

Slide 29

Slide 29

BERT Bidirectional Encoder Representations from Transformers Bidirectional Reads what comes before and after a word for full context Trained on Wikipedia Pre-trained on a vast amount of data Top NLP benchmarks Achieved top scores for comprehension, common sense, sentiment analysis, and more ‹#› @hummusonrails Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2024. All rights reserved.

Slide 30

Slide 30

GPT Generative PreTrained Transformer Autoregressive Predicts what word comes next based on previous words ‹#› @hummusonrails Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2024. All rights reserved.

Slide 31

Slide 31

How vector search works ‹#›

Slide 32

Slide 32

LET’S TALK ABOUT That’s a little too close for comfort @hummusonrails ‹#›

Slide 33

Slide 33

Closeness in vector search refers to how similar two vectors are, measured by the distance between them, with smaller distances indicating greater similarity. @hummusonrails ‹#›

Slide 34

Slide 34

The search query as a vector @hummusonrails ‹#›

Slide 35

Slide 35

How is closeness determined? @hummusonrails ‹#›

Slide 36

Slide 36

@hummusonrails ‹#›

Slide 37

Slide 37

Euclidian • Measures the straight-line distance between two points in Euclidean space. • Often used in clustering algorithms like K-means, where the actual distance between points is important. @hummusonrails grouping by similarity Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2024. All rights reserved. ‹#›

Slide 38

Slide 38

Cosine • Measures the cosine of the angle between two vectors, indicating how similar their directions are. • Commonly used in text analysis and information retrieval where the orientation (not the meaning of magnitude) of the vectors text, not size matters. of text @hummusonrails Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2024. All rights reserved. ‹#›

Slide 39

Slide 39

Manhattan Distance (L1) • Measures the sum of the lots of absolute differences of their information coordinates. • Useful in high-dimensional spaces and in scenarios where the differences are linear and not squared, such as certain machine learning algorithms and optimization problems. @hummusonrails straightforward differences Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2024. All rights reserved. ‹#›

Slide 40

Slide 40

Dot Product Similarity • Measures the sum of the products of corresponding elements of two vectors. • Higher sums equate to more similarity. • Often used in information retrieval and recommendation systems, where the magnitude and direction of vectors are important. @hummusonrails Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2024. All rights reserved.

Slide 41

Slide 41

@hummusonrails ‹#›

Slide 42

Slide 42

Keyword search starts @hummusonrails ‹#›

Slide 43

Slide 43

But, have you ever seen something like this? @hummusonrails ‹#›

Slide 44

Slide 44

@hummusonrails ‹#›

Slide 45

Slide 45

@hummusonrails ‹#›

Slide 46

Slide 46

When the query is more complex, vector search can be more performant @hummusonrails ‹#›

Slide 47

Slide 47

It’s even useful for more than just @hummusonrails ‹#›

Slide 48

Slide 48

@hummusonrails ‹#›

Slide 49

Slide 49

Images, audio and video can be transformed into @hummusonrails ‹#›

Slide 50

Slide 50

What’s it got to do with GENAI @hummusonrails ‹#›

Slide 51

Slide 51

Chatbots without context @hummusonrails ‹#›

Slide 52

Slide 52

HALLUCINATE @hummusonrails ‹#›

Slide 53

Slide 53

@hummusonrails ‹#›

Slide 54

Slide 54

Slide 55

Slide 55

Retrieval Augmented Generation Query Embedding & Retrieval Convert to vectors Find relevant documents Contextual Augmentation Text Generation Enhance with content Add background details Ensure relevance Generate coherent text @hummusonrails Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2024. All rights reserved. ‹#›

Slide 56

Slide 56

@hummusonrails ‹#›

Slide 57

Slide 57

When would you use it? ‹#›

Slide 58

Slide 58

Finding and retrieving similar items quickly and accurately in large datasets @hummusonrails ‹#›

Slide 59

Slide 59

1.Recomendation systems 2.Anomaly detection 3.Natural language processing @hummusonrails @hummusonrails ‹#›

Slide 60

Slide 60

  1. Exact match retrieval 2. Real time transaction processing 3. Small simple datasets @hummusonrails ‹#›

Slide 61

Slide 61

@hummusonrails ‹#›

Slide 62

Slide 62

Online fraud costs £27 billion annually in the UK @hummusonrails

Slide 63

Slide 63

Slide 64

Slide 64

Ben, show me an example! ‹#›

Slide 65

Slide 65

Where does every developer experiment with new technologies? @hummusonrails ‹#›

Slide 66

Slide 66

PERSONAL SITE @hummusonrails ‹#›

Slide 67

Slide 67

@hummusonrails ‹#›

Slide 68

Slide 68

@hummusonrails

Slide 69

Slide 69

Mastering Vector Search for Developers Est. Publish Date: February 2025, Published by: The Pragmatic Bookshelf Intro to vector search Building vector search in Node.js Implementing similarity measures with JavaScript Creating search functionality with Node.js examples Optimizing search performance in JavaScript Real-world Node.js applications for vector search vectorsearchbook.com @hummusonrails ‹#›

Slide 70

Slide 70

Thank you! @hummusonrails ‹#›