ADVANCED Python AI Agent Tutorial - Using RAG

2024 ж. 13 Мам.
108 050 Рет қаралды

In this video, I will be showing you how to create an artificial intelligence agent that will be able to use all of the tools that we provide it with. That's right, we will create and AI agent & give it various tools for it to use selectively based on the task at hand.
Note: This video refers to llamaindex version 0.9. On Feb 12th, 2024 llamaindex version 0.10 was released which is mostly the same but has some added functionality :)
🎞 Video Resources 🎞
Check out Llama Index: www.llamaindex.ai/
Llama Index Docs: docs.llamaindex.ai/en/stable/
Population Dataset: www.kaggle.com/datasets/joebe...
Llama Hub: llamahub.ai/
Code in this video: github.com/techwithtim/Python...
⏳ Timestamps ⏳
00:00 | Overview
00:27 | Project Demos
03:54 | Understanding Agents & RAG
06:29 | Installation/Setup
09:00 | Data Sources
13:18 | Querying Pandas Data
19:17 | Building Agent Capabilities
29:18 | Querying Unstructured Data
39:38 | Next Steps
Hashtags
#PythonAI
#TechWithTim
#AICoding

Пікірлер
  • Just a tip for whoever is following along.The code, from llama_index.query_engine needs to be llama_index.core.query_engine.

    @loggerboy9325@loggerboy93252 ай бұрын
    • How did you figured that out bro ? 😮❤ Btw thanks alot

      @shashankshukla6691@shashankshukla66912 ай бұрын
    • why

      @Al_Miqdad_@Al_Miqdad_2 ай бұрын
    • @@Al_Miqdad_ because llama_index.query_engine doesn't works, unless you add .core

      @shashankshukla6691@shashankshukla66912 ай бұрын
    • i love you

      @martyallen6931@martyallen69312 ай бұрын
    • @@shashankshukla6691 looked up the llama documentation

      @loggerboy9325@loggerboy93252 ай бұрын
  • Detailed, no-nonense, topical. One of the best coding channels on youtube. Always looking forward to a new video.

    @sadiqkhawaja7019@sadiqkhawaja70192 ай бұрын
  • 5 mins into the video and I am already excited about the future!

    @josephabuo6027@josephabuo60272 ай бұрын
    • For sure it’s super cool!

      @TechWithTim@TechWithTim2 ай бұрын
  • This channel is a Godsend, which instilled the fundamentals of Python within me, which helped me to obtain a certification in robotics. You never cease to amaze me. 😊

    @ReDoG129@ReDoG1292 ай бұрын
  • Guys! The llama-index package format has changed, try importing this way and it should work: from llama_index.core.query_engine import ... Like so everyone can see!

    @PeacefulHarmonyMusicHealing@PeacefulHarmonyMusicHealingАй бұрын
    • thanks

      @sorrym8958@sorrym8958Ай бұрын
    • thanks

      @ErdeEnterprise@ErdeEnterprise13 күн бұрын
  • thank you very much for your feedback ❤❤❤❤

    @Al_Miqdad_@Al_Miqdad_2 ай бұрын
  • one of the best videos on internet regarding AI agents

    @amanaggarwal4061@amanaggarwal40612 ай бұрын
  • This is the gold standard for this kind of coding tutorials.💯 I hope more KZheadrs would be like him. Please keep up the good work.

    @myanghua@myanghua2 ай бұрын
  • To add context in order to refer to previous response like "save the response to my notes", you can add context = " ".join([f"role: {exchange['role']} content: {exchange['content']}" for exchange in st.session_state.messages]) response = agent.query(context + " " + prompt)

    @philippechassany7279@philippechassany72792 ай бұрын
  • Amazing video ,tim ...i always wanted a fast an ld easy way to understand llamaindex...now I can build my own project fast ... Thanks a million brother

    @mushinart@mushinart2 ай бұрын
  • Tim we need more content like this or a course... and as always awesome work ❤

    @ayanjawaid2251@ayanjawaid22512 ай бұрын
  • Tim you saved my day, you are awesome. I will write in details later how, but for now thanks for the brilliant working code

    @myslates2854@myslates28542 ай бұрын
  • Thanks for sharing Tim.

    @rodrigogazcon506@rodrigogazcon5062 ай бұрын
  • If you are running this blindly without using Tim's requirements file, please note that due to security `from llama_index.query_engine import PandasQueryEngine` is no longer the right import, try pip installing `llama-index-experimental` and then using the PandasQueryEngine class from `from llama_index.experimental.query_engine import PandasQueryEngine`. This is for py3.10. Finally, the PromptTemplate class is now at `from llama_index.core import PromptTemplate`. The documentation will really help though. Thanks Tim.

    @hypo30cal@hypo30cal6 күн бұрын
  • More ai video 😊 awesome working

    @yuvrajkukreja1248@yuvrajkukreja12482 ай бұрын
    • Thanks very much!

      @TechWithTim@TechWithTim2 ай бұрын
  • I second that, the RAG toolkit is amazing.

    @LeonardoGomez-lk5ei@LeonardoGomez-lk5ei2 ай бұрын
  • Love your content❤

    @harmansavla7510@harmansavla75102 ай бұрын
  • Great tutorial Tim!

    @mahmoudabuzamel7038@mahmoudabuzamel70388 күн бұрын
  • awesome great explanation i spended days to read the docs i know the efforts you in to generate this content, thanks

    @suryapratap3622@suryapratap3622Ай бұрын
  • Excited to experiment more.

    @AbelMartinez-xb3gl@AbelMartinez-xb3gl2 ай бұрын
  • Thank you for the video. It is interesting and clear

    @alexsischin2107@alexsischin21072 ай бұрын
  • This looks like a helpful tutorial, hope I can learn something!

    @inocentesantiago3194@inocentesantiago31942 ай бұрын
  • Thank you Tim.

    @juanbetancourt5106@juanbetancourt51062 ай бұрын
  • For windows if './ai/bin/activate' doesn't work then use ' ./ai/Scripts/activate' , that would do the trick^^

    @omghosal3301@omghosal33012 ай бұрын
  • Very informative video!

    @mariamanuel2795@mariamanuel27952 ай бұрын
  • Thanks for sharing.

    @damianaguila7841@damianaguila78412 ай бұрын
  • Alright let's go i'll get all hyped up regardless of what will come of it Thanks Tim

    @pauloseixas5452@pauloseixas54522 ай бұрын
  • Hi Tim - Thanks so much for the video. Great job!!! Would you be able to address not using OpenAI (model, agent) but rather using an open source LLMs?

    @seanh1591@seanh15912 ай бұрын
  • Brilliant!

    @enkhbaatardorjsuren9427@enkhbaatardorjsuren94272 ай бұрын
  • Best explanation using coding , hats off bro

    @saravanannatarajan6515@saravanannatarajan65152 ай бұрын
  • Nice one Tim!

    @brandonhernandezvillantes2937@brandonhernandezvillantes29372 ай бұрын
  • This is great wow ...🎉i can think of a lot of ideas now for this ...but please guys play safe on this... like wiring your complex project to the net..dev opps are very important regarding that...😅otherwise this is great...❤❤great content Tim..

    @user-kw4ph2cz8q@user-kw4ph2cz8q22 күн бұрын
  • I love to see you used venv. I find it more practical than other alternatives.

    @srinivasguptha9538@srinivasguptha95382 ай бұрын
  • Hi Tim, Thank you for creating this video; it's really informative. Would it be possible for you to create a video on LLM that pulls data from Confluence space or pages and generates a response based on it?

    @initkloud@initkloudАй бұрын
  • @Tim Excellent video. The reason the app wasn't able to save the note (end of video) is because you need to include chat memory / history. The llm has no view of the previous messages.

    @leonvanzyl@leonvanzyl2 ай бұрын
    • Can you explain with code?

      @user-ki6un6ut2g@user-ki6un6ut2g26 күн бұрын
  • Thanks for the information @internetMadeCoder but i have a question i struggle at learning programming languages which makee it frustrating and make the process feel tiring i went online and there something when am learning from the video it seems pretty easy and but when i want to use it to try and solve maybe exercises it feels difficult and also forget of what i learnt the previous days and also how do i work on this and be able to learn better what caan u advice me to do

    @kayodedaniel6174@kayodedaniel61742 ай бұрын
  • Appreciate you sharing your skills, super helpful for noobs like me.

    @user-op1ru7nx9j@user-op1ru7nx9j2 ай бұрын
  • This is really cool stuff awesome video

    @chymoney1@chymoney12 ай бұрын
    • glad you liked it!

      @TechWithTim@TechWithTim2 ай бұрын
  • Your vid quality is legit what's your setup?

    @tylerpeterson420@tylerpeterson4202 ай бұрын
  • I have maybe beginner question coming, I wonder if it is possible to make and IA agent that can use both the normal model trained on his dataset, our RAG with provided data source as in this course plus internet search and compile these source in the output ?

    @tinellixavier8022@tinellixavier80222 ай бұрын
  • Hi man, you are the best, I wish if it was about extracting data from text or pdf and also harnessing data from agents LLM to store it in KG and make LLM query from it, all the video I watched about that were poor and not a practical solution, either they doesn't work or poor result or use paid software or don't accumulate data in the KG database with no duplicate... Man you are the one for this project, if you did it I unsure you your channel will be on fire.

    @malikanaser8251@malikanaser82518 күн бұрын
  • This is amazing. Can you create a next video on automation script generation and Sql query generation(for complex schema) using Rag or AI agents. ( but use open source models.)

    @user-ez9st6xt1h@user-ez9st6xt1h2 ай бұрын
  • So RAG stands for Really Awesome Guidance, nice.

    @PedorEmilo@PedorEmilo2 ай бұрын
  • Great Topic! It would be awesome if you extend this example with crewai

    @user-ki6un6ut2g@user-ki6un6ut2g26 күн бұрын
  • great stuff, even though I had to bail on the pdf part because I got some weird stuff going on, it said I have no openai api key and stuff, battled with it for two days and figured out that the code works without that part so... no pdf for me, but everything else works fine :) I will definitely play around with llama-index more

    @BorisHrzenjak@BorisHrzenjak2 ай бұрын
    • can you please tell how you build the project without open ai key?... I am facing the issue in this only

      @sonalithakur8234@sonalithakur82342 ай бұрын
    • @@sonalithakur8234I didn't build it without an api_key. I removed the part of code that was meant to read pdf because it was giving me problems.

      @BorisHrzenjak@BorisHrzenjak2 ай бұрын
    • Yeah same problem for me did anyone figure it out?

      @_c_v@_c_v2 ай бұрын
    • I think that the issue was that the function was not called in openai section so for me, the issue was model was not being used for instance in the 5 or 7 line of code in main the code which ends with input openai is not working because this is not a function which is why the model section near the end was not working so if you want this code to run that I think function needs to be defined for it

      @mbasemhassen2947@mbasemhassen2947Ай бұрын
  • Lots of Thanks in the comments section but i owe you another one, THANKS A LOT !!

    @khalifarmili1256@khalifarmili125615 күн бұрын
  • Hi Tim, first of all, great tutorial! I wanted to ask you if you know if it's possible or efficient to use llama index to do RAG over 300k pages of pdfs. I've been researching and a lot of people say that I will have to fine tune the embeddings models and use one from hugging face. Also to make the results better, use metadata. However, I am wondering if using llama index is the correct approach or if I will need to create my own RAG system. Thank you for taking the time to read this.

    @pntra1220@pntra12202 ай бұрын
  • Thanks, Tim. I've noticed that many of the RAG examples available on KZhead primarily focus on enhancing the model using PDFs, CSVs, or plain text. However, in practice, a significant portion of business data is stored in relational databases, such as Oracle or SQL Server. Could you provide an example demonstrating how RAG can be applied to data from relational databases?

    @ahmadsaud3531@ahmadsaud35312 ай бұрын
    • Hi Tim, i am waiting for your answer please

      @ahmadsaud3531@ahmadsaud35312 ай бұрын
    • @@ahmadsaud3531 did you get the answer ?

      @arnav3674@arnav3674Ай бұрын
    • @@arnav3674 not yet

      @ahmadsaud3531@ahmadsaud3531Ай бұрын
    • @@arnav3674 not yet

      @ahmadsaud3531@ahmadsaud3531Ай бұрын
  • Hi There, Great video. I was wondering if this same method would work but the llm was loaded in via llama instead of using openai llm?

    @varungonsalves6249@varungonsalves62492 ай бұрын
  • Great video, just one question: What would I have to do if I wanted to use open-source tools instead of the openAI API? Thanks.

    @user-fp2yd4wj9o@user-fp2yd4wj9o2 ай бұрын
  • It doesn't save a note using the previous prompt because I think it is lost. I think you are calling a new instance of the model each time you give a new prompt. So you would have to update or append prompt outside the while loop to get it to remember the entire conversation... But I could definitely be wrong, just my intuition :P

    @egericke123@egericke123Ай бұрын
  • Awesome! Hey Tim, can you tell me what theme and font are you using for vscode?

    @malekmot@malekmot2 ай бұрын
  • Thanks for the great vid. i tried following along but getting too many import errors. i also tried building a new virtual env, then installed the modules from your requirements.txt mentioned in this thread, and that also now doesnt work (llama_index tries to load pkg_resources which is not found).

    @neilpayne8244@neilpayne8244Ай бұрын
  • @TechWithTim can you make a video on how do you go thorough any documentation, what is your mindset where you start, and what flow do you follow. Please and Thank you :)

    @vrajmalvi7194@vrajmalvi7194Ай бұрын
  • not sure how long ago this was recorded but the correct import for pandasquery engine as of the latest version of llama-index is: from llama_index.core.query_engine import PandasQueryEngine

    @stephenbonifacio3846@stephenbonifacio38462 ай бұрын
  • This tutorial is super helpful. Thanks Tim. I was able to get the app working. when I ask a question about canada or population, Agent is able to answer the question by looking at the PDF, CSV etc.. But when I ask a question like "what is solar eclipse", the agent is still able to answer the question. How can I prevent it from happening ? I just want answers that are available in the documents.

    @SivaMahadevan-ny7vm@SivaMahadevan-ny7vmАй бұрын
  • in next 5 years they can write research papers, if you just give your idea and results. this is mindblowing.

    @prakhars962@prakhars9622 ай бұрын
  • Hey Tim, Can you make a video with mistral model locally loaded rather than using openai API key.

    @krishnak3532@krishnak35322 ай бұрын
  • Can I use it with my git repos (js, ts on nodejs)? It would be great to build custom, local copilot for coding.

    @sdkfeldfwerer6751@sdkfeldfwerer6751Ай бұрын
  • Nice

    @user-xb9hi6xb1w@user-xb9hi6xb1w2 ай бұрын
  • Question : once loading a vector store , how can we output a dataset from the store to be used as a fine tuning object ?

    @xspydazx@xspydazx10 күн бұрын
  • muy buen video pregunta como hago para que la salida este en formato pandas o dict o list ?

    @mejia414@mejia4142 ай бұрын
  • what are your thoughts on using some of the open source LLMs for this, via Ollama?

    @madhudson1@madhudson14 күн бұрын
  • if you pass context history with the new prompt only then would it be able to save to note. Passing context history to LLM is an integral part of any RAG otherwise it looses context.

    @bhasadish@bhasadish2 ай бұрын
  • Thank you for the video! Did anyone face the issue where the query engine returns only the pandas code and not the pandas output?

    @swetarajan1781@swetarajan17812 ай бұрын
  • For me, the agent keeps using the wrong column: df[df['Country'] == 'Canada']['Population'] despite there being no column named population

    @theuser810@theuser810Ай бұрын
  • Makes me want to build my own AI chatbot.

    @ANG747@ANG7472 ай бұрын
  • Cool video. Random question, are you ever going to move out of Canada? I know a few that have tried but there are too many hoops.

    @Hello_-_-_-_@Hello_-_-_-_2 ай бұрын
    • Yes I’m currently living in Dubai

      @TechWithTim@TechWithTim2 ай бұрын
  • can i make it use microsoft access and use the features in it? like using formulas curating huge amount of data is that possible?

    @frricbc4442@frricbc44422 ай бұрын
  • sory for basic question. can we make it into api that can be consumed ? thanks

    @adamabdullah6789@adamabdullah67892 ай бұрын
  • I wonder how we can use local LLMs like ollama or mistral using your code.

    @cematilkan8553@cematilkan85532 ай бұрын
  • Hi! Tim, can i choose different llm

    @najiibrashiidabdi5014@najiibrashiidabdi501422 күн бұрын
  • I know this could sound stupid I am new to this field, but instead of giving data in pdf or csv form can we retrieve data from website?

    @vibhorbisht4122@vibhorbisht41222 ай бұрын
  • is this tutorial one of the RAG application also

    @izzhamburhan9518@izzhamburhan95182 ай бұрын
  • I think this is way easier than the Langchain framework

    @shillowcollins6392@shillowcollins63922 ай бұрын
  • in case if you see this error --ImportError: cannot import name 'OpenAI' from 'llama_index.llms' (unknown location)-- do this --from llama_index.llms.openai import OpenAI-- and for error. --ImportError: cannot import name 'note_engine' from 'note_engine' (/Users/macbookpro/AIAgent/note_engine.py)-- change this. if not os.path.exist(note_file): to this if not os.path.isfile(note_file):

    @TanzerTel@TanzerTel2 ай бұрын
    • Thanks

      @ErdeEnterprise@ErdeEnterprise13 күн бұрын
  • what text editor theme is he using?

    @jeremyham764@jeremyham764Ай бұрын
  • Langchain or llama index, which is ideal

    @is_adjekofori@is_adjekofori2 ай бұрын
  • there is no query engine in my llama_index it not importing

    @saisreekarsunku9022@saisreekarsunku902225 күн бұрын
  • i am using Azure open AI. The agent some how does not work and give "openai.NotFoundError: Error code: 404 - {'error': {'code': '404', 'message': 'Resource not found'}}". All the credentials API, endpoint, were stored in .env file. Any solution or workaround for this?

    @user-wf5er3eo8v@user-wf5er3eo8v2 ай бұрын
  • Is this similar to Langchain agents?

    @KumR@KumR2 ай бұрын
  • Perhaps extend this to a web based interactive chat that allows a user to choose between different LLM models like the new llama 3 vs chatgpt

    @cclementson1986@cclementson198621 күн бұрын
  • Hi guys, I encounted with the following eroor message: from llama_index import PromptTemplate ImportError: cannot import name 'PromptTemplate' from 'llama_index' (unknown location) Please advise

    @vdzneladze1@vdzneladze12 ай бұрын
    • 'llama_index' should be 'llama_index.core' for both the import and the pip install. At least, that's what worked for me. So, the pip install is 'pip install llama-index.core pypdf python-dotenv pandas' and the import is 'from llama_index.core.query_engine import PandasQueryEngine'

      @stevenzusack9668@stevenzusack96682 ай бұрын
    • @@stevenzusack9668 thank you for your response, this just worked for me

      @ryansumbele3552@ryansumbele3552Ай бұрын
  • I was getting the python expression rather than the actual value as my output, any ideas why (although what I dont understand is thats what the instructions ask for - so why isnt this the correct output anyway?) > Pandas Output: df[df['Country'] == 'Canada']['Population2023'].values[0]

    @thelittlenuttree@thelittlenuttreeАй бұрын
    • discovered the problem: WARNING:llama_index.core.query_engine.pandas.output_parser:Python version must be >= 3.9 in order to use the default output processor, which executes the Python query. Instead, we will return the raw Python instructions as a string.

      @thelittlenuttree@thelittlenuttreeАй бұрын
  • I have import errors and there is no StorageCintext, Vector StoreIndex

    @noa2427@noa2427Ай бұрын
  • How to build a Autonomous RAG LLM Agent with Function Calling that is connected with External REST API like Microsoft Graph API ? Can You make a video on this ?

    @mallunightmares5845@mallunightmares584528 күн бұрын
  • note-engine is not available what the alternative for it

    @user-hb8xc1qv6e@user-hb8xc1qv6e2 ай бұрын
  • Everything is great except a few things. Idk why but the llama_index libraries used in the video has to be cahnged slightly for instance :"from llama_index.core.agent import ReActAgent" instead of "from llama_index.agent import ReActAgent", same with the prompts file ('from llama_index import PromptTemplate' won't work idk why still). Aprt from that, am I the only one who is getting error 429 and I havent used had a singel usage (according to the openai api usage page). HELP NEEDED!

    @arshadsafi8317@arshadsafi83172 ай бұрын
    • openai.RateLimitError: Error code: 429 same problems not working for me. do you found solution?

      @TheFeanture@TheFeanture2 ай бұрын
    • for me. CSV file was to long. i just deleted everything after Canada. now it is working

      @TheFeanture@TheFeanture2 ай бұрын
    • @@TheFeanture The problem was actually in the Openai account. Unforetunately when you sign up for a chat gpt account at the same time you receive that $5 free cedit. I had my account my nearly two years and it was expired (3 months limit for the $5). Solution: create a new openai account, with a new phone number.

      @arshadsafi8317@arshadsafi8317Ай бұрын
    • Did you figure out what the updated version of 'from llama_index import PromptTemplate' is?

      @mikkelchristensen4237@mikkelchristensen4237Ай бұрын
    • @@mikkelchristensen4237 from llama_index.core import PromptTemplate

      @wolfofthelight5690@wolfofthelight569027 күн бұрын
  • Bruh Can You Make A oop series for c++ please

    @zazbhai5802@zazbhai58022 ай бұрын
  • tim please put about LLM . what is rag how it work

    @rohithdon2621@rohithdon262119 күн бұрын
  • Openai free key has limit, any other free model we can use?

    @thelifehackerpro9943@thelifehackerpro99432 ай бұрын
  • the installing in the terminal doesn't work on my computer

    @perpektodimagkamali4529@perpektodimagkamali45292 ай бұрын
  • How to force llamindex to answer in the same language than the question is?

    @philippechassany7279@philippechassany72792 ай бұрын
  • first of all, thank you so much for the wonderful tutorial, as i m doing the follow through, i kept running into “ no module named ‘dotenv’ “. but i notice that my packages are all installed into lib/python3.11/site-packages directory instead of the bin folder. so i can not proceed the next step after that. wondering where i need to adjust? 🤔

    @PeterPan-hs5tu@PeterPan-hs5tu2 ай бұрын
    • Did you activate the virtual environment?

      @TechWithTim@TechWithTim2 ай бұрын
    • @@TechWithTim yup a little (ai) is added in front of the name inside the terminal

      @PeterPan-hs5tu@PeterPan-hs5tu2 ай бұрын
    • try using pip and then if that doesnt work use pip3 instead@@PeterPan-hs5tu

      @TechWithTim@TechWithTim2 ай бұрын
    • @@TechWithTimyou mean when i install using pip command via terminal instead of pip3?

      @PeterPan-hs5tu@PeterPan-hs5tu2 ай бұрын
    • @@TechWithTimI have been using the following command in terminal “pip3 install llama-index pypdf python-dotenv pandas” and as soon as the command finished installing, the notice popped up telling me the new release of pip available: 22.3.1 -> 24.0 so i tried upgrade it it didn’t work, i have also tried not upgrade still does not work 😢

      @PeterPan-hs5tu@PeterPan-hs5tu2 ай бұрын
  • Why is it that every time I try to follow a video in vscode using python, there is always some bullshit I encounter during the install process which takes 30 minutes to try and figure out the answer to? Is coding always this ridiculous?

    @Laxobigging@Laxobigging2 ай бұрын
  • Tech with Tim, can you please make something for the forex traders please

    @mr_e_xofficial@mr_e_xofficial2 ай бұрын
  • Very interesting video...we have just landed a big client that has thousand of documents. Would it be possible for you to help us with this project man, or at least offer your expertise on some consulting session ?

    @HypeDigitalyAI@HypeDigitalyAIАй бұрын
    • You can find my business email on my about page, send me an email

      @TechWithTim@TechWithTimАй бұрын
  • Can this be done without using openai?

    @OliverWatts-tq8nr@OliverWatts-tq8nr20 күн бұрын
  • Most of the time i try to use llamaindex, i get time out error. Is anyone else facing the same or encountered let me know.

    @deveshmishra5245@deveshmishra524525 күн бұрын
  • even in the .env file if i put my local. host model api is still trying to acces the openai api how can i fix it to use my local model api

    @og_23yg54@og_23yg542 ай бұрын
    • same

      @aryantiwari1945@aryantiwari19452 ай бұрын
    • @@aryantiwari1945 I can help you fix this issue I already fixed it use CrewAI not llamaindex

      @og_23yg54@og_23yg542 ай бұрын
KZhead