And so what do we do about this? This brings us to the idea of retrieval augmented generation. This is one of the ways in which we can give a large language model more context with which to answer. The idea behind retrieval augmented generation is we take all of our up-to-date or private data and we store it somewhere.
When a user makes a query to a bot that we've built, we use that query to retrieve relevant data about the query, provide that data as context to the model alongside the original query, provide how the model to generate a response using that context, using information that it couldn't have known previously, and then eventually I guess profit. That's the idea here.
How the difficult part of this actually, you know, because models have been made, we know this, and they keep improving and getting better. The difficult part for us is to retrieve relevant data based on something like a natural language query. And so this is how it all fits together.
So retrieval in this retrieval went to generation retrieval is that search step against your data that you want to make available to the bot. The augmentation is where you turn it into a prompt and finally the generation is handled by a model. And we're going to talk about the search side of this because this is the most important part. And so it's important that it's natural language search. It's not keyword search. We want to search by similarity of meaning.
This gives us the idea of vector embeddings. Vector embeddings are a list of numbers, ultimately, that represents the meaning of a body of text. And we can generate these in different ways. We'll have a look at a couple of those ways today, starting by creating our own vector embedding.
So I have a hypothesis for this. For a bot about a conference, say JSNation US where we are, the titles and descriptions contain the meanings of the talks that we're going to see. Those titles and descriptions are made up of words. Provide me here. And titles and descriptions that share words are similar. And so also natural language queries that also share words that are in those titles and descriptions are probably asking about those specific talks. And so if we collect all the words and represent each talk as a count of each of the total set of words, then when we get a user query we can do the same thing and compare them, ultimately getting similar words based just on the similarity of similar talks and queries based on the number of words that they share.
And so let's go and have a look at this. I've got this useless kind of event chat right now, but I have the code for that over here. And so what I've done is I scraped all the talk descriptions for JSNation US and I've got those in a big array of JSON file. I'm going to go and do some processing on them. So we're basically cutting out punctuation and common words, because those common words in my hypothesis don't really capture any of the meaning, because they're just I, me, myself, like not particularly useful stuff.
Comments