Python RAG Tutorial (with Local LLMs): AI For Your PDFs

Поделиться
HTML-код
  • Опубликовано: 6 июн 2024
  • Learn how to build a RAG (Retrieval Augmented Generation) app in Python that can let you query/chat with your PDFs using generative AI.
    This project contains some more advanced topics, like how to run RAG apps locally (with Ollama), how to update a vector DB with new items, how to use RAG with PDFs (or any other files), and how to test the quality of AI generated responses.
    👉 Links
    🔗 GitHub: github.com/pixegami/rag-tutor...
    🔗 Basic RAG Tutorial: • RAG + Langchain Python...
    🔗 PyTest Video: • How To Write Unit Test...
    👉 Resources
    🔗 Document loaders: python.langchain.com/docs/mod...
    🔗 PDF Loader: python.langchain.com/docs/mod...
    🔗 Ollama: ollama.com
    📚 Chapters
    00:00 Introduction
    01:06 RAG Recap
    03:22 Loading PDF Data
    05:08 Generate Embeddings
    07:16 How To Store and Update Data
    10:46 Updating Database
    11:45 Running RAG Locally
    15:12 Unit Testing AI Output
    20:29 Wrapping Up

Комментарии • 267

  • @musiitwaedmond1426
    @musiitwaedmond1426 Месяц назад +7

    this is the best RAG tutorial I have come across on youtube, thank you so much man💪

    • @pixegami
      @pixegami  26 дней назад +1

      Thank you! I appreciate it!

  • @tinghaowang-ei7kv
    @tinghaowang-ei7kv Месяц назад +13

    It's hard to find such high quality videos on China's Beep, but you've done it, thank you so much for your selflessness. Great talk, looking forward to the next video. Thanks again, you did a great job!

    • @pixegami
      @pixegami  Месяц назад

      Thank you! Glad you enjoyed it!

  • @frederichominh3152
    @frederichominh3152 Месяц назад +14

    Best tutorial I've ever seen in a long time, maybe ever. Timing, sequence, content, logic, context... everything is right in your video. Thank YOU and congrats, you are smart as hell.

    • @heesongkoh
      @heesongkoh 27 дней назад

      agreed.

    • @pixegami
      @pixegami  26 дней назад

      Wow, thanks for your comment. I really appreciate it, and I'm glad you liked the video.

  • @denijane89
    @denijane89 Месяц назад +4

    That was the most useful video I've seen on the topic (and I watched quite a lot). I didn't realise that the quality of the embedding is so important. I have one working code for local pdf ai, but I wasn't very impressed by the results. That explains why. Thank you for the great content. I'd love to see other uses of local LLMs.

    • @pixegami
      @pixegami  26 дней назад +1

      Glad you liked it! Thanks for commenting and for sharing your experience.
      And absolutely - when building apps with LLM (or any kind of ML/AI technology), the quality of the data and the index is really non-negotiable if you want to have high-quality results.

  • @JaqUkto
    @JaqUkto Месяц назад +2

    Thank you very much! I've started my RAG using your vids. Of course, much of your code needed to be updated, but it was simple even given my zero knowledge of Python.

    • @sergiovasquez7686
      @sergiovasquez7686 Месяц назад +2

      You may could share the updates to us 😅

    • @pixegami
      @pixegami  26 дней назад

      Nice work, glad you got it working!

  • @paulham.2447
    @paulham.2447 Месяц назад +3

    Very very useful and so much well explained ! Thanks.

  • @careyatou
    @careyatou 11 дней назад +1

    I got this to work with my own data. This was so cool. Thanks!

    • @pixegami
      @pixegami  10 дней назад

      Awesome! Glad to hear it worked for you :)

  • @nascentnaga
    @nascentnaga Месяц назад +3

    Suuuuuper helpful. I need to test this for a work idea. thank you!

  • @NW8187
    @NW8187 Месяц назад +3

    Simplifying a complex topic for a diverse set of users requires an amazing level of clarity of thought, knowledge and communication skills, which you have demonstrated in this video. Congratulations! Here are some items on my wish list for you when you can get to it. 1. Ability for users to pick among a selected list of open-source LLMs. A list that users can keep it updated. 2. build a local RAG application for getting insights from personal tabular data, which stored in multiple formats e.g. excel/google sheets, PDF tables

    • @pixegami
      @pixegami  26 дней назад

      Thanks for your comment, I'm really glad to hear it was helpful. I appreciate you sharing the feedback and suggestions as well, I've added these items to my list of ideas for future videos :)

  • @user-xk3tj5cj8p
    @user-xk3tj5cj8p Месяц назад +3

    Recently discovered your channel 🎉 , subscribed 😊 keep up the awesome content

    • @pixegami
      @pixegami  Месяц назад +1

      Thank you! Welcome to the channel!

  • @joxxen
    @joxxen Месяц назад +3

    Very nice, I wish I had this guide few weeks ago, had to learn it the hard way xD

    • @pixegami
      @pixegami  Месяц назад

      You got there in the end :)

  • @zhubarb
    @zhubarb Месяц назад +1

    Crystal clear. Great video.

    • @pixegami
      @pixegami  26 дней назад

      Thank you! Glad to hear that :)

  • @fabsync
    @fabsync Месяц назад +2

    Oh man.. by far the best tutorial on the subject.. finally someone using pdf and explaining the entire process! You should do a more in-depth series on this...

    • @pixegami
      @pixegami  26 дней назад +1

      Thank you for the feedback :) Looks like with the interest this topic has received, I'm definitely keen to dive into it a bit deeper.

    • @fabsync
      @fabsync 26 дней назад +1

      One of the questions that I was asking myself with pdf.. do you clean the pdf before doing the embeddings .. or this is something that you can resolve by customizing the prompt?
      What would be a good way to do semantic search after using pgvector..? I am still struggling with those answers

    • @pixegami
      @pixegami  26 дней назад

      @@fabsync Yeah I've had a lot of people ask about cleaning the PDFs too. I think if you have PDFs that have certain structural challenges, I'd probably recommend to find a way to clean/augment it for your workflow.
      And LLM prompt can only go so far, and cleaning noise from the data will always help.

  • @nachoeigu
    @nachoeigu Месяц назад +4

    Your content is amazing! Keep it going. I would like to see the continuation of this video in terms of how to upload and automate the workflow in the cloud AWS and how to integrate the chat interface with telegram bot

    • @pixegami
      @pixegami  Месяц назад +2

      Glad you liked it, and thanks for the suggestions. My next video will be focused on how to deploy this to the cloud - but I hadn't thought about the Telegram bot idea before, I will look up how to do that.

  • @carlosalberto-mo1wj
    @carlosalberto-mo1wj 2 дня назад +1

    I simply love the hole video!
    for the next Rag tutorial can you make a deploy on a azure cloud or any other cloud, just to see in depth how this works!
    thanks so mutch for the content man!

    • @pixegami
      @pixegami  День назад

      My upcoming video is actually about how to deploy a RAG app like this to the AWS cloud :) Stay tuned!

  • @basselkordy8223
    @basselkordy8223 Месяц назад +3

    High quality stuff. Thanks

    • @pixegami
      @pixegami  Месяц назад

      Glad you liked it!

  • @gustavojuantorena
    @gustavojuantorena Месяц назад +2

    Great content as always!

    • @pixegami
      @pixegami  Месяц назад

      Thanks for watching!

  • @muhannadobeidat
    @muhannadobeidat Месяц назад +1

    Great video and nicely scripted. Thanks for the excellent effort.
    I find that nomic 1.5 is pretty good for embedding and lightweight as well. I did not do actual performance metric based analysis of that but actual recall and precision testing is pretty impressive with 768 dimensions only.

    • @pixegami
      @pixegami  Месяц назад

      Thank you! Glad nomic text worked well for your use case :)

  • @RasNot
    @RasNot Месяц назад +1

    Great content, thanks for making it!

    • @pixegami
      @pixegami  Месяц назад

      Glad you enjoyed it!

  • @durand101
    @durand101 6 дней назад +1

    Such a helpful tutorial, thank you!

    • @pixegami
      @pixegami  День назад

      Glad you enjoyed it!

  • @AlexandreBarbosaIT
    @AlexandreBarbosaIT Месяц назад +3

    Smashed the Subscribe button! Awesome content! Looking forward for the next ones.

    • @pixegami
      @pixegami  Месяц назад

      Thank you! Glad you enjoyed it, and welcome!

  • @jial.5245
    @jial.5245 Месяц назад +4

    Thank you so much for the content👍🏼 very well explained! Would be great to see a use case of using autogen multi-agent approach to enhance RAG response.

    • @pixegami
      @pixegami  Месяц назад +1

      Glad you liked it, thank you! And thanks for the suggestion and project idea :)

  • @elvistolotti45
    @elvistolotti45 21 день назад +1

    great tutorial

  • @60pluscrazy
    @60pluscrazy Месяц назад +1

    Excellent 🎉🎉🎉

    • @pixegami
      @pixegami  Месяц назад

      Thank you! Cheers!

  • @KrishnaKotabhattara
    @KrishnaKotabhattara Месяц назад +3

    For evaluation, use RAGAs and Langsmith.
    There is also an SDK for azure which does same things as RAGAs and Langsmith.

    • @pixegami
      @pixegami  Месяц назад

      Oh, thanks for the recommendation. I'll have to take a look into that.

  • @namaefumei
    @namaefumei 12 дней назад

    This is great!

  • @pampaniyavijay007
    @pampaniyavijay007 Месяц назад +1

    Superb bro 🤩

  • @mrrohitjadhav470
    @mrrohitjadhav470 Месяц назад +8

    After searching 100s of videos journey ends here. 😍Please would you make a tutorial making a knowledge graph using Ollama?

    • @pixegami
      @pixegami  Месяц назад +2

      Thanks, glad your journey came to an end :) Thanks for the suggestion - I've added the idea to my list :)

    • @mrrohitjadhav470
      @mrrohitjadhav470 Месяц назад

      @@pixegami Aweeeeeeeesome, Just want to slightly change the knowledge graph based on pdf,txt (own data). Sorry for not elaborating, but too much own data makes it difficult to find connections between many sources.

  • @ishadhiwar7636
    @ishadhiwar7636 18 дней назад +1

    Thank you for the fantastic tutorial! It was incredibly helpful and well-explained. I was wondering if you have any plans to release a video on fine-tuning this project using techniques like RLHF? It would be great to see your insights on that aspect as well.

    • @pixegami
      @pixegami  15 дней назад

      Thank you! Glad you enjoyed the video. I've noted the suggestion about fine-tuning-I hadn't considered it yet, but thanks for sharing that idea with me.

  • @kozark875491
    @kozark875491 23 дня назад

    Very high quality video! Thank you!!!
    What are the min requrements to download and run locally llama3?

  • @sergiovasquez7686
    @sergiovasquez7686 Месяц назад +1

    I just subscribed to your channel… very high vids on RUclips

    • @pixegami
      @pixegami  26 дней назад

      Thank you! Welcome.

  • @JohnBoen
    @JohnBoen 24 дня назад

    He he he... tests are easy. I was wondering how to do those.
    Prompt:
    State several facts about the data and construct a question that asks for each fact.
    Create tests that look for the wrong answer...
    Give me 50 of each...
    Give me some examples of boundary conditions...
    Formatting...
    In an hour I will have fat stack of tests that would normally take a day a day to create.
    This is awesome :)

  • @maikoke6768
    @maikoke6768 24 дня назад

    correct and improve:
    The issue I have with the Rag is that when I ask about something in a document that I know doesn't exist, the AI still provides a response, even though I would prefer it not to.

  • @mingilin1317
    @mingilin1317 Месяц назад +1

    Great video! Successfully implemented RAG for the first time, so touching. Subscribed to the channel already!
    In the video, you mentioned handling document updates. Do you have plans to cover this topic in the future? I'm really interested about it!
    Also, is "ticket_to_ride" and "monopoly" sharing the same database in example code? What if I don't want them to share? Is there a way to handle that?

    • @pixegami
      @pixegami  26 дней назад

      Awesome! Glad to hear about your successful RAG project, well done!
      I've had a lot of folks ask about vector database updates, so it's something I definitely want to cover.
      If you want to store different pieces of data in different databases, then I recommend put another layer of logic on top of the document loading (and querying). Have each folder use a different database (named after each folder), then add another LLM layer to interpret the question, and map it to which database it should query.

  • @iainhmunro
    @iainhmunro Месяц назад +2

    This is pretty good. I was wondering how I could integrate this with my current python scripts for my AI Calling Agent, so if someone wanted to call the number, they could chat with the PDF.

    • @pixegami
      @pixegami  Месяц назад

      I think that certainly should be possible, but it's quite complicated (I haven't done anything like that before myself).
      You'd probably need something to hook up a phone number/service to an app that can transcribe the text in real like (like what Alexa or Siri does), then have an agent to figure out what to do with that interaction. And eventually hook it up to the RAG app.
      After that, you'll need to seriously think about guard-rails for the agent, otherwise you could end up with it getting your business into trouble. An example of this is when Air Canada's chatbot promised a customer a discount that wasn't available: www.bbc.com/travel/article/20240222-air-canada-chatbot-misinformation-what-travellers-should-know

  • @mehmetkaya4330
    @mehmetkaya4330 Месяц назад +1

    Great tutorial! And if you could please do a tutorial on when/how to know data within the documents (pdf or csv etc) has changed?

    • @pixegami
      @pixegami  Месяц назад

      Thanks for the suggestion :) That's a good idea, I think I'll have to plan it...

  • @MrRoflHamster
    @MrRoflHamster 13 дней назад

    Thank you so much for the tutorial! How would you go about creating a webinterface for the application to serve it locally for example?

  • @felixkindawoke
    @felixkindawoke 11 дней назад

    Thank you! Could you do a tutorial on how to talk to the data? So based on this create a voice chat with it.

  • @davidgortega3734
    @davidgortega3734 5 дней назад +1

    For the unit tests you can use tools or grammars to limit the output and that way you can fix some issues that you are showing

    • @pixegami
      @pixegami  День назад

      Good idea. I haven't actually explored testing LLM output in detail yet, and I think it will be a fascinating topic.

  • @ayoubfr8660
    @ayoubfr8660 Месяц назад +4

    Great stuff as usual! Could we have a video about how to turn this RAG app into a nice and proper desktop app with a graphic interface? Cheers mate.

    • @pixegami
      @pixegami  Месяц назад +1

      Good idea, thanks! I'll note it down as a video idea :)

    • @ayoubfr8660
      @ayoubfr8660 Месяц назад +1

      @@pixegami Thank you for the reply and reactivity! Have a nice day!

    • @J3R3MI6
      @J3R3MI6 Месяц назад +1

      @@pixegamiI subbed for the advanced RAG content

  • @nickmills8476
    @nickmills8476 20 дней назад +1

    To update the chromadb data for PDF chunks whose data has changed, store the PDF document contents hash in the metadata field. In addition to adding IDs that don't already exist, select records whose metadata.hash has changed and update these records, using collection.update()

  • @user-xz1jh9qv1k
    @user-xz1jh9qv1k 28 дней назад +1

    Very good content. Thanks for making it. Actually I liked your validation idea but How about for the descriptive answers to evaluate? Does pytest and prompt together works? Also did you make tutorial on how to update the vector database when file content changes.

    • @pixegami
      @pixegami  26 дней назад

      Thanks, I appreciate it! I think you can also try to use the same evaluation strategy for descriptive answers. I've also seen other commenters mention frameworks for evaluating LLM responses so that might be worth looking into as well.

  • @JorgeGil-qf6zy
    @JorgeGil-qf6zy Месяц назад +1

    thank you for the video pixegami, question, how will you do to implement follow up questions based on the last answer?

    • @pixegami
      @pixegami  26 дней назад +1

      You'd probably need a way to store/manage memory and use it as part of the next prompt. I haven't explored this much myself, but it's a topic I'm interested to look into as well, so thanks for the comment :)

  • @NgocDung211
    @NgocDung211 2 дня назад +1

    That's amazing video, thank you so much for your effort making those free. I want to know that if i have my own finetuned LLMs and want to use RAG. Is it something else diffrent.

    • @pixegami
      @pixegami  День назад

      Glad to hear it was helpful! I don't know how fine-tuned LLMs would interact with RAG. They are very different techniques - RAG is just a way to engineer better prompts.
      Both RAG and LLM fine-tuning can work together. But for general purpose use-cases, I'd probably avoid fine-tuning because it's harder and more expensive to operate/maintain.

  • @SmooveFinance
    @SmooveFinance 3 дня назад +1

    Hi, loved the video. I was wondering if it would be possible to populate the data with markdown files as well as pdf. this would greatly improve my training data :) thanks for your time

    • @pixegami
      @pixegami  День назад

      Yes, my first RAG tutorial actually uses Markdown :) ruclips.net/video/tcqEUSNCn8I/видео.html
      You can pretty much load any type of data, just need to search Langchain for the appropriate dataloader: python.langchain.com/v0.1/docs/modules/data_connection/document_loaders/markdown/

  • @danielcomeon
    @danielcomeon Месяц назад +1

    Thanks a lot. Great video!!! I want to know how to add new data to the existing database with new unique IDs.

    • @pixegami
      @pixegami  26 дней назад

      Thanks! Glad you liked it. If you just want to **add** new data, the chapter on updating the database should already cover this. You just need to add new files into the folder, and run the `populate_database` command again. Any pages/docs on in the database will be added.
      But if you meant updating existing pages/segments in the existing data, then yes I'll have to make a video/tutorial about that :)

  • @AiWithAnshul
    @AiWithAnshul Месяц назад +1

    This is an impressive setup! I'm currently using Weaviate as my Vector DB along with Open AI Models, and it's working really well for handling PDFs, Docs, PPTs, and even Outlook email files. However, I've been struggling to integrate Excel and CSV files into my Knowledge Base. For small Excel files, the vector approach seems fine, but it's challenging for larger ones. I'd love to get your input on how to build a system that incorporates Excel files along with the other formats. I've considered using something like PandasGPT for handling the Excel and CSV files and the traditional RAG approach for the remaining file types (PDFs, Docs, etc.). Perhaps adding an agent as the first layer to determine where to direct the query (to the RAG model or PandasGPT) would be a good idea? What are your thoughts on this?

    • @pixegami
      @pixegami  26 дней назад

      Thanks for your comment and for sharing your challenges and ideas. I think if you are mixing free-form text (like documents) and something more traditionally queryable (like a DB), it does make sense to engineer some more modality into your app (like what you suggested).
      I haven't explored that far myself so I can't share anything useful yet. But I'll be sure to keep it in mind for future videos. Good luck with your project!

  • @chhil
    @chhil 21 день назад

    Thank you for your content and access to your github repo. I tried modifying the code to read java file from the folder and keep getting an error Unsupported mime type: text/x-java-source. I use the GenericLoader to load the java file. Any pointers on where to look for a solution?

  • @LaptopiaLTD
    @LaptopiaLTD Месяц назад +1

    Thank you for making this concise, clear, and helpful video. Is there a limitation on the quantity and size of PDF files? I'm currently using ChatRTX; however, it has limitations due to being beta. Perhaps a video exploring this question and ChatRTX limitations would be useful?

    • @pixegami
      @pixegami  26 дней назад +1

      Glad you enjoyed it! I haven't had a look at ChatRTX yet, but thanks for the suggestion.

  • @edgarallik9995
    @edgarallik9995 Месяц назад +1

    Thank you for the video! Would there be an advantage in an LLM pre-processing the user query before it is embedded and matched against the database of documents? I'm thinking perhaps embedding the more useful parts of the user question to help in the matching process.

    • @pixegami
      @pixegami  26 дней назад +1

      Yes, there's actually quite a bit of research on "query transformation" to improve RAG results (and it's effective too). E.g. there's a technique that uses an LLM to create a "fake answer" to the question, then use that fake answer to query (instead of the question).
      Here's a paper on that: boston.lti.cs.cmu.edu/luyug/HyDE/HyDE.pdf

  • @nickmills8476
    @nickmills8476 20 дней назад +1

    Using a local embedding model: mxbai-embed-large, got me similar results to your monopoly answer.

    • @pixegami
      @pixegami  15 дней назад

      Thanks for sharing! I hadn't tried that one yet.

  • @shaigrustamov5115
    @shaigrustamov5115 Месяц назад +1

    Great videos 👍
    Do you think RAG is better than fine tuning for invoice data extraction?
    If I have 5000 invoices and want to train a model for data extraction, do you know if I need to prepare both OCR and labels? Do the labels also need to contain bounding boxes? Is not this very time consuming? Are there models that can be trained without bounding boxes?

    • @pixegami
      @pixegami  26 дней назад +1

      I don't have a ton of experience with fine-tuning LLM models so I can't compare them or advise them for your use-case. But in general, I prefer not to fine-tune, since that is quite a slow/expensive process and it'll bind your use-case tightly to your model (a RAG approach lets you switch LLMs more easily).
      For the OCR issue, I think you'll probably want to separate that process out as a different problem. You might want a computer-vision process to first extract the data for your document and standardize them somehow for your RAG workflow later.

  • @HimSecOps
    @HimSecOps Месяц назад +1

    Amaizing bro! Thank you I request you to tell how to connect the prompt part to ui

    • @pixegami
      @pixegami  26 дней назад +1

      Thanks for the suggestion :) This is on my list to work on as well, stay tuned!

  • @rob679
    @rob679 Месяц назад +1

    On model param size, 7B models are enough. Not related to this video, but I'm using Llama3 8B with OpenWebUI's RAG and it works but it sometimes have problems to refer to correct document while giving correct answer (it will hallucinate document name), but its how its RAG implementation are.

    • @pixegami
      @pixegami  26 дней назад

      Interesting, I haven't tried this with the 7GB models yet. Thanks for sharing!

  • @user-zl5dl7bu8j
    @user-zl5dl7bu8j 8 дней назад

    We can duplicate edited files upon an edit trigger , delete original file and have the duplicate being added to our existing database.

  • @MaliciousCode-gw5tq
    @MaliciousCode-gw5tq 22 дня назад

    Question will RAG method works even if the data are too big? Example 1k pages each file?

  • @E.X.P.JP_roblox
    @E.X.P.JP_roblox Месяц назад +1

    If my word documents contain mostly tables instead of text, and the format of the tables are all over the place and may be difficult to work with (with merged cells and sub tables), would the chunking and embedding steps stay the same? Or would you recommend cleaning up the word documents to kind of “flatten” the contents and perhaps make it easier for AI model to understand? However, manually cleaning up the files doesn’t sound like a scalable solution.

    • @pixegami
      @pixegami  26 дней назад +2

      Very good question, that's a real challenge I've run into as well in other projects. It's hard to answer-the chunking/prompting strategy really depends on the data, and the best way to know is to just test different strategies.
      Of course, you probably don't want a "manual" solution, but it might make sense to do things manually for a small part of the data just to see what works.
      With tables, I'd probably attempt to pre-process it somehow so it's in a format that could be embedded more easily. For example, I might normalize the headers/columns of the table into every row. E.g. instead of "30", I might change it to "price: 30", because I notice most table formats have the headers at the top, but that is cut-off if the table is split into two or more chunks.
      Complex problem! Let me know if you find something that works.

  • @vibesforyou8230
    @vibesforyou8230 День назад +1

    Hey , can yolu tell me which python version do you use for such project ? I am curious about working with LLMs , so this best video which gave me a decent understanding of communicating with LLMs but i never used pyhton so need to know what version is better for such project . BTW it great have your in feed and go through it 🙂

    • @pixegami
      @pixegami  День назад

      That's awesome. I use Python 3.10 right now, but anything higher than 3.8 should be fine. When you are learning, the version doesn't matter as much (as long as it's > 3).
      I also have an entire beginner tutorial series for Python as well if you're looking to learn (all 100% free!): ruclips.net/p/PLZJBfja3V3Rsbiz84Z63IXnTQZH_Rnfuo

  • @ziadbensaada
    @ziadbensaada 13 дней назад +1

    hi, it give me this problem when I run python populate_database.py:
    Could not load credentials to authenticate with AWS client. Please check that credentials in the specified profile name are valid. Bedrock error: The config profile (default) could not be found (type=value_error)

  • @NicolaRomano
    @NicolaRomano 29 дней назад +1

    Thanks for the great video! This might be a silly question, but say I want to extract some information from a bunch of PDF files. So, for example in your example of manuals I have manuals for 100 different games and want to know for each of them how many players is the game for. Is there a difference in processing all of the documents at once, putting them in a vector store and then query this versus processing one document at a time? I can see the advantage of having a vector store in case you want to ask another question, so you don't have to reprocess all of the documents, but aside from that? Also, can you somehow limit what context the LLM uses? Say I want to ensure the LLM is using file1.pdf but not file2.pdf how would I go about that?

    • @REINOSO195
      @REINOSO195 28 дней назад +1

      Amigo eso es tema de tesis, lul

    • @pixegami
      @pixegami  26 дней назад +2

      Thanks for watching and for the great questions. You are asking about 3 different use-cases I think, so it's probably best to tackle them one at a time as separate problems.
      1) If I wanted a very specific piece of information from all my documents, and I need it be accurate, then I'd probably write purpose-specific logic to extract it rather than make it a general-purpose thing.
      2) If you still wanted to run general queries across all the knowledge, then that could be a separate project (maybe using a knowledge graph instead of just a vector DB).
      3) You could store separate DBs, or use the tags/meta-data to filter out page that aren't from the one you want.
      These are all very basic solutions to you problems, but you get the idea - a good solution will depend on your use-case and how strong you need the solution to be.

    • @NicolaRomano
      @NicolaRomano 23 дня назад +1

      ​@@pixegamithanks I've been looking into metadata filtering and it seems to be a good direction indeed! I'm currently testing it and seems to do a good job!

  • @patoury4392
    @patoury4392 5 дней назад +1

    Very interesting, thanks for this video. I have a question : Once you realize that your model has many failures. How can you adjust back the model ? Should there be document replacement ? like starting over ?

    • @pixegami
      @pixegami  День назад

      Thank you for watching! That's an excellent question. I haven't explored all the options to rollback and limit blast radius in detail. Top of my head, I'd probably:
      - Separate my data-sources and DBs by topic/subject to limit the blast-radius (if something goes wrong).
      - Store every single version of the embedding DB and source data as a back-up. Maybe make them last 1-2 years before they get deleted (if storage cost is a problem). Then if I have an issue, just rollback to the previous version and try again.

  • @Queenmaya99
    @Queenmaya99 Месяц назад +2

    hello! do you know if there is a way to filter the db.similarity_search_with_score, based on metadata? for example, if you had a query and you wanted it to only reference the monopoly pdf to answer it.

    • @pixegami
      @pixegami  Месяц назад +1

      I think it might be possible. I haven't tried it, but looks like Chroma has an underlying API for filtering (and Langchain should surface it too): docs.trychroma.com/usage-guide#querying-a-collection
      collection.query(
      query_embeddings=[[11.1, 12.1, 13.1],[1.1, 2.3, 3.2], ...],
      n_results=10,
      where={"metadata_field": "is_equal_to_this"},
      where_document={"$contains":"search_string"}
      )

  • @TimC00k
    @TimC00k 12 дней назад +1

    Thank you for making great video. but I can't even start first step because the terminal displays error.. please help me

  • @beatsofbinary
    @beatsofbinary 25 дней назад +1

    I love your video. For the problem of updating a chunk, would a timestamp make sense? For example save the last modified date of a PDF file to each chunk
    Then after reading the documents again, compare if it's newer than that one in the database -> overwrite the chunks?

    • @pixegami
      @pixegami  25 дней назад

      I'm not sure how that would work - if you had a PDF that splits into 100 chunks, and you updated chunk 57, then how does your system know that the chunk was updated? If you *knew* it was updated you can store timestamp, but how do you know when the chunk is updated in the first place?
      I think you're quite close - rather than a timestamp, you can consider using a hash of the chunk (e.g. MD5), then use that to figure out if the chunk has change or not.

    • @beatsofbinary
      @beatsofbinary 24 дня назад

      @@pixegami I thought I could save metadata such as Last Modified directly when importing data. If the Vector database already contains a PDF document that has the same name but is older, it will be overwritten. If it is the same age, the PDF is skipped. I would therefore query the database to see which documents are already in the database. But then all chunks of the older PDF would have to be deleted, you're right. The idea with the hash is good, read in the PDF, split it, create a hash, save it as metadata and then compare the hashes of the chunks. But that leads to further problems, doesn't it? If, for example, only a few words change within a chunk, but the overlap changes as a result, will several or all chunks change at the same time?

  • @JoseLuisCornejoRivas
    @JoseLuisCornejoRivas 27 дней назад +1

    Now how to choose the correct document and not mix contexts from different documents?
    Thinking about a large documentary database

    • @pixegami
      @pixegami  26 дней назад

      Good question. I haven't looked into this myself, but I suspect you'd need to upgrade how you store/query data, maybe using something like a knowledge graph instead (e.g. neo4j): python.langchain.com/v0.1/docs/use_cases/graph/

  • @siswanto4045
    @siswanto4045 18 дней назад +1

    Wow, this is what I wanted. But can it be running on open webUI? Like running ollama locally with webUI? Thank you

    • @pixegami
      @pixegami  15 дней назад

      Glad to hear that! I do plan to do a tutorial later on how to build a a web UI for your app, so stay tuned.

    • @siswanto4045
      @siswanto4045 15 дней назад

      @@pixegami can't wait to watch the video

  • @albertozacchini3388
    @albertozacchini3388 Месяц назад +1

    Hi! Thanks so much for the video, it was super useful. However, i face that is a big problem for my laptop give all the context to the LLM, it will blow my CPU. Do you know any API of other free LLM instead of a local one?

    • @pixegami
      @pixegami  26 дней назад +1

      I haven't used any free LLM APIs myself, but the OpenAI and the AWS Bedrock ones are pretty cheap if you use the turbo models. Otherwise, I found this Reddit thread discussing free LLM APIs: www.reddit.com/r/deeplearning/comments/1350qtu/what_are_some_small_llm_models_or_free_llm_apis/

    • @albertozacchini3388
      @albertozacchini3388 25 дней назад

      @@pixegami yeah I give up on searching but I found the Mistral API really nice for embeddigs, still cheap and super fast to use. By the way thank you so much!

  • @uwegenosdude
    @uwegenosdude Месяц назад +1

    Thank you very much for the really helpful video. I also made bad experience when not using OpenAI to create embeddings. Can you recommend a free embedding model that produces good results and that I could run locally? I tried to use anythingLLM but RAG results were really bad. But I‘m not sure if the reason might be the language of my documents, they are all German.

    • @pixegami
      @pixegami  Месяц назад

      Thanks, glad you found it helpful! For local Embedding models, I haven't tried anything other than nomic-text so far. Have you tried all the other embedding models on ollama.com/library? There is a couple there.
      For non-English text, I heard Mistral (based in France) is quite good. I don't know if it's available on Ollama (officially), but it's open source so you should be able to get a copy: docs.mistral.ai/capabilities/embeddings/

    • @uwegenosdude
      @uwegenosdude Месяц назад

      @@pixegami thanks for your help. I will try this out.

  • @Ammarsays
    @Ammarsays 21 день назад +1

    I am just a layman and I want to know if text splitters count the characters, words or sentences for a given chunk size? And if the text splitters can identify sentences or paragraphs in text?

    • @pixegami
      @pixegami  15 дней назад

      Yup, the splitter should attempt to do that. Here's the documentation: python.langchain.com/v0.1/docs/modules/data_connection/document_transformers/recursive_text_splitter/
      "It is parameterized by a list of characters. It tries to split on them in order until the chunks are small enough. The default list is ["

      ", "
      ", " ", ""]."

  • @natemiles4951
    @natemiles4951 Месяц назад +1

    maybe a dumb question but im curious why the embeddings would be any different if using the same model to generate locally vs the cloud (IE bedrock)?

    • @pixegami
      @pixegami  26 дней назад +1

      The same model should generate the same embeddings, so if your local model is EXACTLY the same as using a cloud model it should work.
      In this video I'm using different models: 1) Titan (via AWS Bedrock) for the embeddings and 2) Mistral for the LLM agent.

  • @rude_people_die_young
    @rude_people_die_young Месяц назад +3

    Great work 🎉❤

  • @edwardtse8631
    @edwardtse8631 Месяц назад +2

    This is a very good tutorial, how do you solve the problem of edit a data file? to store sha-1 of the file?

    • @pixegami
      @pixegami  Месяц назад

      Exactly right - you can use an even simpler hash function like MD5 just to check that the content of each chunk hasn't changed.
      You'll still have to loop through all the chunks though to calculate the hash and to compare them. That should be fine for 100s or 1000s of chunks, but it might not scale too well beyond that.

  • @maxi-g
    @maxi-g Месяц назад +1

    Hey, I have a question. I tried to load a fairly large PDF (100 pages) into the database (approx. 400 documents). However the add_to_chroma function seems to be excruciatingly slow. The output from ollama shows that the embeddings only get requested once every two seconds or so. There is also no CPU or GPU load on my system when this process is running. Is there any way to improve this? Thank's already

    • @pixegami
      @pixegami  26 дней назад +1

      This is most definitely because of the time it takes to embed each page (since you mentioned embeddings get requested once every two seconds). Your Ollama model might not be able to fully leverage your hardware, which is potentially why your don't see your CPU/GPU load rise up.
      You could experiment by switching this to use an online embedding API (like OpenAI or AWS Bedrock) and see if it's faster. Or you could double check to see if Ollama is using your GPU correctly (github.com/ollama/ollama/blob/main/docs/gpu.md)

  • @AstigsiPhilip
    @AstigsiPhilip 13 дней назад

    Hi, this python rag can handle 70,000 pdf index files? thank you for your response.

  • @roxtonjhon
    @roxtonjhon Месяц назад

    How to retain context information in multi-turn conversations

  • @gianmarco-lr7wc
    @gianmarco-lr7wc Месяц назад +1

    hank you! It would be great to see how to deploy this to the cloud, for examplw aws!

    • @pixegami
      @pixegami  Месяц назад

      That's a great idea!

  • @phizicks
    @phizicks 26 дней назад +1

    md5 of the data to the index, if it matches, no update needed. unless I didn't understand the requirement

    • @pixegami
      @pixegami  26 дней назад

      Yup, I think that's probably how you'd go about indexing/updating specific chunks. You might also need a tree structure (e.g. hash the entire document or categorize them first) if you want to work in the scale of 10k+ documents.

  • @DCW09
    @DCW09 Месяц назад +1

    Cursory glance says - add a hashing function to the chunk metadata, this way the chunk should have a unique identifier (MD5, SHA, Etc) if anything changes the hash will also change. Then its just simple logic to validate current chunk page.index against an existing one's hash. If its different, overwrite. If its not, dont waste the cycles.
    In practice, I am not 100% sure that this would be the approach but at least the theory here should be pretty on point for identifying changes with few compute cycles.

    • @pixegami
      @pixegami  Месяц назад +1

      Yup! I think that's probably the way I'd do it too. If there's too documents and you need to scale it, then I guess you can hash the entire document as well first to narrow the search space each time.

    • @MichaelTanOfficialChannel
      @MichaelTanOfficialChannel Месяц назад +1

      @@pixegami I just want to add that I would apply the hash to the entire page and not the chunk. A page can be edited in a way where the content is shorter than previous version, thereby causing the number of chunks to be less that what it previously was. And I would also remove all chunks belonging to the said page before adding new chunks, so as not to have an orphaned chunk from the previous lengthier page.

  • @TrevorDBEYDAG
    @TrevorDBEYDAG 16 дней назад +1

    Thank you for the tutorial, I guess it should be a better way to create chunks, not only by character count because it cuts the paragraph in disruptive way. May be another library to split in paragraphs or at least end of the sentence?

    • @pixegami
      @pixegami  15 дней назад +1

      The Recursive Text Splitter actually attempts to do what you suggest: python.langchain.com/v0.1/docs/modules/data_connection/document_transformers/recursive_text_splitter/
      "It tries to split on them in order until the chunks are small enough. The default list is ["

      ", "
      ", " ", ""]."

    • @TrevorDBEYDAG
      @TrevorDBEYDAG 14 дней назад

      @@pixegami That's cool.

  • @EduardoJGaido
    @EduardoJGaido 28 дней назад +1

    Hello! Thank you for a great video. I ask you or the community, I have a hard problem to solve: i want to make a chatbot using a local LLM with RAG (keep reading please!) BUT i want to use it for my business so the clients of my physiotherapy clinic can ask it and it responds JUST WITH the information that is fed. Otherwise, it says "Oh, i don't know, wait please" so the secretary can answer instead. Just with that, I would be happy. I have a lot of FAQ listed with the answers (in a json friendly format). I can't find this answer anywhere. If you have any information, would be apreciated. Cheers from Argentina.

    • @pixegami
      @pixegami  26 дней назад

      I see, if it's an FAQ I'd structure each question or piece of information as a separate file, and just use a directory loader to turn it into Langchain documents. Then you can try using the technique in this video to see if works.
      To get it to respect the answer boundary, you can probably write an explicit prompt or an evaluation step to say "I don't know" if the answer isn't clear from the queries.

  • @MrAtomUniverse
    @MrAtomUniverse Месяц назад +1

    How do you display your code that way for video , would love to do that for my work

    • @pixegami
      @pixegami  26 дней назад

      I actually use a lot of custom tooling to generate the slides, but you can use this to do something very similar: carbon.now.sh/

  • @nirmalkumar007
    @nirmalkumar007 Месяц назад +2

    which part of the code makes the API call to the OLAMA server ? Kindly help

    • @pixegami
      @pixegami  Месяц назад +1

      The Langchain Ollama wrapper class (e.g. python.langchain.com/docs/integrations/text_embedding/ollama/ for the embedding) wraps all the code to call Ollama for you.

  • @derekpunaro2422
    @derekpunaro2422 Месяц назад +3

    Hi Pixe! I was wondering how would you write the get_embedding_function for Chat GPT OPEN AI?

    • @pixegami
      @pixegami  Месяц назад

      My first RAG project actually uses OpenAI embeddings: ruclips.net/video/tcqEUSNCn8I/видео.html
      Here is the documentation and code examples from Langchain: python.langchain.com/docs/integrations/text_embedding/openai/

  • @mo3x
    @mo3x Месяц назад +11

    So it is just an advanced ctrl+f ?

    • @pixegami
      @pixegami  Месяц назад +2

      Yes, that's one way to think about it. Still, incredibly powerful.

  • @Nord-su
    @Nord-su 6 дней назад +1

    Thanks a lot. How can I make RAG interact with Open WebUI as an interface?

    • @pixegami
      @pixegami  День назад

      Very interesting. I haven't looked into docs.openwebui.com/ yet, but it looks like a great use-case for integrating with RAG. Thanks for the idea!

  • @nhtdmr
    @nhtdmr Месяц назад +2

    Could you make video same project with LLAMA 3?

    • @pixegami
      @pixegami  Месяц назад +1

      You can do it here! Just change the Ollama model to Llama 3: ollama.com/blog/llama3

  • @xspydazx
    @xspydazx Месяц назад +1

    Question : once loading a vector store , how can we output a dataset from the store to be used as a fine tuning object ? as this is the most important part : producing the data from documents that will be used to fine tune the model : as the rag will have the domain documents etc embedded into the vector store:
    As you know retrieval time will be reduced after fine tuning the data into the model : but after deciding if the data is good to update of course , hence all historical chat should also be uploaded into the rag at the end of the chat?

    • @pixegami
      @pixegami  26 дней назад +1

      It really depends on what you want your training data to look like. But honestly I haven't done a lot of work in LLM fine-tuning myself so I can't really give advice on this question yet.

    • @xspydazx
      @xspydazx 23 дня назад

      @@pixegami in truth the beauty of langchain is it's document loaders , hence it enables for you to create datasets from your documents ... Or sites , so it just needs to be saved to JSON . Or your rag will continue to grow . As we know the rag is to fill the training gap !
      But if we have converted our docs we can run a fine tuning session and basically update the model .. so only for large docs or new docs should be in the rag .... The rag ...IE augmented query's ... This.can be done with your chains !! By your chain of questions to your chain , a still augmented response !

  • @mridulkc4010
    @mridulkc4010 7 дней назад +1

    Can the data source be a one-drive folder? I tried to get it to work with one-drive as the data source without success.

    • @pixegami
      @pixegami  День назад

      Hmm, try using the OneDrive document loader: python.langchain.com/v0.1/docs/integrations/document_loaders/microsoft_onedrive/

  • @johnharryduavis3414
    @johnharryduavis3414 Месяц назад +1

    Im wondering if you can deploy it in huggingface so I can use it for my mobile app?

    • @pixegami
      @pixegami  Месяц назад

      I'm not sure, I haven't used HuggingFace much self. But for sure I know it's definitely possible to deploy it as an API using some of the other cloud platforms (AWS, Azure, etc).

  • @vidfan1967
    @vidfan1967 Месяц назад +2

    I want to verify an existing PowerPoint document against a PDF, e.g. with an updated law text. I want to find out, whether my statements on each PPT slide are still true.
    Challenge: each slide contains one or more statements, which should be verified against the PDF, for example you have 6 or 10 bullet points on one slide. To use RAG I cannot use them all for the query as they might be quite diverse and would knowledge from the PDF, that is not specifically matching any one point but all of them together.
    Also: the context on the slide should be considered together with each statement, e.g. the title of the slide, an intro text above the bullet point list, or the upper level information for a statement that sits in a sub-structure of bullet points.
    I guess I would somehow need to split the statements in the PPT in logical chunks, preserving the context. Is there a python function I could use? Or can this be done with AI (e.g. few shot) after the slide text has been extracted?
    If this is of wider interest, I would appreciate a video on this 🙂

    • @pixegami
      @pixegami  Месяц назад

      Thanks for sharing your use case. Yup, this is definitely something you need to solve during the "chunking" phase of the process.
      For example, there are some experimental "chunking" functions from Langchain you could try: python.langchain.com/docs/modules/data_connection/document_transformers/semantic-chunker/
      Also, you could "bake" in custom information to each chunked document itself. E.g. something like (each variable name is made up):
      chunk.metadata["page_content"] = title_of_doc_str + context_str + actual_page_text_str

  • @devmit2071
    @devmit2071 Месяц назад +2

    How do you do this NOT running it locally? i.e. using the AWS cloud for pretty much everything (PDF in vector database, Langchain, Bedrock etc...)

    • @pixegami
      @pixegami  26 дней назад

      You'd have to change all the LLM functions to be cloud based (e.g. AWS Bedrock or OpenAI), wrap the app in an API (like FastAPI) and Docker, and deploy it to the cloud (probably as a Lambda function).
      I'm working on a video about that now, so stay tuned :)

    • @devmit2071
      @devmit2071 25 дней назад

      @@pixegami Thanks. I'll drop you an email with some ideas

  • @nvajay3829
    @nvajay3829 Месяц назад +1

    Brother, this is working well for PDFs, but PDFs with tables and json files it's not able to do even if i use json loader and modify the code. Can you make a video for it ?
    Local RAG for large json files

    • @pixegami
      @pixegami  Месяц назад +1

      Ahh yes, any weird formatting inside a PDF will be challenging. I'd probably try to approach it by seeing if I can first parse it into Markdown or HTML, because I think data in those formats are a little easier to work with.
      If you have any examples of PDFs you'd like to parse, please feel free to share them here and I'll see if it gets interest for me to cover in a future video. Thank you!

  • @gowthamkrishna6283
    @gowthamkrishna6283 Месяц назад +1

    can we do hashing on the page content to only update the modified? any one can share any link to do the same, thanks!

    • @pixegami
      @pixegami  Месяц назад

      Yup, that's the strategy I'd probably use to detect sections of pages being updated too. I don't have a video on it yet, but it's a great idea I'll add to my list of potential tutorials!

  • @Nabeel27
    @Nabeel27 27 дней назад +1

    How to deploy to the cloud so you can share the application?

    • @pixegami
      @pixegami  26 дней назад

      I'm actually working on that idea for my next video, so stay tuned!

  • @williamroales709
    @williamroales709 Месяц назад +1

    awesome! thanks ! how can i use a GPU to make local faster?

    • @pixegami
      @pixegami  Месяц назад

      I think it's probably a setting in Ollama. Have a look at: github.com/ollama/ollama/blob/main/docs/gpu.md

  • @P4jMepR
    @P4jMepR Месяц назад +1

    Would this solution be suitable for evaluating the best candidates from a 100 resumes for example? How would You approach such a project?

    • @pixegami
      @pixegami  26 дней назад +1

      I can't really say if it's a good solution for your use case. I'm sure some companies use LLMs as an initial filter for things like candidates/resumes. But for such a high-judgement, important decision, it's best to really validate it against human output.

  • @beatsofbinary
    @beatsofbinary 26 дней назад +1

    How to add a memory? For example if I want to ask follow up questions (contextual)?

    • @pixegami
      @pixegami  26 дней назад +1

      Good question. I haven't explored this myself yet, but many LLM libraries (including Langchain) seem to have a concept of a "memory" module: python.langchain.com/v0.1/docs/modules/memory/
      That'd probably be where I'd start.

    • @beatsofbinary
      @beatsofbinary 26 дней назад +1

      @@pixegami Thanks! I've seen another tutorial about that. The guy who created the script collected the chat history in a python list and added it to the prompt. Basically the LLM was given the questions and answers and was asked to reformulate that to a history. That was added then to the prompt something like: "Please answer the human's question based on this chat History"

    • @pixegami
      @pixegami  26 дней назад

      @@beatsofbinary Ah yup, even if you use a memory module, at the end of the day all LLMs are stateless so you pretty much always have to basically just add it back into the prompt :)

  • @lesptitsoiseaux
    @lesptitsoiseaux 7 дней назад +1

    May I ask why the embeddings weren't good enough and how you knew?

    • @pixegami
      @pixegami  День назад

      After I used the local embeddings, I tested end-to-end, and the database entries it matched weren't really the best matches (just from eye-balling the results).
      I guess it's because the model is quite small, the the embedding itself doesn't really have the dimensions to capture the meaning accurately.

  • @prateemnaskar1656
    @prateemnaskar1656 Месяц назад +1

    I want to execute the instructions in my PDF directly, How can I do it?

    • @pixegami
      @pixegami  26 дней назад

      You'd probably have to structure the app more like an agent, so it can look for information, but also take actions and execute on it: python.langchain.com/v0.1/docs/modules/agents/

  • @rahulsharmaah
    @rahulsharmaah Месяц назад +3

    can we get an api of this and apply in our application

    • @pixegami
      @pixegami  Месяц назад +1

      Yup! That's going to be the plan for my next video (hosting a RAG app in the cloud)