LlamaIndex Crash Course - AI Agents in Python

NeuralNine · Beginner ·🧠 Large Language Models ·5mo ago

Key Takeaways

The video provides a crash course on LlamaIndex, an AI agent and RAG framework for Python, covering its installation, usage, and customization with various tools and models such as OpenAI, Olama, and Google Geni.

Full Transcript

This video today is going to be a crash course on llama index which is an agentic framework for Python similar to langchain but I would say it has a stronger focus on retrieval on rack on retrieving context on parsing different data sources connecting to different data sources. I would say that for the most part you can do with lang chain what you can do with llama index and vice versa but langchain is more general and llama index is more focused on as I said advanced retrieval techniques and we're going to talk about that a little bit but mainly this video today is going to be a beginner friendly introduction to llama index so we're not going to go into the very deep low-level advanced retrieval techniques I'm going to maybe mention them in the end but primarily this crash course today is for giving you an introduction into llama index so you know how to build agents how to do function calling, how to do basic rack, how to connect different data sources, vector stores, embedding models, and so on, how to work with llama index on a basic level. If this video performs well, I'm going to go deeper into it as well. If you like this video, let me know by hitting a like button and subscribing. But now, let us get right into it. It's not a game, it's a red. [music] >> All right, so we're going to do a crash course on Llama Index today, which is as I already mentioned in the introduction, an AI agent framework for Python, similar to Langchain, for example. Which already brings me to the first thing I want to briefly cover the question, should you be using Langchain or should you be using Llama Index? And I want to keep it short here. So my answer is whenever you're comparing frameworks, unless one of the frameworks is obviously inferior in most aspects, you should probably try both. See the pros and cons, maybe even learn both. So you have multiple tools in your arsenal, in your toolkit, and then pick the one for the respective use case. So if you're doing something very rack heavy, something that's focused a lot on retrieval, on indexing, on dealing with different data connectors, then Llama index, usually rule of thumb is the better choice. If you're doing something more general and end to end, then Langchain is usually the go-to framework. Besides that, of course, you can also have preferences in terms of the codebase. People say that the Llama index codebase is very clean. The Langchain codebase is not so clean. I don't really have an opinion on that. I didn't really look into the code behind the scenes. But in general, my opinion is always try to learn both. Same thing with PyTorch and TensorFlow. Yes, PyTorch nowadays is the more popular, more commonly used framework. But I think it's good to know both um technologies, frameworks, whatever. So I would recommend learning Llama index in general and especially if you're interested in doing something focused on retrieval data and data connectors. That's enough talking now. Let us get started with the environment setup. For this, I'm going to navigate to my tutorial directory in the terminal. And I personally like to use UV as a package manager. So I'm going to do that. If you just want to use your Python installation, feel free to do whatever I do with UV on your basic Python installation. And so just do pip or pip 3 install and then the packages that we're going to need today. In my case, I'm going to do UV init to create a UV project. And then I'm going to say UV at instead of pip install. Same effect just that I have this rustbased package manager and I have the isolated environment. Don't have to do that if you don't want to. But the packages that you're going to need whether you install them with UV add or pip install are of course llama index and we're going to also need python-.en N and Jupiter lab. So why do we need these packages? Llama index for obvious reasons. Python.enf to load environment variables from a so-called N file because we need an API key to interact with large language models. And then we're also going to use Jupyter Lab as our coding environment. Besides that, I think I don't have anything in the code that I prepared that needs external packages. What I would also recommend if you want to follow along with every aspect of this tutorial is to have Olama on your system. Ola is basically allowing you to host um yeah large language models on your system. So in my case if I do list actually I need to first do lama surf but when I then do lama list you can see I have this quen 3 model with 0.6 billion parameters that's just something I'm going to be using in llama index. If you want to also do that get lama on your system and pull some model that can run on your hardware. After that, we're going to go back into our tutorial directory. And here you need to create a so-called file. In my case, I already have this file. Actually, I need to run ll so you can see it. This is a file called. So, literally just dot and then enth. I'm not going to open it because it contains an API key. I'm going to create a second file here. I'm going to call this demo, but call your your file that you're creating. En here. What you want to do is you want to say open AAI_AI_key equals and then the API key. Where do you get it? You get it from OpenAI. So you go to your OpenAI account. You go to settings API keys. And hopefully you have a better naming scheme than me. I just literally every time I create a key, I just smash on my keyboard and I get some name. But you just get the key, you copy it, you paste it into your file here, into your N file, and that is going to be loaded in Python. So what we're going to do now is we're going to run Jupyter Lab which is an interactive Python notebook environment. So if you just use your Python installation, you run Jupiter Lab like this. If you're using UV like me, you have to say UV run Jupyter Lab. And once you have this opened up, it's going to open up a browser tab. I'm going to move the terminal to a different workspace. And here now we have Jupyter Lab. So this is an environment for working with interactive Python notebooks. We can create one by clicking on this button here. And I always like to give an introduction here. If you've never used an interactive Python notebook, the idea is you don't just have a Python file that you run every time from top to bottom. You have individual cells and you can just set some variable here. For example, use it in another cell. Then you can reset the variable down here. You can go up and run this code. It changes. You can also have multiple instructions per cell. And the main reason to use a notebook like this is just because when you're doing data science, machine learning stuff, especially when training models, doing data analysis, it doesn't make sense to run every single thing from top to bottom. You want to run maybe one additional visualization, but you don't want to load the whole data set from scratch. Again, in terms of working with agents, it's not a necessity. You can also just play around with Python files, but for learning purposes, I like to use Jupyter notebooks because we can run individual cells and that's quite flexible. So the first thing we want to do here is a basic example of getting data from a very simple data source. So what I have here in the file tree is I have two directories data and data 2. These just contain text files. So these five text files here, file one txt up to file 5.xt contain very basic information. I love Linux. I think Apple is better than Microsoft. I think bananas are better than apples. I like oranges. Programming is fun. So these are opinions that I have for example and what I want to do now is I want to just take this directory with llama index turn it into a data source and then query using a query engine and get answers to questions based on this directory as a data source. So that's going to be our first basic example and then we're going to take it from there and add more stuff as we go on. The first thing we want to do is we want to load the open AI API key. So the environment variable for that I'm going to say from.enimp n import load. Then I also want to call load.enf. So if you named the key correctly, now the openi API key is going to be in the environment and llama index and the openi tools are going to automatically recognize that and connect to your account which of course means that you're also going to be charged for it even though it's not a lot. That is how it works here. And the basic example now is we say from llama index uh core import vector store index and simple directory reader. So a vector store for those of you who don't know what it is in a very basic way an embedding is a point in vector space. So let's say you have two dimensions then you have x and y. If you have three dimensions you also have z. If you have a thousand dimensions, it's hard to visualize, but you have a point in n-dimensional space produced by an intelligent embedding model. And these placements of the points make sense because they're close to one another if they're semantically similar and further apart if they're not. So if I have Apple, the company, it's going to be closer in this embedding space to something like Microsoft, even though they're are different companies, but it's going to be closer to that than to the concept of a banana. Even though the banana is a fruit and apple is also a fruit, but this apple here with a capital A, if it's a company in the in the sentence, for example, it's clear that this is a company, it's going to be further away from the fruit stuff and very close to business stuff and tech stuff. That is the basic idea. The vector store now is a database that contains these embeddings. That's the in a nutshell explanation here. So what we're going to do is we're going to say the documents that we're interested in are simple directory reader data load data that is going to load these files as documents and then we can create a vector store based on that. So we can say uh index is equal to vector store index from where's my autocomplete from documents documents. That is super simple. Now what can we do in order to get information based on that? Here you can see we did a call to open AI embeddings. What does this mean? I have the documents but the documents are not embeddings. They're not points in vector space. So what this OpenAI call does is it uses the embedding model of OpenAI to say that I want to have the vector representation the embedding representation of these informations of these pieces pieces of information and then they're taken into the vector store. The results are taken into the vector store and now I can create a so-called query engine and I can say index dot as query engine and then I can just say here query engine dotquery and I can ask a question for example the question could be something like um do I like Linux question mark and the response is going to be a pretty big object. So we can just print it. By printing it, we turn it into uh a simple string answer. You like Linux. Now maybe I can say also what is my favorite fruit? And then the answer is going to be oranges. So as you can see it took the information that there's a file in here. I don't know which one it was. Uh file four. I like oranges. It took that as context and now it knows I like oranges. Now, I didn't say that it's my favorite fruit, but it's uh close enough. So, that is a very very simple example of how to turn a collection of text files into a vector store that you can then query. So, if you have just a directory full of text files, you can just turn them into documents, turn them into an index, and then you have a query engine to interact with that. That is a super simple use case. Now, what I want to show you next is how we can build basic agents. Basic agents in terms of like how we can do it with lang. You have an agent. This agent is based on a certain large language model. Maybe let me get rid of all this here. Based on a certain large language model and this large language model is the thing interacting with you. But maybe you also have functions. Maybe you also have some context, some system prompt. So that is the idea of an agent. How do we do that in llama index? For that I'm going to say here from llama index.core.agent.workflow workflow import the function agent and then from llama index lms. OpenAI import OpenAI because we're going to use an OpenAI model. Now for this function agent, I can provide a tool that this agent can use. For example, let's say I have a function. Let's just make a very simple one. Get favorite color, which is going to get my favorite color. And I'm going to use something that is probably not going to be guessed by a LLM in general. So if I ask it what's my favorite color, it might say blue because that's a common response. So I'm going to say here cyan. So I know it's actually coming from the function and not just a random guess. And now I can create an agent that has access to this function to answer questions if it doesn't know the answer. So what I can do now is I can say agent is equal to function agent and the first thing I want to specify here is the model that this b that this agent is uh using. So I can say llm is equal to open AI and in here now I can provide the model name. So I can say model that I want to be using is for example GPT40- mini and actually I need an additional dash here. So GPT-40- mini. Now in addition to that I can use certain tools. So I can say tools is equal to and I can just pass a list of functions. Get favorite color for example. And then finally I can also pass a system prompt. And that system prompt is just going to be you are a helpful assistant. Let's see if that's enough to make it answer the question what my favorite color is. But that is very similar to what you would do in something like Langchain. You just define the agent, you set the model, you set the tools, you set the system prompt, and then you use it. Quite simple, quite straightforward. So in order to now get a response, I can say response is equal to I have to await the answer. So I can say await because that's asynchronous. Otherwise, I'm just going to get a response object promising me a future um a future answer. But I have to say await agent run and then whatever my question is. For example, what is my favorite color question mark and this now is going to take some time. So it posts here to chat GPT. You can see I get completions and uh the result is of course print response your favorite color sign. So we can also see here two function calls or two two completion calls. I guess the first one is something like that is being asked I asked I have access to these tools what should I do then the response is okay um the response is I called the function this is the response and then the model tells you your favorite color sign so it's like two iterations here that is a very basic way to use agents in llama index what you will notice however is that now I cannot just continue the conversation I cannot just say here response is equal to await agent run And I cannot just say is this common for people question mark because if I do that it doesn't know what I'm talking about. I can just run this and I will get a response. So I will get something that I can print here. Could you please clarify what specific behavior situation you're referring to? Because it doesn't have any context. It doesn't know that we talked about my favorite color. If I want to change that, I can go and say from llama index.core.workflow workflow import context. Then down here I can say ctx is equal to context of agent. And then when I do something like agent run I can say ctx is equal to ctx. So I can just run this. I will get my answer same as before. And now I can say here ctx is equal to ctx. And just by doing this I introduced context. And now it knows that cyan is a vibrant and appealing color. and popularity can vary amongst visual individuals. So, as you can see, this is super easy and now it has the context, it has the message history. So, now let's combine the two things we learned about and add a tool that allows us to access the data here. So, let's say now we have maybe a function called um get context from database or something like this. Probably not the best way to phrase this. And above that here I'm going to define again that I have the vector store. So we're going to do the same thing that we did before. Documents is equal to what was the uh actual I need to also import this from llama index dot core import simple directory reader and vector store index. We're just going to say again simple directory reader. Repetition is key. If you want to learn something, load data. And then we're going to say index is equal to vector store index dot from documents documents. And then we need a query engine. The query engine is going to be equal to index as query engine. So we're going to use this now as part of a tool that can get information from the database. So we can do something like um return and then maybe the string response here of query engine dotquery and that is going to be the question has to be passed here. So we can say question or let's say query is going to be passed here or actually I think it makes more sense to say response let's make this asynchronous. Let's say async defaf and then response is equal to await and we're going to do query engine query for asynchronous query. And it also makes sense to provide type hints not for us not because we're writing clean code but because the model can then know what it has to pass to this function. And then we're just going to say return string of response. So now we have the same thing that we did before documents index query engine but we're using this in a function an asynchronous function here we're using aquery not query we're awaiting it and we're returning the response we're doing string response because otherwise we're going to get this huge JSON object this way we just get the raw answer and now we can just pass this here as a tool we can say get context from database I'm not sure if that's going to be enough to answer some of the questions here but we can try down here directly by saying response is equal to agent.run. And our question is going to be uh what is my favorite food question mark. Maybe it needs some help to answer that. I think so actually because yeah I don't have access to your personal preferences. So let's maybe say in the system prompt if you don't have we're now not going to care about or let's say do not. Okay. If you do not have access to information needed for the answer, consult the tool query from database. Is that what it's called? Get context from database. Actually, sorry. Get context from database. So, that should be fine. Let's go and run this again. Let's go down here and see if it can handle this. Yeah, now you can see completions, embeddings, completions, completions. So, what most likely happened is it got the request. Oh, I don't know the answer. I need to call the tool. Call the tool, do the embedding um of this of this question. Then you get a response and then you get the final response. So, that is here the the querying and that is the final response that we're getting. And the response is your favorite food is oranges. So that is now rack capability in our agent. By the way, what we can also do now is we can go back. I can create a new notebook that's unrelated to this one just for testing here. And here now I can load the vector store when I export it here first. So I can say index dot storage context.persist and I can say storage for example. that is going to write it into a directory called storage here and then I can go into this new uh notebook that is unrelated doesn't have access to index here as you can see I can just say from llama index core import storage and load index from storage actually sorry it's uh storage context not storage and I can say storage context is equal to storage context from defaults And we're going to provide here storage as a keyword argument. Persist directory is equal to storage. And then I can just say index is equal to load index from storage context. And finally query engine that is the same as before is equal to index as query engine. That of course doesn't work because I don't have the open AI key. So let me also do a quick from import load.enf that is going to load the environment key. And now I can rerun this. And this will get our vector store. And now I can just say query engine. And I can ask again same way I did before. What is my favorite fruit? Question mark. And then um that's going to be yeah str of that oranges. There you go. Now let me show you briefly how we can do the same thing with local LLMs. That is actually the same process. The only thing we need to change is we're not using OpenAI. We're actually using O Lama. But this also brings us now to a second part which is Llama Hub. And this is the rich variety of data connectors that we have for Llama Index. So whenever you need something for llama index, you can go to llama hub AI and you can find uh or you can look for specific embedding models, specific vector stores. In our case now, we're using O Lama. So I can just type O Lama. We can see here, oh, there you go, Olama. And it say it says I have to say pip install llama index lms O Lama to be able to connect to my local Olama models. If you don't know what Olama is, it's this nice tool here. You can go to models to see what kind of models are available. I would recommend if you don't have very powerful hardware. You go with a very small model. I think as I said I'm using Quen 3 0.6 billion parameters. All you have to do to use these models is you have to open up a terminal. You have to do surf once you have installed it. Of course, I'm not going to go through the installation process. And then you have to do Olama run or just OLAM pull if you just want to have it on your system. And in my case, I already have it, but you would pull, for example, Gwen 3 0.6 billion. And if you have this, you can just use it in your program. You can also just use it by chatting with it in the terminal. So, I'm going to close this one. I'm going to move this somewhere else. And um yeah, we need as I said this Olama integration. And as I also said, you can just look through all these tools. There's a rich uh variety of data connectors here, which is what makes Llama Index so special. You can connect it to basically everything and it's all communitydriven. That's super super awesome. Now, what we're going to exchange here is or first of all, we said we need to install it. So, let me go to the tutorial directory again and I'm going to do a UV add. What was it called? It was called llama index lms llama. So just copy that uvad in my case in your case pip install if you're just using the ordinary Python installation. And once we have this we can go into our code. I hope I don't need to restart. And we can say from llama index lms import lama. And then I can exchange here the open AI with O lama and then model is equal to quen 3 0.6 billion. Now this model is not very smart. So probably it's not going to give very reasonable answers most of the time. Let's see. Uh now keep in mind we're still using here the OpenAI embeddings for the vector store part. We're just replacing the agent itself when it answers. So now I'm going to run this again. Actually I'm missing a comma. There you go. I'm going to run this again and we're going to see if it knows my favorite color. Takes some time. You can see now the requests are going to local host. This one went to embeddings from OpenAI but here now I was talking to my local model. And I get your favorite color is cyan which is correct. It also knew that it had to call a tool. Um, and then I can run this again here with a context and it should say something like, "Yeah, that's probably not the most common color, but I know what you're talking about, which is important." And then we can see if we can also use the rack capabilities response agent run. What's my favorite food? Uh, in this case here, it probably tells me result is not set. Do I need to await this? Yeah, I need to await this, of course. So, I don't have access to your personal information. So let's maybe say you need to call the context tool. Then it should hopefully manage to do that. If I instruct it to call the tool take some time and the tools you pro include uh the tools you provided don't include a function to retrieve personal information. I literally told you which function to use. So let's try if I give you the name maybe you can handle it. Then you need to call the this tool here. If it doesn't know how to do that, then yeah, I guess we're going to stop trying. There you go. It called the tool called the OpenAI embedding API, but it it's not the smartest model. As you can see, your favorite food is oranges, banana. Great. Um, yeah. So, this is how you can also use Olama. If I may for a second, I would like to plug myself in as the sponsor of my own video. If you go to my website neurallonline.com, you will find a tab services and a tab tutoring. Here you can hire me for all sorts of stuff like data science, machine learning, web development. If you need help with something in a project, here you can book me for one-on-one tutoring. If you want me to teach you personally something that you don't understand, if you like my teaching style on both pages at the bottom, you can contact me via mail and also via LinkedIn. Just wanted to let you know about this. So the next thing I want to show you is how we can change individual components of this whole part. Now we already did that with the LLM. I changed it from OpenAI to OLAM. But I now want to show you one more time how we can change this to Google. I want to show you how we can change the vector store to face. And I also want to show you how we can change to a specific embedding model. So we're now going to make all of this more customized. And for this we're going to start with the installations. How do we know what we need to install? We can just go to Llama Hub. Here I can type Genai. This is going to show me Gemini. So this is actually Google geni is Gemini. You can see llama index lm's Google geni. This is one thing that we need to install. So let's open up a terminal. Navigate to this directory again. In my case again uv add in your case pip install this package. Then we're also going to need face because I'm going to use face to be precise. I'm going to use it with the CPU to keep it simple here. So face CPU. This is just a vector store. You can also use something else if you want to. And then we also need a data connector for face. So I need to go here and I can say face. There you go. Face vector store. Click on this and you can see llama index vector stores face. So these are the three packages we're going to add now. And they're installed. We can go back here and now we're going to exchange this index by a or with a face vector store. So I'm going to say here first of all from llama index lms.g Google Genai import Google Genai. We're going to get rid of O Lama. We're also going to get rid of um the OpenAI lm, but we're going to use from llama index embeddings. OpenAI. We're going to use the OpenAI embedding. So, we're still going to use an embedding model from OpenAI, but we're going to use a specific one. And then I'm going to say from llama index dot vector stores dophase import face vector store. And then finally also we're going to say import face itself. That's also going to be important. So what we're going to do now is we're going to keep the documents the same. We're going to still load them from the directory. We're also going to use vector store index but not right away. So I'm going to get rid of that. And I'm going to also for now get rid of the query engine. Doesn't really matter. And now the first thing we want to do is we want to create the face uh storage context first. And then we want to just pass it as a parameter for the vector store index. So I'm going to say here vector store is going to be equal to face vector store. And for this we need phase index and that's going to be a phase.index. Why do I not get autocomp completion? Okay, then I'm going to type it index flat L2. And here we're going to pass a dimensionality. So the embeddings from OpenAI are 1,536 dimensions. So that is just a format. You need to know what embedding model you're targeting. The one I'm going to use has this dimensionality in the output. And now we're going to say storage context is equal to storage context which of course needs to be imported here. Storage context and the storage context from defaults is going to be taking the vector store in as a keyword parameter. So vector store is equal to vector store. Um and this storage context now can be passed when creating the index. So we can say index is equal to vector store index. We can say actually from documents as we did before. So vector store index from documents. We can pass the documents but we're going to also pass the storage context. So I'm going to say storage context is equal to storage context. Now we can also set the embedding model here. So I'm going to say embedding model or actually it's embed model that is going to be equal to open AAI embedding and the model name is called text dash embedding-3- small I think we should provide model is equal to here then add some spacing here and that is now basically the same idea as before we can also turn this into a query engine that is not a problem index as query engine. And this now works with a specific embedding model. And of course, we can use a local one, we can use O Lama embedding, we can use Gemini, whatever. And with a face vector store. And then finally, we can go down here and exchange this with a Google model. For this, by the way, you need to get an API key. Again, in my case, what I did is I just got this free API key from Google AI Studio. I copied it. I put it into my end file as a second line where I said Google API key and then I basically just put it there. So for that of course what I also need to do is I need to reload the environment and I need to also import OS so I can actually access it. And here now we're going to say that uh Gemini or what was it Google Genai model is going to be equal to Gemini 2.0 and o flash for example and I'm going to pass the API key which is going to be os get from the environment the Google API key which I provided in the info. So let's see if all of this works now I can just run this. There you go. It's using Gemini here to actually do nothing yet but it gets the Gemini model here. We also have the embeddings used from OpenAI. And now I can run this and the response is your favorite color is cyan. So response is equal await agent run. Is it common for people? Print response. Can it also Okay, now I already told it what to do. Of course, it's going to use the tool, but maybe I can say nothing. Maybe it can just figure that out on its own. And I'm getting a client error, I assume. Yeah, okay. There's just too many requests. This is a Google error. We're not going to talk about this now. But basically, you can see we can swap out components. I can use a different storage context, a different vector store behind the scenes. I can use a different embedding model. I can use u a different reasoning model here for the agent. All of this can be u used here in Llama Hub. I can just look up whatever I want to use. I can say I'm looking for a different embedding model. Click on embeddings. Here I get all the embeddings. I can use different indexes. There you go. Indexes. Um yeah. So that's super convenient. Vector stores, same thing. We can just use a bunch of different vector stores. We have a bunch of data connectors and thirdparty packages. Now, finally, I want to show you two more things and then we're going to wrap this up. I'm going to start here by showing you prompt templates. So from llama index.core.prompts import the rich prompt template. And the idea here is just that we can have placeholders and then we can fill them. Very simple to a ginger template. We just say here template is equal to let's make this a multi-line string. So three quotation marks and then we can say something like uh take the following context into consideration. Then we can have some separating lines here. Whatever something like this you can copy it in between. We can have now with double curly brackets a placeholder like context string. And then I can say now answer this question or this query I should say. Then we can say query string. This is just a nice little thing that we can do with llama index. I can now take this I can turn it into a prompt template and then we can fill it. So I can say QA template is equal or actually is equal to rich prompt template and then template string or actually I just called it template. That's going to be the template itself. And then I can just say the prompt is equal to QA template dot format. And then I can just pass context string here. And then I could say I don't know I like oranges again to stay in the same uh example. And I can say query string is equal to what do I like question mark. And then the prompt would not give us the answer. It would just be the prompt with all the stuff formatted in. Nothing too fancy, but that's one way we can do it with llama index. And then finally, a small thing that I want to show you is how to model message histories. If we want to pass not just a single message, but already a message history that needs to be continued. For that, we can say from llama index.core. LM import message and message role. So the idea here is we're going to say the role can be system, assistant or user and we're going to say we have a model and for that we can say open AI model is going to be equal to GPT4 mini. So now we don't have an agent we just have a model and what I want to do now is I want to pass a message history. So messages is equal to a list and every entry here is going to be a chat message that has certain content and also a row. So role can be for example message row dots system and the content can be you are a helpful assistant and then I can say comma and I can say the next role is user the content is what is the best color and then the assistant could answer obviously It is blue. And then we could ask as a next question why is that question mark? And hopefully we get some answer that is uh yeah part of this context. So we can say response is equal to model chat and we pass the entire message history and once this is done we can just say print response and here we get blue is often considered a favorite color for many people for se several reasons and then we get it. So this is mainly what I wanted to cover. I wanted to show you how to work with llama index in a very basic way. If you want to go deeper into that first of all I want to give you a couple of links. Second of all, if you like this video, we can also make a follow-up some advanced lama index or some advanced retrieval or rack with lama index because there are examples here in the documentation like advanced retrieval strategies. We have property graph indexes, we have structured hierarchical retrieval. So llama index as I mentioned in the beginning is very much focused on retrieval indexes vector stores on data connectors not so much on general agentic stuff but primarily on retrieving data and working with context and working with data. So if you want to go deeper into that you can take a look at these um segments in the documentation or you can also let me know that you want to see a deeper dive into llama index in a more advanced crash course. So that's it for this video today. I hope you enjoyed it and hope you learned something. If so, let me know by hitting a like button and leaving a comment in the comment section down below. Also, in case you're interested, on my website, you will find a tutoring tab and also a services tab. There you can contact me if you want to have some one-on-one tutoring, one-on-one teaching. Or if you need some help with your startup project, idea, whatever, you can contact me there and we can talk about this. You can contact me via LinkedIn and email. Besides that, don't forget to subscribe to this channel and hit the notification bell to not miss a single future video for free. Other than that, thank you much for watching. See you in the next video and bye.

Original Description

In this video today we do a crash course on LlamaIndex, an AI agent and RAG framework for Python, similar to LangChain. ◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾ 📚 Programming Books & Merch 📚 🐍 The Python Bible Book: https://www.neuralnine.com/books/ 💻 The Algorithm Bible Book: https://www.neuralnine.com/books/ 👕 Programming Merch: https://www.neuralnine.com/shop 💼 Services 💼 💻 Freelancing & Tutoring: https://www.neuralnine.com/services 🖥️ Setup & Gear 🖥️: https://neuralnine.com/extras/ 🌐 Social Media & Contact 🌐 📱 Website: https://www.neuralnine.com/ 📷 Instagram: https://www.instagram.com/neuralnine 🐦 Twitter: https://twitter.com/neuralnine 🤵 LinkedIn: https://www.linkedin.com/company/neuralnine/ 📁 GitHub: https://github.com/NeuralNine 🎙 Discord: https://discord.gg/JU4xr8U3dm Timestamps: (0:00) Intro (1:09) LlamaIndex VS LangChain (2:33) Environment Setup (6:24) Basic RAG Example (11:18) Basic Agent Example (14:38) Context & Chat History (15:53) Agent with RAG (21:37) Local LLMs & Ollama (26:44) Data Connectors & LlamaHub (33:31) Prompt Templates (35:26) Pass Entire Conversations (37:17) Advanced Resources (38:12) Outro
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from NeuralNine · NeuralNine · 0 of 60

← Previous Next →
1 Visualizing Stock Data With Candlestick Charts in Python
Visualizing Stock Data With Candlestick Charts in Python
NeuralNine
2 Python Beginner Tutorial #1 - Installation and First Program
Python Beginner Tutorial #1 - Installation and First Program
NeuralNine
3 Python Beginner Tutorial #2 - Variables and Data Types
Python Beginner Tutorial #2 - Variables and Data Types
NeuralNine
4 Python Beginner Tutorial #3 - Operators and User Input
Python Beginner Tutorial #3 - Operators and User Input
NeuralNine
5 Python Beginner Tutorial #4 - If Statements and Conditions
Python Beginner Tutorial #4 - If Statements and Conditions
NeuralNine
6 Python Beginner Tutorial #5 - Loops
Python Beginner Tutorial #5 - Loops
NeuralNine
7 Python Beginner Tutorial #6 - Sequences and Collections
Python Beginner Tutorial #6 - Sequences and Collections
NeuralNine
8 Python Beginner Tutorial #7 - Functions
Python Beginner Tutorial #7 - Functions
NeuralNine
9 Python Beginner Tutorial #8 - Exception Handling
Python Beginner Tutorial #8 - Exception Handling
NeuralNine
10 Python Beginner Tutorial #9 - File Operations
Python Beginner Tutorial #9 - File Operations
NeuralNine
11 Python Beginner Tutorial #10 - String Functions
Python Beginner Tutorial #10 - String Functions
NeuralNine
12 Python Intermediate Tutorial #1 - Classes and Objects
Python Intermediate Tutorial #1 - Classes and Objects
NeuralNine
13 Python Intermediate Tutorial #2 - Inheritance
Python Intermediate Tutorial #2 - Inheritance
NeuralNine
14 Python Intermediate Tutorial #3 - Multithreading
Python Intermediate Tutorial #3 - Multithreading
NeuralNine
15 Python Intermediate Tutorial #4 - Synchronizing Threads
Python Intermediate Tutorial #4 - Synchronizing Threads
NeuralNine
16 Python Intermediate Tutorial #5 - Events and Daemon Threads
Python Intermediate Tutorial #5 - Events and Daemon Threads
NeuralNine
17 Python Intermediate Tutorial #6 - Queues
Python Intermediate Tutorial #6 - Queues
NeuralNine
18 Python Intermediate Tutorial #7 - Sockets and Network Programming
Python Intermediate Tutorial #7 - Sockets and Network Programming
NeuralNine
19 Python Intermediate Tutorial #8 - Database Programming
Python Intermediate Tutorial #8 - Database Programming
NeuralNine
20 Python Intermediate Tutorial #9 - Recursion
Python Intermediate Tutorial #9 - Recursion
NeuralNine
21 Python Intermediate Tutorial #10 - XML Processing
Python Intermediate Tutorial #10 - XML Processing
NeuralNine
22 Python Intermediate Tutorial #11 - Logging
Python Intermediate Tutorial #11 - Logging
NeuralNine
23 Python Data Science Tutorial #1 - Anaconda and PyCharm Setup
Python Data Science Tutorial #1 - Anaconda and PyCharm Setup
NeuralNine
24 Python Data Science Tutorial #2 - NumPy Arrays
Python Data Science Tutorial #2 - NumPy Arrays
NeuralNine
25 Python Data Science Tutorial #3 - Numpy Functions
Python Data Science Tutorial #3 - Numpy Functions
NeuralNine
26 Python Data Science Tutorial #4 - Plotting Functions With Matplotlib
Python Data Science Tutorial #4 - Plotting Functions With Matplotlib
NeuralNine
27 Python Data Science Tutorial #5 - Subplots and Multiple Windows
Python Data Science Tutorial #5 - Subplots and Multiple Windows
NeuralNine
28 Python Data Science Tutorial #6 - Matplotlib Styling
Python Data Science Tutorial #6 - Matplotlib Styling
NeuralNine
29 Python Data Science Tutorial #7 - Bar Charts with Matplotlib
Python Data Science Tutorial #7 - Bar Charts with Matplotlib
NeuralNine
30 Python Data Science Tutorial #8 - Pie Charts with Matplotlib
Python Data Science Tutorial #8 - Pie Charts with Matplotlib
NeuralNine
31 Python Data Science Tutorial #9 - Plotting Histograms with Matplotlib
Python Data Science Tutorial #9 - Plotting Histograms with Matplotlib
NeuralNine
32 Python Data Science Tutorial #10 - Scatter Plots with Matplotlib
Python Data Science Tutorial #10 - Scatter Plots with Matplotlib
NeuralNine
33 Python Data Science Tutorial #11 - 3D Plotting with Matplotlib
Python Data Science Tutorial #11 - 3D Plotting with Matplotlib
NeuralNine
34 Python Data Science Tutorial #12 - Pandas Series
Python Data Science Tutorial #12 - Pandas Series
NeuralNine
35 Python Data Science Tutorial #13 - Pandas Data Frames
Python Data Science Tutorial #13 - Pandas Data Frames
NeuralNine
36 Python Data Science Tutorial #14 - Pandas Statistics
Python Data Science Tutorial #14 - Pandas Statistics
NeuralNine
37 Python Data Science Tutorial #15 - Pandas Sorting and Functions
Python Data Science Tutorial #15 - Pandas Sorting and Functions
NeuralNine
38 Python Data Science Tutorial #16 - Pandas Merging Data Frames
Python Data Science Tutorial #16 - Pandas Merging Data Frames
NeuralNine
39 Python Data Science Tutorial #17 - Pandas Queries
Python Data Science Tutorial #17 - Pandas Queries
NeuralNine
40 Python Machine Learning Tutorial #1 - What is Machine Learning?
Python Machine Learning Tutorial #1 - What is Machine Learning?
NeuralNine
41 Python Machine Learning Tutorial #2 - Linear Regression
Python Machine Learning Tutorial #2 - Linear Regression
NeuralNine
42 Python Machine Learning Tutorial #3 - K-Nearest Neighbors Classification
Python Machine Learning Tutorial #3 - K-Nearest Neighbors Classification
NeuralNine
43 Python Machine Learning #4 - Support Vector Machines
Python Machine Learning #4 - Support Vector Machines
NeuralNine
44 Python Machine Learning Tutorial #5 - Decision Trees and Random Forest Classification
Python Machine Learning Tutorial #5 - Decision Trees and Random Forest Classification
NeuralNine
45 Python Machine Learning Tutorial #6 - K-Means Clustering
Python Machine Learning Tutorial #6 - K-Means Clustering
NeuralNine
46 Python Machine Learning Tutorial #7 - Neural Networks
Python Machine Learning Tutorial #7 - Neural Networks
NeuralNine
47 Python Machine Learning Tutorial #8 - Handwritten Digit Recognition with Tensorflow
Python Machine Learning Tutorial #8 - Handwritten Digit Recognition with Tensorflow
NeuralNine
48 Generating Poetic Texts with Recurrent Neural Networks in Python
Generating Poetic Texts with Recurrent Neural Networks in Python
NeuralNine
49 Stock Portfolio Visualization with Matplotlib in Python
Stock Portfolio Visualization with Matplotlib in Python
NeuralNine
50 Analyzing Coronavirus with Python (COVID-19)
Analyzing Coronavirus with Python (COVID-19)
NeuralNine
51 Making Text Images Readable Again with Python and OpenCV
Making Text Images Readable Again with Python and OpenCV
NeuralNine
52 Neural Networks Simply Explained (Theory)
Neural Networks Simply Explained (Theory)
NeuralNine
53 Motion Filtering with OpenCV in Python
Motion Filtering with OpenCV in Python
NeuralNine
54 Top 5 Programming Languages To Learn in 2020
Top 5 Programming Languages To Learn in 2020
NeuralNine
55 Simple TCP Chat Room in Python
Simple TCP Chat Room in Python
NeuralNine
56 Image Classification with Neural Networks in Python
Image Classification with Neural Networks in Python
NeuralNine
57 Edge Detection with OpenCV in Python
Edge Detection with OpenCV in Python
NeuralNine
58 S&P 500 Web Scraping with Python
S&P 500 Web Scraping with Python
NeuralNine
59 Simple Sentiment Text Analysis in Python
Simple Sentiment Text Analysis in Python
NeuralNine
60 Introduction - Algorithms & Data Structures #1
Introduction - Algorithms & Data Structures #1
NeuralNine

This video teaches how to use LlamaIndex to build AI agents and customize them with various tools and models, providing a comprehensive introduction to retrieval augmented generation and LLM engineering.

Key Takeaways
  1. Install LlamaIndex using pip
  2. Create a UV project
  3. Load environment variables from an N file
  4. Define a basic agent using a large language model and functions to interact with the user
  5. Use the agent to answer questions
  6. Exchange OpenAI LLM for Google Geni in LlamaIndex
  7. Replace OpenAI embeddings with OpenAI embedding model in LlamaIndex
💡 LlamaIndex provides a flexible and customizable framework for building AI agents and integrating them with various tools and models, making it a powerful tool for retrieval augmented generation and LLM engineering.

Related Reads

📰
Top AI Papers on Hugging Face - 2026-07-15
Explore the top AI papers on Hugging Face, focusing on agent longevity, robotics, and efficient model training methods
Dev.to AI
📰
Integrating Open-Weight LLMs as Drop-In API Replacements: A Practical Guide
Learn to integrate open-weight LLMs as drop-in API replacements for a vendor-locked-in free solution
Dev.to AI
📰
Build a Bounded JSON Repair Loop for LLM Output in Python
Learn to build a bounded JSON repair loop for LLM output in Python to separate syntax, shape, and semantic errors
Dev.to · Alex Chen
📰
How I Built a Multi-Page AI Website Generator for Nigerian SMBs — Architecture, LLM Prompting, and Lessons Learned
Learn how to build a multi-page AI website generator for small businesses using LLM prompting and key architectural decisions
Dev.to · Innocent Oyebode
Up next
5 Levels of AI Agents - From Simple LLM Calls to Multi-Agent Systems
Dave Ebbelaar (LLM Eng)
Watch →