Hello guys.
So we are going to continue our discussion with respect to login with Graphdb.
Now I will be showing you like what generative AI project that we are specifically going to create with
the help of Lang Chain along with Graphdb.
Okay, so here the plan is very simple.
Let's say if a user queries right, let's say if a user is querying anything right now with respect
to this specific query, this will probably initially go to our LMS, right?
My LM models.
Let's consider this as my LM model.
Now this LM model, what it should be doing is that it should be creating my Cypher query.
Cypher query.
Let's say if I go ahead and say, hey, who was this particular person who was acting in this particular
movie?
If I asked that question to my LLM, my LLM should be able to create my Cypher query, and once I get
my Cypher query, it should be able to probably query from our graph DB database.
Right.
Let's say this is my graph db database.
Okay.
And once it is able to query right again, it should probably get the response from this.
Give it to my LM model.
And based on our prompt it should be able to give our output okay output response.
So uh this is the entire thing that we are specifically going to create.
And if I probably consider this entire thing this block.
Right.
This block where we are specifically using LM, uh, Cypher query graph DB.
So this is my.
Graph DB right.
This is specifically called as graph agent.
But here instead of, you know, only generating a Cypher query, we are also going to use a graph DB,
and we are going to query with respect to the specific query that the user is putting.
And once we get the output, we should basically be able to combine with a prompt along with the my
LM model and get my output response.
Okay, so this is the entire project that we are going to develop with respect to our, uh, that we
are specifically planning in this particular project.
Okay.
So let's go ahead and, uh, let's generate this particular project.
So I'll just go ahead and write one.
And uh, I will keep this like Q&A, right.
Q&A with graph I will write graph DB.
Okay.
So this is done I guess.
Now the first thing first what I will do is that inside this folder I will go ahead and create my experiments
dot p Ipynb file.
So that will get an idea how to probably go ahead and start this.
Okay.
So first of all we will go ahead and select our kernel.
Once we go ahead and select our kernel I am just going to go ahead and create a markdown.
Let's say over here I'm going to use this three quotes.
Okay.
So here we are basically going to build a question answer application over a graph database okay.
So to start with uh the first thing that you actually require is all this information right.
So here at least you have this URI username password right.
Instance ID and instance name is not required.
So I will just go ahead and initialize this right over here.
So let's convert this into strings.
So I will just go ahead and initialize all these things.
Or you can also directly put it in your environment variable if you want.
Okay.
And you can probably read from those environment variable okay.
It is up to you.
So okay it is saying me to install the ipy and b uh, sorry.
Uh ipykernel.
So I will quickly go ahead and open my terminal.
I will say, hey Pip, install Ipykernel because that is required when you are probably using Jupyter
Notebook for the first time.
Right.
And the environment that is specifically used over here is 3.12.
So let's this installation take place.
Till then we will just wait.
And then once the installation will be completed, we will continue.
So here you can see guys, the ipykernel installation is done.
So I will close this.
Now let's go ahead and execute it once again.
Now you can see it is connecting to the kernel.
And now it absolutely works fine okay.
Now the next thing is that I will just go ahead and import OS and we will go ahead and set up all these
environment variables.
Right.
So specifically, whenever we set up this environment variable, we are going to set it for Neo4j's
URI username and password.
Okay.
So uh this URL we will try to replace it with Neo4j's URI.
So let me quickly go ahead and do this.
And similarly we will go ahead and replace this with our username.
At least we require this three important information.
And this will basically be my new 4G password.
Perfect.
So till here everything looks good.
Now in order to start working, first of all, I'll execute all since I've set up all the environment
variables over here.
Now, the next thing that we are going to do again I will go ahead and write from long chain underscore
community okay.
Dot graphs.
So long chain community actually provides this library in graphs which is nothing.
But it is a class which is called as Neo4j's graph.
Now this Neo4j's graph actually helps you to connect to your DB with the help of this information.
That is Neo4j's URI username and password.
So here I'm going to go ahead and create my graph.
And here you have this Neo4j's graph with URL is equal to.
So first information that I want is even though I have actually set up my environment, you can also
directly pass all these values over here.
So let's go ahead and pass it.
So Neo4j's URI.
Then along with this my second is second parameter is nothing but username.
So I can go ahead and write Neo4j's username.
And the third one is something called as password whatever password we have.
And here also I will just go ahead and write Neo4j's password.
So this way also you will be able to initialize your graph which is basically connecting to your entire
database.
Right.
So once you execute this here it shows that hey Lincoln underscore community dot graph Neo4j's underscore
graph.
At this specific memory location the object is basically created.
Now let's see in for which data set we are going to specifically work okay.
So data set that we are going to work is nothing.
But it is with respect to movies uh data set.
It has some of the information like which actor has probably worked and all and.
All right.
So here, uh, let's see this particular data set that we are going to use.
So I'm just going to close this okay.
So here is the data set.
So here you can see I've opened this movie's underscore small dot CSV file.
It is available in this GitHub location.
It has informations like movie ID release title actors directors see directors can be many.
So you can see over here you have like Jim Jim Varney, Tim Allen, Tom Hanks, Don Nickles.
Right.
So Don Rickles, then you have General Jim Generals, then you have ID and B ratings.
Right.
right.
And with respect to a journalist right here also, you'll be able to see that it has adventure animation.
So it has that pipe symbol.
Now what we are going to do is that we're going to go ahead and read this entire URL right now.
Already I've already shown you how to probably go ahead and read this particular URL.
So first of all we'll go ahead and create our query okay.
So let's go ahead and create our query.
So I'll say hey this is my movie query.
And this time I'm just going to use a triple quotes okay.
So this will be my triple quotes here I'll say hey let's go ahead and load CSV okay CSV.
And here uh, and I have to also make sure that I provide with headers from because this is the query
initially we need to have some data.
So that is the reason I'm writing the Cypher query language right.
And then I will go ahead and put this entire URL okay.
Now from this I will make this as row okay.
So it will be when I say as row it is going to take with all the headers right.
So as row we will be taking all the row right.
And then we will also make sure that we will merge this okay.
Now see merging is very much important because there are so many features that is available.
So first of all, I will go ahead and create a node with movie M right M and this will basically be
my label.
So and please make sure that whatever things I'm writing, you follow that same steps.
Right inside this movie you will be having two important features.
So if I go ahead and show you.
So this is nothing but movie ID, right?
So in order to access this, I will just go ahead and create my property, which is called as ID.
So here I'm going to basically write ID colon right row dot movie ID okay.
So but inside this movie ID also you'll be able to see that um, along with this movie ID so if I go
ahead and see over here, you'll also be seeing that same for that particular movie ID there are information
like a release titles, actors, right Id.me ratings and all right.
And obviously when I'm using this released, uh, let's say title is also there.
Right.
And I'd and B ratings are there remaining.
All are like they are like actors.
Also there will be many actors directors also there will be many directors.
So first of all, let's do one thing.
Let's take all the single fields and probably create that many number of features in short right or
property keys.
So I'll go over here.
Now see this.
What I will do I will say hey go ahead and set all this features.
That is M dot released is equal to date.
We are converting this particular value row dot release to date okay.
And then I have this row dot title m dot idb m rating to float row.id rating.
Okay.
So all these things are done similarly for directors.
For directors we will go ahead and use for each loop.
So here you will be able to see in Cypher Query.
You also have this for each directory in split Road or Director with this pipe symbol.
Then you have this P person name is equal to name trim director then merge p director with respect to
this particular m value okay.
So this are all the directories we are going to put inside our person node itself.
Right.
Or person entity which we have actually created.
And we are also going to create a relationship with respect to P with movies.
Right.
With all the movies information.
Okay.
Then, uh, similarly for the actor also we will be doing and we also need to create another relationship
that is called as acting in acted in.
Okay.
So here directed here acted in okay.
And again we are going to basically do trim dot actor.
We are using this pipe symbol to separate all the actors from that movie okay.
And similarly you will be able to also see that there will be a joiner field.
Right.
And joiner also we are using a pipe symbol.
So again joiner in Split Road or joiners genres.
We are using this pipe symbol again.
We are saying merge on or name trimmed or genre.
Then we are merging this by creating a relationship over here with this G right?
And G is nothing but genre.
So movie with genre is basically created as a relationship person with movie.
We have created a relationship like actor P directed with M, we have created like this.
Okay, so this is the query to probably load this entire data set.
So I will go ahead and execute this.
So if you go ahead and see my movie query okay.
So here you'll be able to see this is my entire query.
Right.
Perfect.
Great.
Now what I'm actually going to do I'll just go ahead and write graph dot query okay.
So if you go ahead and see this definition the Cypher query to execute whatever query that we are going
to execute over here.
So let's go ahead and write this movies query okay.
So once I execute this here you'll be able to see I'm getting some blank okay.
But no worries.
Uh, let's do one thing.
Let's take this entire graph and refresh its schema.
Okay.
So I will go ahead and write refresh schema and we will go ahead and print our graph dot schema.
Okay.
So here you can see all the information right.
Node properties.
This all all the previous information that I had uploaded.
Right now you have movie user post this right relationship.
Also you can see a person acted in movie directed in movie.
These all are my previous information that I had right now.
Let me do one thing.
Let me just go back to my Neo4j's DB.
So let's reload this.
I don't know whether we will be able to reload this or not, but it shows.
Disconnected.
No worries, I will go to my home page of Neo4j's.
Okay, so let me just go ahead and write new, Neo for J or RDB and I will go ahead and click this start
free.
It will tell me to log in okay.
So I have logged in over here.
I will go ahead and open it and it will tell me to connect let's say whether it connects or not.
These are all my queries that I have actually created.
And it has also been attached.
Right now let's go to the database.
Here you can see in genre.
So if I go ahead and click this see amazing graph is basically getting created.
That basically means my entire data has got just inserted right.
Romance.
Drama.
Father of the bride part two.
It is a comedy genre comedy.
Toy story two comedy.
It is fantasy.
It is having this animations and.
All right.
Amazing.
Right.
And, uh, if you go and and see acted in.
Right, this is a huge database again.
So with respect to acted you'll be able to see over here.
Let's see with uh acted in I will just go ahead and click it.
See forest white text acted in species.
Uh burnt by Nikita mike.
I guess they have acted in different movies.
Clint Eastwood this jawlensky French twist.
Right?
So this is the kind of data that we have already there.
Okay.
Along with this, you know that we have also created directed, right?
So if I go ahead and click on directed, there's so many directors see Oliver Stone and all.
So with respect to person, how many persons are there?
If I want to double click this, it will show a relation.
It has directed heat Jon Lester, it has directed Toy Story.
Right.
So this is a simple way of just showing you that how with the help of using this graph dot query function.
Right.
We use just just this graph dot query to probably insert this entire data.
Right.
And let us executed the entire query itself inside the graph database.
Now, uh, this was the basic fundamental of inserting.
Now in my next video we will go.
We'll proceed further.
And then I will try to ask any kind of questions with the graph DB with the help of LLM.
And I think I should be able to get the answer.
And that is what we are going to see in the next video.
This was it.
I will see you all in the next video.
Thank you.