WEBVTT

00:00.080 --> 00:02.960
All right, here we are, our super bass project rag.

00:02.960 --> 00:03.800
I went and got a coffee.

00:03.800 --> 00:04.840
I came back and it's done.

00:04.840 --> 00:05.920
It takes a few minutes.

00:06.360 --> 00:09.840
So let's just look around this navigation as we're looking into our project.

00:09.880 --> 00:14.960
Of course, the way you get here if you ever get lost is if you're on your projects page, you simply

00:14.960 --> 00:16.440
come into rag and back.

00:16.440 --> 00:17.560
We are here again.

00:17.560 --> 00:20.600
And looking at the nav here, we can be looking at tables.

00:20.600 --> 00:26.400
We can looking at something called SQL, SQL which you probably know is how you, you you ask questions,

00:26.400 --> 00:32.200
you query your database, the database itself, uh, and then a bunch of other stuff.

00:32.440 --> 00:35.920
If we look at the database itself, loading tables, we have no tables.

00:35.920 --> 00:37.760
It's an empty database.

00:38.080 --> 00:38.600
Okay.

00:38.640 --> 00:39.000
Back.

00:39.000 --> 00:41.920
We go back we go to the project overview.

00:42.160 --> 00:43.000
Here we are.

00:43.200 --> 00:48.400
And now is the one thing I told you I was going to do something that's kind of Cody.

00:48.400 --> 00:53.160
And so for those of you that are engineers this is going to be like, sure, this is easy for those

00:53.160 --> 00:55.880
of you that aren't this is going to be like, Holy cow, what is this?

00:56.120 --> 01:02.720
And and I'm here to tell you that it honestly, it's very cookie cutter stuff.

01:02.880 --> 01:08.230
Whilst you do need to run some code at this point, which you will find in the in the course resources

01:08.270 --> 01:09.830
tell you exactly what to do.

01:10.030 --> 01:13.070
This is a very pedestrian activity.

01:13.350 --> 01:14.550
And here's the thing.

01:14.870 --> 01:20.630
You could ask ChatGPT to write this for you with some instructions, and it would do it in a heartbeat.

01:20.830 --> 01:24.710
And in fact, as like a just a dark secret that's just between you and me.

01:24.750 --> 01:25.910
Don't tell anybody else.

01:25.910 --> 01:29.150
But I got ChatGPT to generate this for me because I hate SQL.

01:29.150 --> 01:31.590
I always seem to make mistakes with it, so I didn't want to do that.

01:31.590 --> 01:33.310
I just asked ChatGPT to generate it.

01:33.310 --> 01:36.070
I told it exactly what it needed to do and it did it right away.

01:36.470 --> 01:42.190
You can use that or code or whatever you like to use, but when you're ready, I need you now to go

01:42.190 --> 01:48.670
to the SQL editor, which is where you get to run code should you wish, by pasting it in there and

01:48.670 --> 01:50.470
pressing that run button down there.

01:50.510 --> 01:51.910
And that's what we're going to do next.

01:51.910 --> 01:58.390
So the reason we're doing this is because the tables that come with the super base database aren't,

01:58.390 --> 02:02.390
by default, set up to be exactly the format that Nam would like.

02:02.390 --> 02:06.710
And it's not like there's a there's a sort of out of the box way to say, hey, make me the tables and

02:06.750 --> 02:07.310
expects.

02:07.310 --> 02:11.910
So we have to create the database in that particular format so that this will work well.

02:11.950 --> 02:15.750
And so if I paste in this SQL, this is the SQL that you should be able to copy and paste also from

02:15.750 --> 02:16.510
the resources.

02:16.510 --> 02:21.790
And let me just quickly say at a high level, because there is one janky thing about this one janky

02:21.830 --> 02:22.150
thing.

02:22.350 --> 02:27.510
Uh, so this basically says, I want you to create a table called knowledgebase that is going to be

02:27.510 --> 02:28.630
the database table.

02:28.630 --> 02:29.630
It's going to create.

02:29.790 --> 02:35.310
And I want every row on that table to have an ID content, which is going to be the text that we just

02:35.310 --> 02:41.790
built in metadata, which is going to be the metadata including the category and then the vector.

02:42.070 --> 02:44.030
The embedding vector.

02:44.030 --> 02:46.350
And this is the janky thing that I'm going to come back to.

02:46.790 --> 02:51.950
And then I need to make a single a function in the database called a match documents.

02:51.950 --> 02:55.230
And this is a function that expects this is a function.

02:55.230 --> 02:59.350
It's going to want to call when it wants to retrieve relevant context.

02:59.350 --> 03:03.910
And as I say, if you go with like like some database setups, this will all be automatically built

03:03.910 --> 03:06.350
and will be exactly what Nan is expecting.

03:06.350 --> 03:09.510
And we only had to do this because we're going pro with Supabase.

03:09.790 --> 03:12.790
So we're creating this function, match documents.

03:12.790 --> 03:14.830
We're saying that it should return some information.

03:14.940 --> 03:17.220
and this is what the function needs to look like.

03:17.260 --> 03:24.580
And basically it's because when you when you do the natural calculation in the base table with this,

03:24.580 --> 03:29.020
this Postgres function, it gives something slightly different to what Nam would like.

03:29.060 --> 03:34.580
And you have to take one minus that calculation in order to get just the right number for super base.

03:34.580 --> 03:35.780
So this stuff doesn't really matter.

03:35.780 --> 03:41.580
If you wanted to generate this for you, you would just simply say the ChatGPT hey, can you make me

03:41.940 --> 03:42.420
something?

03:42.420 --> 03:49.060
I can run in super base in Postgres, which would allow me to set up a table called Knowledge Base that

03:49.060 --> 03:55.180
would be in the right format with content and metadata, and a vector that Nam would expect, and it

03:55.180 --> 03:58.100
will generate something just like this, as it did for me.

03:58.420 --> 04:01.220
Okay, now let me explain the one janky thing.

04:01.220 --> 04:02.060
So here's the thing.

04:02.380 --> 04:07.340
People that are relatively new to Rag sometimes think that the the magic in rag is something to do with

04:07.340 --> 04:08.940
what's in the vector database.

04:08.940 --> 04:14.900
These vectors and and whilst it's true that magic is in the vectors, the vector database, it's just

04:14.900 --> 04:18.740
an efficient database that can deal with with, with similarity calculations.

04:18.740 --> 04:22.260
The thing that's doing the magic is the embedding model.

04:22.260 --> 04:28.060
It's the LLM that's able to take text and turn it into a vector, and that's outside Postgres.

04:28.060 --> 04:32.820
We're about to set that up in N810, and that's going to come up with a vector and pass it in.

04:32.980 --> 04:38.900
And what Postgres and Superbase is able to do well is store that vector.

04:38.900 --> 04:42.100
But but this database doesn't actually create the vector.

04:42.500 --> 04:47.780
And that means that there is one important thing that needs to be set up when you create the database.

04:47.780 --> 04:54.180
And it comes down to this, this idea of, of dimensions, it's the question is how many dimensions

04:54.180 --> 04:55.740
are the vectors going to have.

04:55.780 --> 04:59.380
Because this database needs to be set up to expect that.

04:59.380 --> 05:03.700
And that is a is a is a feature of the embedding model that we choose.

05:03.740 --> 05:07.580
As I say, you can imagine one that just comes up with three numbers that you can imagine.

05:07.580 --> 05:09.220
Some come up with thousands.

05:09.220 --> 05:11.580
And so you have to pick a model.

05:11.740 --> 05:17.420
And then that you have to make sure that the number of dimensions that the database is expecting matches

05:17.420 --> 05:18.540
your embedding model.

05:18.740 --> 05:26.940
And in our case, we're going to pick a really standard typical first choice, which is to use a model

05:26.940 --> 05:30.340
that called called OpenAI embedding small.

05:30.340 --> 05:38.020
And it's a great model and everyone uses it, and it happens to have 1536 dimensions.

05:38.020 --> 05:42.380
And that number one, five, three, six needs to go in these two places here.

05:42.420 --> 05:44.060
And that is a bit janky.

05:44.060 --> 05:45.900
I do agree that seems like what.

05:45.940 --> 05:51.300
So if you put one, five, three, seven one off, you're going to get a weird error at some point about

05:51.300 --> 05:52.940
mismatching dimensions.

05:52.940 --> 05:53.940
And that's no good.

05:53.980 --> 06:00.060
So that has to be right now OpenAI embeddings model does have a charge associated with it, but it's

06:00.060 --> 06:01.180
really tiny.

06:01.220 --> 06:03.420
It's really tiny for huge numbers of documents.

06:03.420 --> 06:05.780
And so it's super tiny for 60 documents.

06:05.820 --> 06:10.260
Nonetheless, I know that that OpenAI needs an upfront payment and you might not want to use that.

06:10.260 --> 06:14.940
Gemini has a great embeddings model two, and if you know what you're doing with open source, of course

06:14.940 --> 06:16.700
the open source models are free.

06:17.180 --> 06:21.140
And if you do choose to go in that different direction, the only thing you need to know is once you've

06:21.140 --> 06:26.140
picked your embedding model, you may have to come back and rerun this with a different number.

06:26.140 --> 06:30.490
In here you can run this, this, this recreates the table if it already exists.

06:30.490 --> 06:32.010
You can run this as many times as you want.

06:32.050 --> 06:38.690
Just make sure that the last time you run it that the number of dimensions that you specify here matches

06:38.690 --> 06:40.650
the embedding model that you pick.

06:40.690 --> 06:48.050
And if you stick with the plan and you pick OpenAI's model, then 1536 is the perfect number to have

06:48.050 --> 06:48.450
here.

06:48.450 --> 06:50.490
So I appreciate that.

06:50.530 --> 06:52.930
It's a bit weird to to to have it like this.

06:52.970 --> 06:58.290
It seems like a bit of voodoo, but but uh, yeah, you need to make sure that the dimensions in your

06:58.290 --> 07:03.810
embedding model matches the number of dimensions that you tell super base it needs to create in this

07:03.810 --> 07:04.690
database table.

07:05.010 --> 07:07.650
All right, that's a long explanation.

07:07.690 --> 07:08.570
Time to run this.

07:08.610 --> 07:10.570
Ah, but wait, there is one more thing we need to do.

07:10.610 --> 07:11.770
Just before we run this script.

07:11.770 --> 07:18.970
We have to just tell Super Base that we're using vector related stuff with this database.

07:18.970 --> 07:25.610
And the way we do that is you go over here on the left to the database section, and you go to extensions

07:25.770 --> 07:26.730
right here.

07:26.730 --> 07:30.010
And you see all these extensions here, type vector.

07:30.170 --> 07:31.330
And this comes up.

07:31.330 --> 07:35.120
And then you turn that on and here we go.

07:35.160 --> 07:36.520
Enable extension.

07:36.760 --> 07:37.640
Let it think.

07:38.160 --> 07:38.880
And it's done.

07:38.880 --> 07:42.200
Extension vector is now enabled.

07:42.400 --> 07:45.480
And now come back to the SQL editor.

07:45.600 --> 07:46.320
Here we go.

07:46.360 --> 07:49.320
You see the arrow I got down there because I didn't do it yet.

07:49.400 --> 07:53.160
Uh, and now we should be able to run and get a better result.

07:53.200 --> 07:54.120
Okay, here we go.

07:54.120 --> 07:54.680
Run!

07:55.000 --> 07:55.760
Running.

07:55.760 --> 07:59.160
It says success.

07:59.160 --> 07:59.840
No rows returned.

07:59.840 --> 08:00.480
That's what we wanted.

08:00.480 --> 08:02.120
We didn't want any rows returned.

08:02.320 --> 08:04.360
And now to check that it's really been successful.

08:04.360 --> 08:06.040
Like it says we go to database.

08:06.400 --> 08:08.560
It says it said for a moment it said no tables.

08:08.560 --> 08:09.200
But there it is.

08:09.200 --> 08:11.720
There is our knowledge base database we've set up.

08:11.960 --> 08:16.320
It has an ID, it has content that's going to be the stuff.

08:16.360 --> 08:21.720
It has metadata and it has embedding, which is our vector.

08:21.920 --> 08:24.280
This is where it's going to go.

08:24.480 --> 08:26.040
So we've done it.

08:26.040 --> 08:29.040
We've set up a super base database.

08:29.040 --> 08:37.360
It's now time for us to go to back to N and to hook it all up and then populate our database, do the

08:37.400 --> 08:39.280
load part of ETL.
