Welcome, this is the attacks on GenAI data and using vector encryption to stop them talk. I'm Patrick Walsh, this is Bob Wall, we're the co-founders of IronCore Labs, where we help people protect data in their cloud applications by making application layer encryption more easy and practical and usable. So this talk is going to be about the ecosystems around LLMs, but we'll start by talking about LLMs specifically. And in particular, some limitations of LLMs, right? When an LLM is trained, it's trained to predict a plausible completion to a prompt, and that means it can sometimes make stuff up that sounds good but isn't necessarily right. It's also trained on what, by the time it's released, is typically stale data, because it takes a long time to train it, to test it, to fine-tune it, etc. And then finally, it hopefully hasn't been trained on your data, and therefore, if you want it to do things that are cool across, you know, your corporate data, your personal data, or something like that, it's not going to work. And to fill those gaps, there's a thing called RAG, or Retrieval Augmented Generation. Terrible name, basically means stuff extra stuff into the prompt so the LLM can answer questions better. And it works a lot like this. You have a chat app, it doesn't have to be a chat app, it's just like the most common thing you use, right? A user asks a question, and now instead of passing that question to the LLM, the first thing it does is a search. And that search is to find relevant documents related to the query. That all gets jammed together into a prompt, which then goes to the LLM. That's it, that's RAG in a nutshell, you get it. Here's a kind of more practical example of what that looks like. There's a system prompt, there's a history of the previous questions and answers from the chat, and then there's the current, the most recent question, and then stuffed in with that is any documents or web pages or whatever it is that might be related to what the question was. In this case, it's about, hey, what's that draft 10Q? It's a private document that's not public, and that's how it all gets in to the LLM so it can answer questions on that private data. It's fundamental to basically how everyone is using this stuff today, if you're using chat inside an app. And to make all this work, you need to have some type of more intelligent search than what we typically do. Call it AI search, call it semantic search or whatever you want to, and there's a bunch of ways to do this. The most popular right now is an approach called vector search. It's kind of what everyone is doing, although it's not the only way to do it. And vector search and actually all of those AI search type techniques are important because they differentiate between different meanings of words, they can understand a sentence in context, they can understand when arm means a division of an organization versus when arm is a body part or even a verb, right? And in practice, how these types of vector search works is you start with some input document. And that input, did we lose it? And that input document then gets chunked up into pieces. Sometimes it's by sentence, sometimes it's sets of, call it 30 words, or it can be any strategy and often overlapping. But each of those pieces gets run through something that's very similar to an LLM, that sucks, that's very similar to an LLM, but is in fact called a text embedding model. And a text embedding model, unlike an LLM, produces something called a vector embedding. That's not great. Produces something called a vector embedding. And the vector embedding is basically just a long list of very small numbers. And those small numbers can be hundreds or thousands in length. And we'll get into what they mean in a minute here, but to give you some intuition on these, we'll take a look at a list, like a vector that's only three long, right? Because you can graph this in 3D space and you can understand it better. And if we have a bunch of different vectors, let's say we have A and B and we have C, we can kind of look at this visually and say, oh look, A and B kind of look like they're close together and A and C look like they're far apart. In fact, if we run a distance comparison operation like this one, Euclidean distance, although there's a bunch of different ones, they all have the same kind of effect, you can see that A and B are 2.2 apart, whereas A and C are 5.6 apart. And the way this works with search is we take a query, right? It's a sentence, and we reduce it to, let's say, A. A is a vector representation of what we queried, and then we search across all our vectors and we say, give me anything that's similar to A, and then hopefully, if it does it right, it returns B but not C. That's it, that's what vector search is doing, it's the whole shebang. The vector represents the meaning of the content. And to make that work, we have this kind of new concept, or at least new to a lot of us, at least to me, although I guess it's been around for quite a while, and that's called a vector database. And a vector database's purpose is to be able to do these nearest neighbor or approximate nearest neighbor searches across large amounts of data very quickly. And there are a lot of these companies now that are doing this. In fact, last year we saw hundreds of millions of VC money go into the startups that are building vector databases, startups like Pinecone and Weaviate and Quadrant. And despite that, the idea of a vector database is already eroding away to nothing because classic databases like Mongo and Postgres and Oracle are all adding vector capabilities to their existing databases. So you're getting these type of vector comparison nearest neighbor search capability pretty much everywhere that you have a database now. Okay, changing tracks for a second. We started thinking to ourselves, who's using this stuff? Well, we looked at the top 10 SaaS companies and we thought, how many of them are doing adding LLM capabilities over private data? Which means that they're almost certainly using RAG. The answer is 100%. Then we said, well, what about security companies? They wouldn't jump on to just using all this new technology that we don't know how to secure yet, would they? No, 100% of them too. Also adding LLM capabilities on top of private data. Think about that for a moment, right? It means that these AI systems, whatever cloud services and things you're using, they are hoovering up this data. Probably copies of it are going into the vector databases as vectors and among other places, which I'll talk about ever so briefly later. So, do these vectors matter? I was talking to the CEO of one of the vector database companies who's raised tens of million dollars last year and he told me that a vector was like a hash and it was basically meaningless, except for comparison purposes. So, which my first thought is, well, you clearly don't know how people abuse hashes. And my second thought is, you're wrong. So, that isn't how it works at all. If you look at taking a phrase and you reduce it to an embedding vector, an embedding model into a vector, okay, it looks pretty meaningless to us. But then again, so does an animated GIF like this cat if you look at it in a text editor, right? Just because it's meaningless to us to look at, doesn't mean it's meaningless to a computer or in this case, to an AI model. And so, the way you go back from a vector to the original text or something approximating it is using something called an inversion model. An inversion model is just a model that's trained on vectors to sentences so that it can make that same prediction. In this case, it comes close. It's our income is down instead of our earnings is down, right, in this example. 100% match on meaning, not 100% match on words. There are some tens of thousands of papers on this at this point. It's heavily studied in academia, not widely known, I don't think, broadly. Best paper we've seen for text inversions, and it's not just text that vectors represent, I'll talk about that in a second, recovers 92% of exact words. That means full names, everything coming right back out exactly as it went in on the text, okay? The other 8% is basically effectively the same anyway. So are these attacks hard? What's the skill level for doing this kind of attack? The answer is most of these papers have accompanying open source software on GitHub, and so really you just need someone who can run the software, not someone who knows how to build the software, which means it's script kiddy level. And on that note, we actually ran some of these attacks ourselves. We posted some blogs you can check out. We did one on, so I mentioned vectors can represent different things, they can represent images for image search, they can represent faces or voice prints or other things for that. We did one against facial recognition. That doesn't use an inversion model, that's a different technique by the way, so it's kind of interesting for that purpose, and we did one on text inversions. Really good results, like you can really get all the stuff back out or very near approximations of the inputs. All right, so let's talk about these new vector database companies. They probably have good security, right? Actually no, super immature. They'll fix it over time, it'll be fine, but if you look closely at these as we have, two of them have no authentication required by default, right, making the mistakes of Elasticsearch and MongoDB of years past but not learning. One of them has services that are meant to be internal services and that, you know, there's no protection or authentication on them, so that if someone goes to access that because the firewall neglected to block a port, direct access back to the data without any authentication. Two of them claim to have end-to-end encryption when they only have TLS in transport, and more. I could go on, it doesn't matter. The point is that these vector database systems, and for that matter the chat apps, either way, are like total treasure troves of information. And even if you don't use it and invert it, they're at least treasure maps of information because they point back to the data and you can query it. And if you think about that for a second, imagine that you're in a CTF competition in that corner of this thing, and you know, you get into a machine, cool, but now you have to get the flag, and it's in a database, you have to get into the database, and now you have to reverse the schema and, you know, figure out a query and find the flag. It ain't as easy as it sounds, right? It's a lot of expertise and time to do that versus, you know, give me that data. It is, like, incredibly far, far easier to attack these systems because you can do it in natural language. So, what do we think about bringing AI into our infrastructure? Maybe we should pause for a moment and think a little bit about it. Or if it's in there, maybe if you're a hacker in the audience, you should think about, holy shit, there's a lot here. Let me give you some ideas. Obviously, everyone knows about prompt injections. Maybe you haven't thought so much about the fact that you can put a prompt injection in the documents being searched, and they get pulled into the prompt, and you can poison the prompt that way. Logs are everywhere. If you're putting private data into the things that go to the LLMs and the LLMs log it, that's a problem. But also, the prompt firewalls, if you're using those, are logging that stuff, too. So, the data's kind of exploding. And don't even get me started on agents. Talk to me after if you want to hear about my thoughts on that. But if you're generating code to run to query a database, you're beyond hope. Today, though, we're not going to talk about any of that. We're going to talk specifically about this vector stuff and how to protect it. So, basically, today, the way to protect that is to encrypt it. And there's two approaches to this, at least in academia, that you could do. One is fully homomorphic encryption, and the other is partially homomorphic. So, fully homomorphic encryption, there's actually quite a few papers on this, and they're fairly interesting. There's a lot of different approaches. Some of them require sending all the vectors to the server. Some require some other stuff. They typically suffer from being slow. And you would have to build your own vector database and be another logo on that wall and compete with all the other vector databases on every other thing. The other option is partially homomorphic encryption. And the idea here is that something that's partially homomorphic is able to do some operations, but not arbitrary operations. And in this case, we're talking about optimizing for that nearest neighbor search type of operation. So, in this example, partially homomorphic, specific to nearest neighbor searches. And to talk more about this paper and the work that we've done around it, I'm going to turn it over to Bob. All right. We found this paper about a way to encrypt vectors. And you can see the title, Approximate Distance Comparison Preserving Symmetric Encryption. So, that's a mouthful. But this algorithm is a type of property-preserving encryption, which means it's kind of like order-preserving encryption or maybe deterministic encryption, if you've heard of those. The property that this algorithm is preserving, though, is distance comparison instead of equality or order. And so, if you can preserve the ability to compare the distance between two vectors after they've been encrypted, that means your vector database continues to work on the encrypted vectors just as well as it did on the original vectors. So, like deterministic and order-preserving encryption, there's a trade-off. The more secure you make it, the less well the property is preserved. And so, the less well queries might work on the data. So, you have a decision to make about whether you want a lot of security and you can tolerate maybe a little less accuracy on queries, or you want a lot of accuracy on the queries and maybe you'll have a little bit less protection of the data. But the system works by, if you've got a system that's ingesting data and it's making these vectors, putting them into a vector database, it's easy to add this encryption. You just, in the system that's already there, after you've taken the data and run it through the embedding model and generated the vector embedding, you run it through this algorithm and encrypt it, it's still a vector, it looks similar enough to the original vector that the vector database is going to take it and be happy with it. So, you use a secret key, you encrypt the vector, you throw it in the vector database. So, very simple change to the system to be able to do that. Now, most of these vector database systems support storing metadata along with the vectors, and that metadata might have some sensitive data in it too. So, you might want to consider encrypting that. That's a whole different thing. We're just going to focus on the vectors for right now. So, once you've got all of these vectors encrypted, you've loaded them into your vector database. When it's time to do a query, it's also pretty simple. Again, the normal process would be to take the query, run it through the embedding model, get a vector. So, then you just encrypt that vector with the same key and the same algorithm, and then you do your normal search. And because the algorithm, the encryption, preserves distance comparison, that means that when you give that encrypted query to the vector database, it's going to return the encrypted vectors that are closest to the encrypted query, and those are going to correspond to the decrypted vectors, the original vectors, that are closest to the original query. So, you get the same results out, pretty much. And once you get them out, you can maybe decrypt the vectors if you need to, or maybe you've got some metadata that lets you look up the associated data in a database or something else. So, without the key, an attacker can't really understand the queries. They are enough different that they can't look at that and kind of know what the query was. They can't invert the data that's in the database, even if they hacked it, exfiltrated all the data, they can't easily invert it. The results are still fairly accurate. Again, that's a trade-off between the security and the accuracy of their searches. The whole thing is, it introduces a negligible penalty in terms of performance. The encryption process is fast, so you can add this in and not add a lot of time to your process. So, I'm going to talk a little bit more about this encryption function. So, it's a function that maps inputs to outputs, and it does it such that for any distance function, the margin of error that you get when you compare two encrypted vectors will be within some factor, we'll call that beta, the approximation factor of the original distance. And so, if you can build a function that preserves that for any pair of vectors that you give as an input, then you have distance comparison preserving encryption functions. So, in real systems, we kind of talked about this, the comparison function is used for nearest neighbor and approximate nearest neighbor searches, which is what all these vector databases are doing. So, you know, if we can build, and we can, we've built this function that preserves distance comparison, so we can use it to encrypt these vectors. So, the paper introduced this scale and perturb algorithm. And I won't go into a lot of details about how it works, but I will give you a few key points about it. So, there's a scale factor, when you, when you set up the algorithm, you randomly choose this scale factor, and you choose a random key. And so, there's also when you go to encrypt an individual vector, you generate an initialization vector, an IV value, just the same as you might if you're doing symmetric encryption on data with, you know, a normal symmetric algorithm. And you perturb each element of the vector using that key in that initialization vector randomly. So, every element in the vector is going to get wiggled around a little bit. And that amount that it gets wiggled around depends on that value beta, that approximation value. And that's how it limits the change in the distance that you can get. So, the paper had this idea of perturbing the vectors as well. And they basically had this idea of shuffling. If you had all of the vectors, you would shuffle the order of them before you encrypted them. And we wanted an online algorithm so that you could, you know, you just encrypted the vectors as you saw them. So, we didn't find that shuffling to be beneficial. But we did add a shuffle where we took the elements of the vector and shuffled them up. So, we randomly changed the order. And it's a deterministic shuffling based on the key. So, when you get done, all of the elements in the vector have been scaled. And then they get shifted around, which makes it even harder. Even if you knew what the algorithm, what the embedding model was, all of the elements of the vector are in different places, which makes it a lot harder to look at it and try to even guess how it corresponds to the original vectors. So, to give a little bit of a more intuition about this, you can think about these vectors. I mean, a vector is a line from the origin to some point. And the point is defined by the elements in the vector, right? Those are the coordinates of that point. And so, the beta basically defines a sphere in n-dimensional space around that point. And so, as we perturb the elements of the vector, the resulting point is somewhere within that sphere. And the size of that sphere is governed by that beta value, the approximation factor. So, you can see that if you bound the amount that you can move the point around, and you've bound the amount that you've moved another point around, the distance between those is bounded too. So, that's how it manages to preserve the distance comparison. So, in addition, we talked about, we also scaled the vectors up so that they're, you know, they get moved around a little bit, they get scaled. So, if you just look at them, and then the elements get shuffled. So, it's very difficult to correlate an encrypted vector and the original vector that was encrypted. Again, because we've preserved that distance comparison, they're still relatively close together with each other. Here's an example, we kind of turned off the shuffle part of it, so it wouldn't be quite as difficult to see, but you can see, you know, we scaled it up, and then we perturb everything. So, sometimes, depending on how much we perturb stuff, signs on elements might change, you know, they bounce around a little bit, but they're still in this vector. So, we've implemented this algorithm. We've got an open source library we call IronCoreAlloy that's out there on GitHub. It's under the AGPL license. So, if you can use GPL software, you can go grab it and use it. If you can't use GPL software, you can talk to us about a different arrangement. Along with the library, we've got some sample code that shows how you can use it with a number of different vector databases. And as I said earlier, it's easy. So, the examples aren't super complicated. It's pretty easy to drop this into some code that's going to put data in one of these vector databases. The library is written in Rust, but we've exposed it in Java, Kotlin, and Python. We've got some more language support on the way. Along with the examples, we've got some results of using this on some output of different LLMs, open source LLMs. And you can see for an approximation factor of one and a half, which is a pretty modest one, we don't impact the search performance. We measured precision and recall loss, which are pretty common measures of search accuracy. It didn't really impact the search accuracy much at all. So, you know, it works. So now, once we've encrypted these vectors, suppose we want to run an attack on them. We're going to run one of the inversion models that Patrick was talking about. So, we know exactly, somehow we know exactly what the embedding model was that was used. It was an open source one, so we don't have to... we train this up once, and it's going to work on every embedding that was generated by that embedding model. But we're going to try to run it on the encrypted vectors. It turns out, because we've done the perturbation, and we shifted around all of the elements, it's mostly gibberish that we get out. So, you really can't tell much about them. Even if somebody knows the plain text, and they have a black box access to the model, and they're going to submit vectors, get encrypted vectors out for a particular key, and they're going to train their own inversion model, the randomization makes that so that it's very difficult, and you get a lot less valuable results. You might get a little bit of the meaning. You're not going to get exact words. And if you... and again, it depends on what value you use for that approximation model. If you knew the plain text, and you knew the ciphertext, can you extract the key? No. It's based on a probabilistic random function that's essentially like a 256-bit keyed hash. And I don't know about you, but I don't want to spend my next two billion weekends trying to brute force attack a 256-bit keyed hash. So, I'm going to turn it over to Patrick, and he'll summarize for you. Okay, so the takeaways that we hope you have here, as we just did a real brief fast run through on what this is and how it works, is first and foremost, you should walk away realizing that RAG produces a lot of copies of data. So, if people are using AI and LLMs in their applications, and somehow that they're operating over data that model wasn't trained on, probably they're doing this and probably lots of copies of that data are being made. It's sprinkled everywhere. And vector databases are like a key part of that. Second thing is that vectors and vector databases can be inverted back to their original input or something very closely approximating it, right? High fidelity and low effort attack, and oftentimes an attacker won't even need to do that. If they have access to the chat app, they can bypass that even. But never mind, if they have access to the vector database, that's as good as having access to the chat app, right? And then the third takeaway that we want you to walk away with is this. It isn't that hard in this case, because there's a built open source library to implement a solution to this problem in your software. So, if you want to, feel free, check out the results, go try it online. The results you get in a vector search are really close to the original. Like, it looks the same to me pretty much across the board. The benchmarks show a few percent differences. There's almost no performance penalty. From a latency perspective, there's almost no reason not to encrypt your vectors if they contain sensitive data in them. And that's it. Thanks for your time today. We're going to be out there, probably just outside the Creator Stage area, if people want to chat with us or have any questions. Thanks for your time.