Let's Build a "Chat With PDF” app using Langchain(TS/JS), AI SDK, Pinecone DB, Open AI & Next.js 13

2024 ж. 13 Мам.
14 972 Рет қаралды

✨ Update ✨
Looks like Pinecone has removed namespaces from free-tier, so I pushed recent changes to github.com/rajeshdavidbabu/pd... and removed the name-spaces and tested the code its still working ! 🥹 🚀
Troubleshooting:
For " Error [InsufficientQuotaError]: 429 You exceeded your current quota, please check your plan and billing details. For more information on this error, read the docs: platform.openai.com/docs/guid...."
I had to delete all my old API keys and created a new one + charged my credits for about 10 dollars.
If you have questions jump on the discord link / discord
------------------
A beginner friendly and full-tutorial on how to build a “Chat with PDF” using Langchain, AI SDK, Pinecone DB, Open AI and Next.js 13.
Github: github.com/rajeshdavidbabu/pd...
(without AI SDK - Github: github.com/rajeshdavidbabu/pd...)
Timecode:
0:00 - Intro
01:08 - How to make your LLMs smarter ?
02:29 - Tech-stack walkthrough
04:20 - App Architecture
05:53 - Breakdown of app into steps
07:16 - Step 1: Setup Next.js 13 and shadcn app
08:54 - Step 2: Building chat UI components
14:44 - Step 3: Setting up API keys and ENV config
16:55 - Step 4: Setup Pinecone DB client
18:40 - Step 5: Embed PDF and store on Pinecone DB
24:18 - Step 6: LLM Templates and models
25:55 - Step 7: Building chains using Langchain
31:14 - Step 8: Prepare chat-endpoint
32:53 - Step 9: Build a streaming chat UI
36:09 - Step 10: Streaming the sources information

Пікірлер
  • Fantastic Raj. I am not a coder, just a sales guy and have been trying to develop one such thing for training my own team. This will help me a lot. Great going mate!

    @henapra@henapra3 ай бұрын
  • Excellent, very well explained!

    @FaizanS-nu5hs@FaizanS-nu5hs2 ай бұрын
  • Hi Rajesh, Excellent Work Bro!

    @timschannel247@timschannel2472 ай бұрын
  • You are a legend! Keep up the amazing work!

    @Karim-gr9yl@Karim-gr9ylАй бұрын
  • Thanks Raj.

    @prashlovessamosa@prashlovessamosa5 ай бұрын
  • fab buddy , keeping making ai based interesting videos

    @aakash2665@aakash26657 ай бұрын
  • this is a dope tutorial keep it up bru

    @jooshmayer@jooshmayer8 ай бұрын
    • Thanks for the feedback. Much appreciated!

      @raj_talks_tech@raj_talks_tech8 ай бұрын
  • excellent

    @user-fm8hs5uk4o@user-fm8hs5uk4o7 ай бұрын
  • Excellent video! Could you create a tutorial on building an agent using open-source tools like Llama2, Chroma DB, Langchain, and FastAPI? Also, include instructions on how to deploy the project

    @orlandocastellanos9263@orlandocastellanos92638 ай бұрын
    • thanks for the feedback ! Will see what I can do. I do really wanna try opensource llm but as I see it I would still need to use providers like Huggingface

      @raj_talks_tech@raj_talks_tech8 ай бұрын
  • i did the Embed PDF and store on Pinecone DB put iam bilding by app using express js can eny one help me how to implement Conversational Retrieval QA

    @mohamed.hesham@mohamed.hesham13 күн бұрын
  • Hey Raj, great tutorial! I'm planning on building an app where the user uploads a PDF, it is parsed to plain text, uploaded to GPT with a prompt and the user receives generated data based on the PDF. Will I need Pinecone for that, or is Pinecone just used for prolonged, multiple gpt requests like a chat? Cheers!

    @LM43243@LM432436 ай бұрын
    • If your PDF is too large, you definitely need to store it in a vector DB(like Pinecone) and do a retrieval step and only add relevant data to the GPT prompt. Why ? Because GPT Prompts have max-cap on tokens.

      @raj_talks_tech@raj_talks_tech6 ай бұрын
    • That makes a lot of sense, thanks mate.@@raj_talks_tech

      @LM43243@LM432436 ай бұрын
  • whats the accuracy of the LLM ?

    @dhruv.n1176@dhruv.n11764 ай бұрын
  • Good tutor, i have followed along. unfortunately got an error when run scripts, last step of storing embeddings on function embedAndStoreDocs, it just failed. Error: Request failed with status code 404 at createError (.....) I don't know how to fix it, Please help me

    @johnnylyimo@johnnylyimo8 ай бұрын
    • Hey John, I have also explained that your index creation might have failed. Check if you have the right pinecone API keys and try again. Or create the index on the pinecone console. It should work !

      @raj_talks_tech@raj_talks_tech8 ай бұрын
  • Hey this is really good information, how can make use of this to answer based on my webiste data instead of pdf ?

    @swapnilharpale-ic5fq@swapnilharpale-ic5fq3 ай бұрын
    • Please watch the attached link if you are done with "Chat with PDF" kzhead.info/sun/hpeMZpihfJyIras/bejne.html

      @raj_talks_tech@raj_talks_tech3 ай бұрын
  • Thanks for the video. Quick question, if I want to add multiple docs in my pinecone db should I run this cmd: npm run prepare:data and after that change the doc and run the cmd again?

    @mzafarr@mzafarr5 ай бұрын
    • Should work when you run the cmd everytime for importing a doc. In the end you need to make sure that you append the new doc to existing namespace or add it to a new-namespace (which may need you to have a paid account). But adding to a new-namespace would be easier

      @raj_talks_tech@raj_talks_tech5 ай бұрын
    • @@raj_talks_tech I'm on the free version so I am using it without namespaces. So will it work without changing anything else in your code, the only thing I changed was to remove the namespace part.

      @mzafarr@mzafarr5 ай бұрын
    • @@mzafarr Yes then you have to append to the existing name-space without destroying existing data. Can you double-check by running the command twice on a fresh-namespace ? You should see sum of vectors (vectors for doc A + doc B).

      @raj_talks_tech@raj_talks_tech5 ай бұрын
    • @@raj_talks_tech I looked at the code again and found that it won't do anything if index already exists. So I think some changes will be required, here you can have a look: const pineconeClient = new PineconeClient(); await pineconeClient.init({...}) const indexName = ... const existingIndexes = await pineconeClient.listIndexes(); if (!existingIndexes.includes(indexName)) { createIndex(pineconeClient, indexName); } else { console.log("Your index already exists. nice !!"); }

      @mzafarr@mzafarr5 ай бұрын
  • i get into a problem that 17:16, PineconeClient is not a module in this package

    @junaidiqbal4104@junaidiqbal4104Ай бұрын
  • Hello, how you can deploy this project on vercel because streaming do not support in vercel, can you please make a video or help us in deploying this site

    @user-ob1xi6zd8p@user-ob1xi6zd8p7 ай бұрын
    • Hi, For streaming I am using ai-sdk from Vercel. So I am pretty sure that it should be supported.

      @raj_talks_tech@raj_talks_tech7 ай бұрын
  • Nice thank you. Would it be possible to create a new one with the current packages? I get a lot of deprecated errors.

    @TheWhoIsTom@TheWhoIsTomАй бұрын
    • there is an update on my discord about this. updated namespaces field and also verified it last month

      @raj_talks_tech@raj_talks_techАй бұрын
    • @@raj_talks_tech nice thank you. Like the way you teaching! Another question: is there a chance you will record a session where you show implementing just an api route which does the work and than returning the result to the requester?

      @TheWhoIsTom@TheWhoIsTomАй бұрын
  • Suddenly namespaces are not supported in free tire project anymore. Also pinecode in new version expect array, so it doesn't work with new versions. Otherwise good tutorial. I made it to the end, but I'm not going to pay 70$ for the next pinecode tire to check if this actually can chat with documents.

    @ArtemBespalov@ArtemBespalov7 ай бұрын
    • Simply remove namespaces from allover the app and try again. There is an answer on my discord, jump on

      @raj_talks_tech@raj_talks_tech7 ай бұрын
    • You don't really have to pay. I found out afterwards. If you apply for the 70$ tire, you get charged with only what you use. It's about ~$2 per day. For the full day. It's completely based on time, you don't pay even for the whole day if you don't use it for that long. The only thing is that, if you have the index connected, then you pay. You can delete it and use it only when you need it and keep the information in a collection, which is ~$0.01 per day or something like that...

      @Alex75847493759573@Alex758474937595737 ай бұрын
  • Thanks buddy great tutorial ❤. I followed you but i am getting error. Error: Question key question not found. Can you help me plz

    @alishoaib3932@alishoaib39324 ай бұрын
    • Can you hop on the discord server you might find answers there !

      @raj_talks_tech@raj_talks_tech2 ай бұрын
  • hi raj, i had a small doubt. for this project do we need open ai credits?

    @shanu494@shanu4942 ай бұрын
    • Yes you need a working API account.

      @raj_talks_tech@raj_talks_tech2 ай бұрын
  • Where can I install ai-stream-experimental/react

    @KinglhbCoding@KinglhbCoding7 ай бұрын
    • Now the ai sdk supports streaming out of the box so you just need to install ai sdk and impor from "ai/react"

      @raj_talks_tech@raj_talks_tech7 ай бұрын
  • Raj, i f*cking love your videos. Could this technically be trained on millions of documents? i want tthem to medical documents

    @OBRosewell@OBRosewellАй бұрын
    • thanks bud. this is more of a RAG so technically its not trained. However if you want the behaviour to change then you can prepare a large dataset from your data and try finetuning !! But in most cases RAG should work if you have a proper chunking + embedding in place

      @raj_talks_tech@raj_talks_techАй бұрын
  • Hii can we use upload the pdf from the web also

    @divyanshiagrwal5216@divyanshiagrwal5216Ай бұрын
    • Absolutely 💯

      @raj_talks_tech@raj_talks_techАй бұрын
  • I am trying to follow through your video but when I try to setup the project, I don't have same files as you do. It would have been better if you could record that portion too. Sorry if it sounded like I wanted to be spoon fed, but thats not true

    @starlord7526@starlord75267 ай бұрын
    • I don't have components as you do and global.css has no dark mode lines

      @starlord7526@starlord75267 ай бұрын
    • Can you join my discord ? I think I can help you out !

      @raj_talks_tech@raj_talks_tech7 ай бұрын
  • Can I build this without pinecode??

    @aaaryanpatel@aaaryanpatel7 ай бұрын
    • Absolutely. You can use any vector database. And open source ones like Qdrant.

      @raj_talks_tech@raj_talks_tech7 ай бұрын
    • @@raj_talks_tech Oh! Thanks 🙏🏻

      @aaaryanpatel@aaaryanpatel7 ай бұрын
  • Why pinecone and not something else?

    @yt-mca@yt-mca8 ай бұрын
    • certainly you can use any vectorDB, I just used Pinecone as it was easy to get started

      @raj_talks_tech@raj_talks_tech8 ай бұрын
  • How can I use a local LLM with this?

    @skrylla@skrylla3 ай бұрын
    • Use Ollama

      @raj_talks_tech@raj_talks_tech3 ай бұрын
  • My application seems like it has access to information other than the files I provided, do you have any idea why this might happen? Great tutorial btw

    @tiagopereira1181@tiagopereira11815 ай бұрын
    • Not entirely sure what you mean here. If you run nodejs it should have access to your file-system.

      @raj_talks_tech@raj_talks_tech5 ай бұрын
    • @@raj_talks_tech basically I Uploaded a text file and the vectors on my dB are good but when I talk to him and make questions about the texts i gave him he gives me information that is not in there.

      @tiagopereira1181@tiagopereira11815 ай бұрын
    • @@raj_talks_tech it also seems odd that we have no similarity search running in the APP. How does it choose the right information ?

      @tiagopereira1181@tiagopereira11815 ай бұрын
    • @@tiagopereira1181 Pinecone takes care of it. It takes care of during embedding and also retrieval

      @raj_talks_tech@raj_talks_tech5 ай бұрын
    • @@raj_talks_tech it is weird because in the sources on each message it has chunks of texts that I Uploaded him with but the message that he sends is not related to the those files i uploaded

      @tiagopereira1181@tiagopereira11815 ай бұрын
  • How to handle PDF files that contains images, diagrams, charts, tables, etc?

    @tiagoc9754@tiagoc97543 ай бұрын
    • In this app you may not be able to handle it, but if you use GPT4 Vision capabilities you can

      @raj_talks_tech@raj_talks_tech2 ай бұрын
    • @@raj_talks_tech thank you. Yeah, I tried using GTP4 vision but it didn't work very well with flowcharts. Tesseract also fails on this. The only solution I could find so far is manually converting them to some textual representation. But that's not a valid option if we want users to upload their docs. I'm still looking forward a better solution for this. I'd be very grateful if you come across any solutions and could share them here. I'll let you know if I find anything as well

      @tiagoc9754@tiagoc97542 ай бұрын
    • @@tiagoc9754 May be try cogagent

      @raj_talks_tech@raj_talks_tech2 ай бұрын
    • @@raj_talks_tech Thank you, I'll take a look at that one

      @tiagoc9754@tiagoc97542 ай бұрын
  • I didn't get why we need 2 prompt templates

    @tiagoc9754@tiagoc97543 ай бұрын
    • Its for chaining LLM calls because instead of making everything in one call, you break down things into multiple tasks

      @raj_talks_tech@raj_talks_tech3 ай бұрын
    • @@raj_talks_tech thank you! I wasn't fully aware of the stand alone question concept. Now it makes totally sense

      @tiagoc9754@tiagoc97543 ай бұрын
  • can upload multi pdf file

    @hugorose4054@hugorose40545 ай бұрын
    • Hey Hugo, For now just one, but it should be pretty easy to extend

      @raj_talks_tech@raj_talks_tech5 ай бұрын
  • Is this considered RAG?

    @joshualazar40@joshualazar402 ай бұрын
    • Yes !

      @raj_talks_tech@raj_talks_tech2 ай бұрын
  • rather than using the command to execute("prepare:data": "tsx -r dotenv/config ./src/scripts/pinecone-prepare-docs.ts") for loading pdf, directly upload the file is possible? I tried it but the pdfLoader is throwing some error about fs module

    @JAZMedia_@JAZMedia_4 ай бұрын
    • You cannot as you need to chunk it and upload it and create embeddings for each chunk

      @raj_talks_tech@raj_talks_tech2 ай бұрын
KZhead