Check out a free preview of the full AI Agent: From Prototype to Production course
The "Create an Upstash Vector Database" Lesson is part of the full, AI Agent: From Prototype to Production course featured in this preview video. Here's what you'd learn in this lesson:
Scott introduces Upstash which is where the movie data is stored and indexed. Upstash is a vector database that allows for querying and filtering. Results are returned based on their proximity or correctness.
Transcript from the "Create an Upstash Vector Database" Lesson
[00:00:00]
>> Scott Moss: We need to set up an account here on Upstash for our vector database. It's free, does not require a credit card, you just set it up. So I'm gonna walk you through how to do that. I have all the notes in here, but I'm just gonna do it on my screen, so you can just follow along.
[00:00:13]
Basically, what you wanna do is you wanna go to upstash.com. Upstash is great in my opinion. I will talk about this product, cuz I think it's great, I use it for everything. It's a great product, [LAUGH] I recommend checking it out. But we're gonna use it for vector databases.
[00:00:30]
So once you make an account, log in. Does not require credit cards, it's a simple GitHub or Google login. Can't remember if they have you make a team or something like that, but whatever they have you do. I think they give you a personal one. Regardless, when you get to this screen, click on Vector.
[00:00:47]
Once you click on vector, you can click Create Index.
>> Scott Moss: Inside of Create Index, you can just give it whatever name you want.
>> Scott Moss: Whatever. Pick whatever region is closest to you, doesn't matter.
>> Scott Moss: For the embedding model, this is important. Do not put Custom. If you put Custom, you will not be able to follow along.
[00:01:17]
Custom means, hey, so Upstash Vector does the embedding for us. We just sit at our text, it will convert it to a vector and put it in a database, if we pick one of these. If we pick Custom, it's assuming we're gonna convert it on our side and just give them the vectors.
[00:01:36]
We're not doing that today. We can, OpenAI actually does have a really good embedding model, so we could just do it, but we're not. It's so much easier just to send Upstash text than it is vectors. So we're just gonna pick the big one here, the mixedbread. This one has a dimension of 1,024, it's pretty big.
[00:01:54]
I think OpenAI's big one is 1,536, so even bigger.
>> Scott Moss: So that means one embedding is gonna be 1224 numbers or vectors. That's one embedding. Every time you make one embedding, there's 1024 decimals in there. That's just one embedding. And you might have one movie, maybe not in our example, but if you did multiple, each chunk is 1024 numbers.
[00:02:24]
So if you have hundreds and thousands of chunks, multiply that by 1024, that's that's how much is in there. So it can get pretty deep. Metric, we'll just pick COSINE. These are the different searching algorithms that I was telling you about. How do they determine the distance between two vectors, or many vectors, to see how similar they are?
[00:02:45]
They have COSINE, EUCLIDEAN, and DOT_PRODUCT. We're just gonna pick COSINE. I don't know the difference between the three, I'm gonna be honest. If you know, let me know. I always just go with COSINE. And then you can click Next, and then you can just click Free, free forever, you get 10,000 updates, 10,000 queries a day for free.
[00:03:00]
That's more than enough for what we need to do today. And then you can click Create.
>> Scott Moss: Aand you can make as many of these as you want, as far as I know. Once you have that you wanna click on env and click this copy button right here, which will copy these two env vars.
[00:03:21]
Put them in your .env file. Put these two env vars in your .env file, and you are set up. That's it. All the NPM modules are already installed, you just need to add these to your .env file. Cool, and just to show you the example of what RAG looks like, let me see here.
[00:03:44]
I already have an index. I'm gonna go back to my other index that I have with my movies in it, here. I have 1000 movies in here. I'm gonna click on Data Browser. And just to show you how the vector database works, right? So let me say, movies about space, and, yeah, movies about space.
[00:04:04]
Let's just query that, let's see what happens. Cool, the first thing that it came back with a score of 0.85, which is really high, I would say anything over 7 something is pretty high, is gravity, which makes sense, cuz that's a movie about space. So it found it, and then Interstellar, and then WALL-E, and then Independence Day, and then Jupiter Ascending.
[00:04:24]
So it can get pretty good, right? And so it's taking this, it's turning it to a vector, and this is the other pieces of vector that it's creating. You can see the vector representation of that right here. I'm gonna copy this just so you can see what this looks like.
[00:04:40]
Let's go down here.
>> Scott Moss: That's just one of those. So that's the array of 1000 numbers that I was talking about, right? So that's where the math is coming from. So it's pretty good. So this is like a little playground. They actually have a RAG Chat where you can go here, add your OpenAI key.
[00:05:05]
And it's a chat app where you can chat with your data, right? So it's pretty cool. But I don't feel like adding my API key, so I'm not doing that.
Learn Straight from the Experts Who Shape the Modern Web
- In-depth Courses
- Industry Leading Experts
- Learning Paths
- Live Interactive Workshops