- Podcasts
- Programming Throwdown
- Machine Learning Embeddings with Edo Liberty
Machine Learning Embeddings with Edo Liberty
Programming Throwdown
- September 27, 2021
- 60 min
- Episode 120
About this episode00:00:24 Introduction 00:02:19 Edo's Background 00:08:20 What are Embeddings? 00:14:00 Self-Organizing Maps & how humans store data…
00:00:24 Introduction
00:02:19 Edo's Background
00:08:20 What are Embeddings?
00:14:00 Self-Organizing Maps & how humans store data
00:22:27 The lifecycle of a machine learning system
00:34:40 The weirdness of high-dimensional spaces
00:42:20 How to manage a vector database
00:47:01 Pinecone the company
★ Support this podcast on Patreon ★Transcript
From the publisherThis transcript comes from the podcast’s own feed, shown as the publisher wrote it.
Machine Learning Embeddings with Edo Liberty
going? I know a lot of folks out there ask about AI and machine learning. You know, Patrick's done some machine learning stuff in the health space. I do a lot of machine learning stuff, or at least I pretend to, in my day job. And so a lot of people write to us, message us on Twitter, asking questions along these lines. And so it's always a real pleasure where we can talk about, you know, kind of an area that we really love. And this is right in the heart of it. We're going to be talking a lot about machine learning embeddings, which is a term you might not have heard before, but you're going to really enjoy it. And it's something that is extremely, extremely useful. I'm extremely lucky that we have Ido Liberty here, who's an expert in this area. He's the CEO of Pinecone, and he's here to talk to us about embeddings and kind of riff on that. So thanks so much for coming on the show, Ido.
Yeah. Yeah, totally agree. Totally agree. I wonder if we'll end up with... Remember WeWork? I think is WeWork still a thing? It probably is still a thing, even though they had all sorts of issues as a company. But that might be the kind of thing where physically you're next to a bunch of people that you can socialize with, but you actually all work for different companies or something like that. Who knows what the future is going to be? Yeah, 100%. Cool. So why don't you tell us your story and how you kind of got into this area and how embeddings became important to what you do and kind of where that all started from?
Yeah, so my journey into becoming a CEO has nothing to do with business. I did my PhD in Computer Science and my postdoc in Applied Math, working mostly on CS theory and algorithms for machine learning and big data. What I ended up doing mostly was high-dimensional geometry, so numerical linear algebra and clustering and dimension reduction and stuff like that. And a big part of that was a mirror's neighbor search and searching through high-dimensional vectors, which we will get to in the end or in the middle of this discussion. And then I opened a company in 2009 that did a real-time video search. And real-time video search kind of has to be based on this vector search capability, which we'll talk about later. And again, so I started investing in that.
So can you tell me real quick, how did you—this always fascinates me—how did you make that leap to being an entrepreneur? So right before, let's say 2008, what were you doing? And then how were you able to sort of quit that job and say, 'Okay, I'm going to start this real-time video understanding company?' You know, what made you take that leap of faith?
So the answer is, so it's two things really. One of them is I've just always kind of been very entrepreneurial, but by nature, I was kind of—I was importing like balanced skateboards to Israel when I was in high school. And I was like, I was always like doing stuff like that, right? So I was, some part of me was always a little bit entrepreneurial. But the other one is just like dumb luck and, you know, just happenstance, you know, I was in New York and my cousins of old people said, 'Oh, I'm going to start this company and I'm going to hire, you know, whatever, like 10 engineers to do X, Y, Z.' And I'm like, 'Oh, you don't need 10 engineers for this. We can, we can whip it up.' In like, like, like a month and you can go raise money on that. And he didn't believe me. So we spent a month and we made something work. And so, you know, when we found ourselves with some money and a company, so like, okay, I guess we have to run a company now.
I was a postdoc at the time. So it's like the work was not incredibly demanding, definitely not time-critical. So I could kind of disappear for a month. It was actually great; I loved it. I actually still remember it. I would wake up at like 8 A.M., make myself coffee, sit down, and code until like midnight and go to sleep. I did that for a full month, and it was fantastic. It was fantastic.
The TV company. And then I moved to Yahoo where I spent a lot of time as a Director of Machine Learning. So I was building Machine Learning platforms and solutions and so on, working on mail and ads and spam and feed ranking and so on. And yeah, then went to AWS and spent about two and a half, three years. So all the offerings from AWS, so SageMaker and all the, you know.
Right. Well, exactly. The English stuff, language stuff, all that, you know, all those services. I didn't own all of them, but I was definitely a part of building that org and being a big part of the science of all these services. So my journey has kind of been a little bit all over the map, which is highly recommended. Seems chaotic in hindsight, but kind of fun nonetheless.
No, I think it's amazing. I think it's great. I think that, you know, you can see the progression. I mean, it might seem chaotic, you know, geometrically, but you can see kind of a nice trajectory. Yeah. Very cool. And so, and so you were at AWS and then from AWS, is that how you were inspired to go to Pinecone or was there a spot in between?
No, no, from AWS and I opened Pinecone. So building, it was kind of seeing how the sausage is made, like building managed services and databases. That's where I really got into like databases and managed services and cloud offerings and so on, kind of really diving in deep into that. And it suddenly dawned on me, you know, that like I had sold exactly the same problem, like 10 times in my career and I always built it from scratch and it was always hard and always like insufficient in the end.
Yeah. So, one of the interesting statistics that I uncovered while thinking about opening Pinecone. You know, I had a lot of conviction that this was needed, but like I knew embeddings were needed for dealing with unstructured data. So when you look at like tabular data, it's very clear how to store it, how to slice and dice into it, how to work with it. Cause we have like 50 years worth of databases developed for it.
Yeah. I mean, if people are used Excel and you've done this thing where maybe you have a bunch of columns with data and in Excel, and then you want to try to learn a new call. Like there's a column has some missing values and you want to try to guess it from the other columns. That's pretty easy to do in Excel. And you can kind of imagine what's going on there. There's some model that's just looking at a single row and pulling those values and then trying to infer that new column. But then there's a question of like, how do you do that? If it's an image or a video or a website, you know, now it's totally unclear how to do that.
Correct. And this, you know, it extends much more. So it could be like, yeah, those like very complex data types, like images and long text documents and, you know, some like audio recordings and so on, but it could be like travel through a website, like a trajectory through a website or a shopping cart or something else, which is in and of itself, like a complex object. It's not like, it's not something you can stick in a table in like four columns. Right. And for a long time, it wasn't really clear how to deal with those objects. Right. It was like each and every one of them had its own like little mini discipline in computer science and how to reason about them, how to structure them, how to predict about them and so on. And in the last few years, there has been this movement with deep learning to basically unify this entire paradigm. So basically say, I will use deep learning neural nets, basically like deep neural nets, right. To take the input in some way and transform it through some layers or through some transformations and in the end provide a high dimensional dense vector. So let's say a thousand twenty four or an array of a thousand twenty four floating point numbers. But I will train the network such that that vector is somehow semantically representative of the object. For example, I would train it such that if two documents mean the same thing, okay, they talk about this in topical, they're like, they're similar in some sense, then their resulting vectors would be very correlated.
Right. And so there's a whole—there's a whole body of literature and a good amount of technical know-how on how do you take data and produce these embeddings, such as they are good. But the fascinating thing is that it's—well, it isn't always the perfect solution. It's very often great. And so you can transform images and text and audio and like shopping habits and like your video preferences and like pretty much you name it and convert it into this like dense vector. Okay? And now you can instead of dealing with this complex type, you can now have this embedding—this, you know, you actually embed like you by embedding. It's like you put an item in high-dimensional space. You assign the vector to it. Right? So think about a vector as like a point in a high-dimensional space. That's why it's called embedding. And so now instead of talking about documents and semantic similarity, you talk about vectors like angles and distances. And so now it becomes a lot more concrete and a lot more actionable and a lot more something that you can talk, reason about, and like build for and like code in systems and not like it's not an abstract thought anymore.
Yeah. I mean, if people have seen this visualization where there's a bunch of points and they all have kind of springs in between them and then you run this through some physics model and they all just kind of separate and end up in this like spider web kind of shape. Right? That's because all the points are kind of repulsing each other. And even though it's only a local repulsion, it creates this really beautiful kind of spider web structure globally. Right? Because you see this similar with birds. Right? Birds have a similar thing where, you know, they have some very simple rules in their brain around not getting too close to other birds and like staying in a certain position to the bird next to them. And then that ends up with this like beautiful kind of V shape or swarm or things like that. And this is similar where we're doing that. But then some of the points are actually getting pulled together and some are getting pushed apart depending on things we know about them.
Exactly. So there were like works from I think the early 2000s called like Self-Organizing Map. So maybe this is like ideas if you're older, you know, I don't know. Maybe the idea itself. Actually, you know what? I think the idea itself is even older. There were like old works like on MDS stuff like that, ISO maps. And there was like a flurry of works and that. Very good. So you would like take things like say I'll take all the people like, you know, a million people and I'll just look at their social network graph.
And I'll try to put—I'll try to create like these virtual springs that put people that you know close together. Right? Physically. Right? So then we'll try to make them like physically adjacent to each other. And if you try to do that in two dimensions, what you get is the map of the US. Like if you have on the US post—maybe now, maybe now with COVID and social networks, maybe that now it doesn't work anymore. But back in the day, it did.
Yeah. Or if you imagine doing a two-dimensional embedding on interests, you might have like a little island over here of gamers and a little island of skateboarders. And there might be somebody who's interested in both. And so they're going to be kind of on this sort of inflection point or on the saddle point in between those two clusters. But—but you'll still have those large clusters, or maybe you'll have another cluster of gamer-skateboarders. Right? If there are enough of them, that cluster will start having a defined border and pushing the other clusters away. And so, yeah, you end up with these really beautiful behaviors. And when you're done, you have something really interesting. You can draw a little circle on that map and say everyone here really likes skateboarding. And once you start introducing a whole bunch of other topics and you get to more than two dimensions, you can even guess at things that people like that they didn't even know they liked.
A hundred percent. And I think in two dimensions, you get pretty limited pretty fast. The two-dimensional space is very limited. But when you live in a thousand-dimensional space, you get so much more representational power because you can be a skateboarder but at the same time be a dad. At the same time, be like really into whatever, like anime and whatever, like also be like vegetarian. I mean, and all these things are facets in your behavior and things that you care about. And they're not mutually exclusive. And, you know, they're just like a part of you. So you're not—you're not a skateboarder or vegetarian. You're both. Yeah. So that's how, you know, these high-dimensional dense vectors can actually like represent something a lot more deep, a lot more rich, a lot more actionable than just like, you know, this one feature or another.
Yeah. It's actually—it's that curse of dimensionality, but actually working in your favor where we're going from two to four dimensions gives you so much more expressibility. And then going to a thousand dimensions gives you exponentially more expressibility. And it's just amazing what you can represent. I mean, we've seen just unbelievable things with GPT-3 where people have auto-generated websites. There's this thing Codex where it auto-generates code. And it's just amazing. And it's all using embeddings.
Yeah. And the amazing thing is like that's how our brain works, too. So if you think about everything that you remember seeing, okay? everything that you've ever seen, okay, the part of the lateral cortex, I mean, like pretty much everything, your higher functions in the brain that deal with visual imagery, okay, the input that they have is not the light intensity on your retina, which you might think is highly related to the actual like image, right? Or what's like what we think about is an image in like as a RGB roster, right? What your brain gets is the output of the visual cortex, which is an activation of a few million neurons, right? And that's it. And those activations have very little correlation to the actual RGB values in the image. In fact, we know for a fact they have almost no correlation because when you look at your partner at midnight or inside the house or maybe in high noon outside, in terms of colors, it's completely different. It's got nothing to do with each other, right? But to you, it looks exactly the same. Like the brain just completely changes all the values to make the embedding exactly the same. So you see the same thing.
Yeah. I mean, a good example of this is to try to guess at how thick a wall is, an interior wall. Now, if you're a dad and you're constantly in the attic, you know, fixing stuff, that's different, you know, that's cheating. But like, you might look at a wall and say, oh, that's maybe, you know, half a foot thick. But then, you know, when you actually look at a map, it's like, oh no, it's like four feet or something like it's just, you'll be off by a ton. And yet you're able to navigate around your house, you know, trivially, you know, you don't have a map that is in any way accurate, but you have this really sort of deep, like semantic understanding of the different rooms and where to go. And, and so you, my, my older son sleepwalks. And so somehow he's able to sleepwalk down the stairs and into the fridge and like get a stick of cheese, like, I don't know how he does it, but, but he's able to do that. Yet there's, there's that map isn't there. So it's, it's all just these super deep embeddings. And, and because everything gets collapsed down to that, in the case of the human brain, you know, million dimensional embedding, it's, it's in a sense, kind of easy to store, right? Because you're, you're putting the same million numbers to hold, you know, everything you see and to hold, you know, you might have to integrate over them for video, you know, audio might be a different thing, but, but it's all the, the, the, the data structure, if you will, is the same for everything.
So that, that actually, I think you nailed it. I think this is like, it brings a very interesting topic, which is how do you even remember? How do you get, like when you your son sleepwalks or when he looks at a stick, stick of cheese and he knows it's a stick of cheese, or you look at your loved one and they're whatever a stick of cheese. How do you know that a stick of cheese? No. How do you know it's the same thing? Yeah. You know, yeah. Somewhere in your brain, you need to be able to go and match what you have against the bank of gobbs of these like embeddings. Right. And say, oh, this isn't the truck. This isn't a tree. And this isn't like a, whatever, like my grandma and it isn't whatever, like a road. It's a stick of cheese. Right.
Right. And so how does that happen? You know, how do you do that? And so if you think about it, computers need to do the same thing. You know, if I generate an embedding for a sentence, right. So we, you know, you might think about, okay, I'm some whatever. Like I used to work on spam detection at Yahoo. Right. So you see an email that looks like some Nigerian prince is trying to convince you to transfer money somewhere. You're like, okay, I know this. I know what it is. Right. But it's not exactly the same email. Like these scams look slightly different from each other. Right. But any rational person would read this and think, oh, I remember this thing. It looks like something else. Because in your brain, you do this matching very easily, but computers don't know how to do this. Right. So for computers, you would pass a different email that maybe semantically says the same thing. Right. But you would get a slightly different vector coming out of it. Unlike structured data, when you can do a hash table lookup and just fetch exactly the same key and then get the same value. You don't have that anymore. You just have a vector that's that's different than anything else you've ever seen before. It might be close to other things you've seen before, highly correlated with a small set, but it's not an exact match. And so if you went ahead and tried to code this thing and try to say, okay, now I have a billion 1000-dimensional vectors and give me the hundred that correlate the most with it. Right. Except for going one by one, computing the correlation and just keeping the top 10, it's not clear what to do. And so now you get into this really, really rich and interesting topic in computer science that has to do with vector indexes and retrieval. And that's, you know, that's something that gets really deep, really fast. And again, I'm happy to dive as deep as you want. I'm not sure how much you want to, how much you want to scratch the surface. Yeah.
Well, let's go through sort of the life cycle of a system that uses vectors. Right. So, so let's take a like a recommender system. Right. So we have a, let's say, let's say it's an image recommender system. So we have a lot of all of these images and whether the person liked them or not. And so we train some model based on that. And if a person likes two images, you know, it's going to sort of bring those embeddings together. And if a person liked one image but not the other, it's going to pull them apart. Right. And there's more complexity around random negative mining and all of that. We'll just leave all that alone and put a bookmark in that. But so you can imagine, you know, in the beginning, it's all random. This is one thing that actually surprised a lot of people in the beginning; all the embeddings are totally random. So, you know, for any particular picture, it's just somewhere floating in that thousand-dimensional space and every picture is going to have some other spot. But then through this process of kind of pulling and pushing, you know, pairs of points, you know, together or apart, you know, eventually it'll start to coalesce into that structure that we really like. And then, and then to your point, if we know somebody the last picture they liked was this one, then we can ask the question, what are they, what should we show them next? And it's well, let's, what are the closest things to that one they just liked? Right. So now we have this problem of here's a point and embedding that we've trained. It could be maybe a week ago, but we have this trained model and we have this point that we know somebody likes. Let's get the points around it. And so, yeah, the naive way to do that is to go through every single point and say, how close are you? How close are you? How close are you? And then keep an array of the top 10. But, you know, for something like imagine Amazon, I mean, how many items does Amazon have in their inventory? Right. Or how many pictures are on Instagram? Right. I mean, just billions. I actually
Oh, really? All right. Let's hear it if it's not confidential. I think it is. Okay. Let's say it's more than a hundred billion or something, at least for Instagram, right? There's so many people on there making pictures. And so, you know, that whole idea of going one by one is just, you just can't do it. So, so that kind of gets to sort of what you've really been focusing on. And so how do people do that? I mean, Amazon works, Instagram, I can press F5 and it comes right up. You know, every time I hit refresh, it's right there. I pull down in the app and I get new photos. Like, how are people able to do that in a reasonable time?
So now, now we basically are discussing this like algorithmic question, right? So this, let's just kind of make that crisp of what the problem is. Okay. You get N vectors in dimension D. So N being large, say billions, D being large-ish but fixed, say a thousand. And now I give you another vector in dimension a thousand. I tell you, give me all the vectors that correlate the most with it. Or let's just say, you know, maybe our closest in Euclidean distance. So I actually measure the sum of square distances and sum of square discrepancies on coordinates and take the square root of that. So like you said, you know, yes, you can scan everything. Clearly that's not feasible. So now how, how do you do it? Interestingly enough, you can actually prove that you cannot accelerate this beyond some limit, which is still pretty grim, okay? Without incurring some level of error. In some sense, you need to accept the fact that you will have a little bit of approximation. So you might, you might miss something that is relatively close, maybe not almost identical, but kind of on the perimeter of the ball you're searching in. And you might miss that, or you might accidentally include something that's slightly outside of it. So you, you have to accept a little bit of a fudge factor, right? But once you do, you can accelerate things significantly. In fact, all the algorithms to do fast nearest neighbor search, do approximate nearest neighbor search. Okay. Then approximate nearest neighbor search means look for the nearest neighbors, looks for the vector that are vectors that are closest, approximately. Approximately means exactly what I said. There's like this little fudge factor around the edges. Okay. Now, I'll just kind of give a very quick and maybe almost like a sketch of kind of the main ideas in big algorithms. So first of all, there is clustering. Clustering is an obvious idea. I'll just start by saying I'll have like a thousand clusters. Clusters are like a large collection of points that are all relatively close to one another. And instead of remembering all of them, I'll just kind of remember the center. Okay. And so when think about when seeing something, I instead of thinking whether it's a mouse or a stick of cheese, I can first say, okay, is this an animal or like an animal object? Right. If it's an animal, good. I've already reduced the search space by a big margin. Right. So now, now I need to and I can, I can iterate on that. So
you can like deconstruct the world. That makes sense. Like hierarchical, like for Amazon, if you search for batteries, there's probably something in Amazon that says this, you know, don't bother with pet food. Like just forget that whole category, you know, like there's, there's probably something and then they can do something afterwards.
Yeah. You cluster the embedding space. So now you take those points in high dimension and just say, oh, those set of points are so close together. That instead of measuring all the distance, I can just measure the distance to the center. And if it's close enough and I will maybe suspect that some of them should be close. Okay. And then I should check that. Okay. So how you cluster exactly and how you then like search within those clusters is still, I still didn't talk about that, but kind of that's one main idea that that works very well. And again, there's like a whole literature on how to do that fast and efficiently and accurately and so on. Then within each cluster. So now let's say you've, you've narrowed down your search space from a billion to like, let's say 20 clusters. Each one of them has a million points. Right. Now they're not clustered anymore because they're all sticks of cheese. Right. So maybe different, whatever, like blue cheese. Yeah. Like a piece of chalk and a stick of cheese. And so now like all white to cylindrical things. Right. Yeah. So now you really have to like do a lot, something a lot more refined. Right. And there you have a whole nother set of algorithms that look like what's called Product Quantization or other types of quantization. Instead of computing the dot product exactly. So saying I'll actually compute the distance exactly for like one, one candidate, one vector. I will compress it somehow and be able to just have a very quick, maybe of one, you know, indication of, is this like a likely match? Right.
Which is a good way, by the way, in low dimensions, bucketing and like an algorithm called Cayley trees is actually very efficient. If you, if you have an algorithm, if your data is like two or five or 10 dimensional, then this like bucketing works fantastically well. In dimensions like a hundred to a thousand, it kind of breaks spectacularly because high dimensional spaces are weird.
Yeah, that's true. I never thought about that, but yeah, I mean, just, just to give a bit of context, like for a KD tree, you can only split. And so KD tree is a binary tree where at each node in the tree, you split in one dimension. And you say everything that's more than this in that dimension, you know, let's say you split where the fourth dimension is 0.4 or higher. They all go to one part of the tree. Everything else goes to the other part. But because each split is only one dimension, if you have a thousand dimensions, you can't usually make very good splits.
No, I mean, if you split roughly in half, you only have log n splits before you, you remain with one item in every box. And log n could be like 10, I don't know, like definitely less than 50. And you have a thousand dimensions. So that doesn't work. Yeah. So you have Product Quantization, which is like a very, very quick way of like iterating through those candidates. And again, a very mathematical, very, very cool field of research has a lot of numerical algebra in it and high performance computing tricks. And it's very exciting. In fact, we actually have a paper coming out showing how we beat the state of the art on that coming up very shortly in probably like a month or so. And then there's a whole field, there's a whole like other type of algorithms that kind of blend the two and kind of create this like graph over your points and say, OK, I'll traverse kind of the map, you know, in high dimensional space. I'll have a set of candidates and I'll just look for the neighbor that gets me in the direction that I want to go and I'll keep going that way. And again, those end up being very efficient sometimes and sometimes kind of they just completely choke. And there's a lot of science about why and when that happens and when they excel and when they're just kind of then the water. You know, I can speak about this for many hours. I highly recommend if you're a computer science major, if you're a mathematician, if you really care about high dimensional geometry, linear algebra and so on. And it's a wide and exciting field where a lot of cool things are happening. It's intimately related to how neural nets are applied and how data is represented. So very cool, very cool field.
Yeah, totally. Yeah. Yeah, I think that it makes a ton of sense. So the quantization, you're saying that through that you don't necessarily need a tree. You're able to get it so fast that once you have that cluster of a million items, you can get the dot product or approximation of the dot product of all million of them really quickly. Correct. Wow, that is so cool. Yeah. For some reason, I totally didn't know that. I thought people were still using KD trees. But, you know, your point is spot on. I guess maybe just to continue the devil's advocacy, like what about ball trees or VP trees or these other things? Is the quantization just the fact that you can parallelize it maybe on a GPU or something? Does that make that more appealing than these other sort of tree ideas?
Yeah. So there are two factors that play in. One of them is the hardware, like you said. Like some algorithms just lend themselves really well to the kind of hardware that you have. So GPUs and so on. And also CPUs, just a memory hierarchy. I mean, the way it's set up, these efficient scans end up being surprisingly efficient. That's one. But the second thing is just like the weirdness of high-dimensional space. You know, we as humans, we are limited to thinking about three dimensions. Like we talk about four and 100-dimensional spaces, but the mental image we have is really three dimensional. And high-dimensional spaces are weird. I mean, they behave mathematically very, very different than low-dimensional spaces. For example, you can ask yourself how many vectors that are exactly orthogonal to each other I can fit in a space of dimension D? Well, they're like, they're exactly orthogonal to each other, and so they form like a coordinate system.
And so in dimension D, you can only fit exactly D of those. Yep. Right. Well, what happens if I give you a little bit of a, like a little bit of flexibility and I say, instead of exactly 90 degrees between two of them, you're allowed to have like 85 degrees between every pair? Right. How many of those can you put together in dimension D? And so in, or maybe instead of vectors, I think about them as like lines. It's going to be go both ways. Right.
Wow. That is remarkable. Wow. That's mind-blowing. I want to put an exclamation point on that. So, you know, everything we're doing is an approximation, right? Everything. I mean, even the fact, the way you got these embeddings was through an approximation. You're using some kind of stochastic descent process. And so, the fact that you're not a perfect 90 degrees, you're still effectively orthogonal with that tolerance. And so what you're saying is that there are billions of ways things can be just completely different from each other.
Yeah. That makes sense. Wow. That is mind-blowing. So, I see. And so then that explains the approximation. Because I was putting a mental bookmark in that because if you do something like KD trees, you can do early stopping. Like at some point, you know, that this partition, this entire subtree is further from the nearest neighbor. You know, even if I was to get the perfect point in this partition, it's still too far, and I don't have to search anymore, and I'm done. But because we're doing this clustering and because we're, you know, there is a chance that maybe you're in between two clusters or something like that. It's just that it's because the clustering is centered around dense areas. The chance that you're not in one of those dense areas is like impossibly small, especially at these high dimensions.
Yes. So even though I think, I think the last point you made was actually maybe the opposite of what I was saying. I mean, I think that, you know, you asked about KD trees and like balls and so on, just maybe to explain to the audience. I mean, the idea is to say, is to say, okay, I'll have everything in one ball and then I'll just, I'll cover my space. I'll just take balls of radius, like one half. Let's say my everything lives in a ball of radius one. I'll just cover my data in balls of radius one-half. Right? So everything lives in there. And then those one-half I'll cover with balls of radius a quarter and so on. Right? What I'm saying is that in high dimensional data, okay. If you have everything in a ball of dimension one, if you had to cover your data with balls of radius one-half. Okay. Every ball will contain one data point. There would be no tree. It was just like, everything is far away from everything else, you know? And so there is no tree. There is no structure. It's just like random chaos. And whether we like it or not, some data is sometimes like that.
Yeah. I see. So clustering. Oh, I see. I see. So, maybe I'll try and get our things. So, so, so clustering is this course thing, but you really only have to do it once. And within a cluster, there's still many entries versus like these tree approaches, you're kind of doing a bad thing many, many times. Like as you're traversing this tree, you're kind of making, you're making log N mistakes, you know, until you get to the leaf. Yeah.
So, I think again, it's hard, at least for me, it's very hard to talk about this abstractly without kind of math and drawings and so on. So, but yeah, it's I'll just maybe try to wrap it up by saying that it's a fascinating set of problems which still have a lot of research going into them. And I highly encourage CS graduates and PE and anybody who's like into this thing and want to see some really gnarly math and really cool engineering. It's a good place to put some time in.
And it's the future of information retrieval. It's a future of how search engines and databases will work. And so like, if you zoom out from the core index, you know, it's like think about making the analog of databases. Like we've just spent whatever, how 20, 25 minutes just talking about features. Right? Or if it's a search engine, we just spent 25 minutes talking about like an inverted index. Right? But we haven't talked about the rest of the database around it. How do you do the embeddings? How do you save them? How do you retrieve from them? How do you do the all the.
How do you update things in place? How do you read and write concurrently? How do you now take this abstract algorithmic discussion and make like an actual hardened production database out of it. That you can go and do information, do like image search on a billion images. Right? In production and not worry about whether it will work or not. Yeah.
I actually had two questions, which I think we'll start to get into the management side of it. One was how do you deal with the fact of that when you retrain the model, even on the same data, you know, unless you keep everything deterministic, which is almost impossible. If you retrain the model, the embeddings are totally different the next time. And so anyone who's using your database and storing the embeddings, for example, is going to be in a real big problem when you, when you retrain. Right? So how, how do you deal with that?
So, for the listeners, Pinecone—the company that I founded and whose CEO is called Pinecone—builds a vector database. That's what we do. Okay? The way we deal with this is we give our customers and our users full control over everything. Right? We are not opinionated on like what embeddings you have, where you know how you create them, or when do you replace what with what. We actually give you full control over your data and how you retrieve from it and what your vectors are. And so we never actually swap your vectors behind the scenes for you. So your query kind of looks one way; a second later, it looks different. You're sitting there thinking, 'What the hell just happened?' You know, if you train a different model and you create different embeddings, then you create like a new vector index in the database. And now you can decide which one of them you want to query. And maybe you phase one out, and maybe you keep both of them, or you do whatever you want. As a data infrastructure, we try to be the least opinionated and the most enabling, just giving all the levers and buttons possible for our customers.
sense. Yeah. I think what you're saying is, again, it raises a lot of other very cool problems. If, you know, if I just tweak, you know, some portion of my data, like, do I have to re-index everything? Do I have to like, how does that work? Do I have access to like both versions of the index with some updated and some not? If I tell me, Oh, I just have all the vectors and I just move each one of them by a little bit. So all the data changes, but not by a whole lot. Do I, can I somehow not just throw everything away and do everything from scratch? Yeah. Right. There's so much to be done. I mean, this is like, and we've, you know, as a science and as an engineering community, we're not even remotely close to being able to answer those questions definitively.
Yeah. We have something in—my background's in Decision Theory, and we have something in Decision Theory called Regular Actor Regularized Regression, or it could be called Critic Regularized Regression. What it's basically saying is let's say it's a robot car. We'll train a model that copies what the robot car is doing right now. So this model, if the robot car—maybe it's being driven by a person, maybe it's not a robot yet, or who knows what it is—but maybe you have a lot of data of real cars, we'll train a model that clones that behavior of these people or of this past system. And then when we go to train the model that's trying to maximize something, we regularize it, which means we add a penalty the further away it gets from this first model. So I could imagine doing something like that where if you keep your entire neural net that generated that embedding, then the next time around, you can add some penalty so that things won't drift too much. SGD is also in high dimensional spaces where—that sounds like it makes sense. And maybe for 99% of the time, it makes sense, but there's still going to be 1% of the embeddings that are going to go to the moon. And so,
Yeah, they're going to change completely. And again, that's fine. What we are trying to achieve is kind of make that layer as robust and just production ready as possible. So you as a scientist or an engineer in a big company, if you want to do semantic search over billions of documents or images or what have you, you get to care about your application and about how you retrieve and how you show it to your customers and what they care about, what models you're using. And not like the entire everything we just talked about, like every all the algorithms and the optimizations and the hardware and the distribution and the systems design. There's so much that goes into it that frankly, you shouldn't care about if that's not your thing. Unless you're me, in which case there is your thing, and it's the only thing you care about.
Yeah. So I just dive into that. There's a bunch of people who are listening to this podcast and thinking this is the coolest thing I've ever seen or heard of in my whole life. Tell us about Pinecone. Are there internships? Where are the internships located? Are there full-time positions? What's a day in the life of Pinecone? Kind of run us through Pinecone as a company.
So Pinecone, first of all, in terms of locations, we have centers in San Francisco, in New York, and in Tel Aviv, Israel. We certainly have open positions all across the board. I'll just say the three or four most critical areas that we invest in. First of all, is the core engine: a lot of high performance computing, hardware accelerations, all the index stuff. That sits mostly in Israel. All the cloud and scaling—how do you take those indexes and those data structures and make them scale at cloud, built to billions of items, and be consistent, persistent, and highly available, and so on. That sits mostly in New York right now. And another thing that sits mostly in New York right now is the management of it. So everything that looks like security, Data Governance, metering, logging, all that stuff. Everything that makes it a management of resource allocation and so on. C: Okay. And the last thing that we invest in is the action of machine learning. So the embeddings, the models, the applications of embeddings and vector representations in real life and things like anywhere from recommendation to text, to images, to personalization, what have you. It runs a pretty wide set of disciplines and locations on everywhere from low-level C++ CUDA and so on, all the way up to modeling and so on. Of course we have open positions both for interns and full-time. Some of them are on our website, pinecone.io. And if you're interested and you're not sure that you appear in those open recs, just send us an email. We love hearing from people.
COVID really threw a wrench in a lot of that, but I will tell you what I feel is most exciting about working at Pinecone. For better or for worse, we've developed this addiction to insanely smart, intelligent people. It makes it very hard to hire people, but most of our folks have either PhDs or high degrees—you know, AWS, Google, Facebook, Amazon—like built huge systems, architected the internals of AWS and S3, and SageMaker, and like Splunk and Databricks. And you know, build unbeatable solutions for whatever, in the optimization kind of people who do crazy things. I mean, I.
Yeah, I did this and that. I changed here and I reorganized all of that. It's like, 'Oh, now it's much faster.' And I was like, 'Oh, shit. I had no idea that was possible.' You know? So you work just with people who just kind of mess with your brain. It's so smart and so talented, and it's just fun. At the same time, it's just—like I said—the problem itself is cool because it runs all the way from data and machine learning to big gnarly systems designed to low-level algorithms, and kind of the whole thing needs to work as one unit. So you kind of have to be very broad to really get it. And so it's just fun. It's just a fun place to work.
That makes sense. And I just wanted to end on this note: who are the kinds of people who use something like this? Because I think some people might look at this and say, 'Well, there's maybe a handful of companies in the world that have a billion images.' But clearly, even people who don't have that much data—you know—it's not just about using a for loop. It's about true management. I mean, you could use a CSV instead of MySQL if you don't have a big company. It doesn't mean that's a good idea. Right? So give us an idea of who is the sort of target audience for this and how broad is that audience? And what are the different verticals there?
Yeah. So it's incredibly broad. I mean, you can—like you said—the fact that you don't have billions of objects, right? Even if you have ten million objects, it doesn't mean you have to start building a microservice for it. You'd rather. And the beautiful thing about consumption-based pricing for Pinecone is that you pay for what you use. So if you have a small use case, it's going to cost you like $50 a month.
Know? So there's the whole management aspect of it, which makes it—you get all the bells and whistles, but you just get a hassle-free experience, right? And that is already a big enough market, right? But you get two different kinds of scaling issues that look very different systems-wise. One of them is just companies who have an unbelievable amount of data, right? So they come to us and say, 'Well, I have, you know, ten billion items. Like what the hell do I do now?' Right? It doesn't fit anywhere. It's just going to cost me an arm and a leg to run anything, right? And companies who have a different scaling issue say, 'You know, I have 10,000 queries per second. What the hell am I like? Yeah. Yeah. What do I do with this?' You know? So now I have this super high availability, low latency system that I have to build. So I have to care about a whole different set of problems.
To all three is hard and exciting. And for somebody like me who that's, you know, what I do for a living, that for me is a worthwhile challenge. But, you know, those, you know, kind of three like buckets are each and every one of them contains thousands of applications and different use cases. And so you don't have to be in Pinterest or Facebook or Google to be facing these issues.
Yeah. I mean, one thing you hit on that I didn't think about until you mentioned it was the SLA, you know, the latency. Because I think with PyTorch and TensorFlow and some of these things, you know, you can do vector math without, like, I don't know anything about CUDA or OpenCL. Or I've just heard these names, but I'm using PyTorch and it can do the job well. But I think that, you know, PyTorch is not designed for low latency. And so if you have a million embeddings in PyTorch, you're stuck. Like, there is nothing that you can really do. You have to go outside of PyTorch to do that. Yeah.
And then, so for that, to get that, you have to, it's like the algorithms and so on. But you have to optimize, you know, even like the way you deserialize JSONs. I mean, you can't be careless about that. You know, it's like stuff like that you don't necessarily think about. Yeah. So it's like everything around it needs to be super optimized for this use case, you know.
One last thing, actually, this is just, I don't want to get too much in the weeds here, but, you know, like with MySQL, you know, people do an insert statement and it seems kind of, you know, you're inserting these tuples. And so it kind of makes sense. So in your case, how do people dump, you know, a billion embeddings into your database? I mean, is like, I guess the API is, it's still like a REST call with like a huge object that's attached to it or something.
So there's this like, you're adding new products, adding new products, adding new products. And then boom, there's like a new embedding model. Everything has to get rewritten. So there's like now sort of this other snapshot that's being spun up. And then when that's ready, you flip them over. And then, yeah, I mean, this is stuff that you do not want to do yourself. I've, I've never done it. It just sounds, it just sounds brutal, just talking about it. I mean, it sounds like a really exciting but hard to do.
So first of all, they can go to our website and they can start a free trial. The free trial right now is two weeks. And so it's not a whole lot of time, but if you're a student and you're working on a cool project and you want that extended, just drop me a note or whatever. We have a chat. Cool. Drop us a note and say, 'Hey, I'm a student. I'm not really a customer, but I'm really, I just really think it's neat. Can I keep using it? Odds are if you really do something cool, we'll just let you do it.'
Very, very cool. Yeah. If people build anything really cool with Pinecone, let us know, let Ido know. We'll have his contact, you know, his Twitter, et cetera, the handle for Pinecone in the show notes. Thanks everybody for, you know, supporting the show on Patreon. We really appreciate that. And thanks for supporting us on Audible if you do that. And thank you, Ido, so much. This was an amazing episode. There's so much more depth we could go into. We could spend a whole day talking about embeddings. We didn't even get a chance to talk about the sort of machine learning part and ResNet and all of that. But, you know, that's, we've done a really good job of covering, you know, the high level. And folks can definitely look up some of the things that we talked about and take it to the next level. Thank you so much. Thank you.
