Langchain and Pinecone with Node.js: A Quick Start Tutorial
Vložit
- čas přidán 25. 08. 2024
- #Langchain #Pinecone #Nodejs #Openai #javascript
Dive into the world of Langchain and Pinecone, two innovative tools powered by OpenAI, within the versatile Node.js environment. This crash course will guide you through the basics and up to more complex applications. Whether you're a novice developer or looking to expand your toolkit, this comprehensive guide will help you grasp these cutting-edge technologies quickly and effectively. Get ready to explore the potentials of AI and machine learning in programming with Langchain and Pinecone.
Github Link: github.com/dev...
Building A Chatbot with Langchain and Upstash Redis in Next js
czcams.com/video/gpXXIvfSCto/video.html
You do an excellent job as an educator, you cover so much so clearly and quickly. thank you.
That means a lot, thank you Nader!
calm voice, straight to the point
subscribed in the first minute❤❤
Thank you so much !
Enjoyed this thoroughly because I'm a newcomer to code and want to take this model apply to certain things like industry specifications for Quality Engineers in Aerospace asking their chatbots about material specifications or generating purchase orders etc...endless workflow improvements on the horizon!
I love this thought! Hope some of my videos can help you on your journey, let me know if you have any questions I can help with
thanks for providing a useful lesson. it will be great to update by pinecone for the "langchain/vectorstores" has been deprecated.
This is an amazing video! The content is really really helpful for someone looking for a js based solution amidst all the python ones. Again, appreciate it.
Thank you for the kind words. I am stoked you found it helpful!
I appreciate the nonsense free example - exactly what I needed!
Thank you for watching!
Thanks so much!!! Very illustrative video. Please go ahead with more videos for nodejs and js.
Thanks SLTRM! I really appreciate it, more to come soon… stay tuned!
@@DevelopersDigest typescript is supported by langchain?
Thanks sir, this is much needed one
Thanks Hemant!
Awesome tutorial, could imagine these video are part of a course.
Thanks Ren! That is a great idea!
That was a clear explanation, thanks for uploading! peace.
Thank you !🙏
Awesome intro tut. Thank you
Thank you Johann 🙏
Super super useful, thank you! Great job explaining it too.
Thank you Orto, that means a lot! 😀
Super helpful! Thank you!
Thank you for watching!
Very useful, I can put this to practical use very quickly 😊
Amazing! I love to hear that :)
You're videos are really good man. Thank you!
I appreciate you saying that Liam! Thank you for watching!
@@DevelopersDigest No worries dude. It's great to see some node js content out there for langchain. I've been struggling to find anything quality and your stuff is right up there with super clear explanations.
This was the best class I've ever taken. I got a lot out of it. Thank you.
I do have one question.
If I wanted to add a CheerioWebBaseLoader() in the following code, how would I modify it?
async readFiles() {
const loader = new DirectoryLoader(this.dataPath, {
'.txt': (path) => new TextLoader(path),
'.pdf': (path) => new PDFLoader(path),
});
const docs = await loader.load();
return docs;
}
Thank you 🙏 I will be releasing more Langchain content where I cover web loaders and I will make sure to include Cheerio.
The one thing with Cheerio or Puppeteer is that loader will be specific to the website you are trying to scrape or crawl and it will be based on the selectors on the page you need. Those will vary from website to website that you will need to use. Stay tuned if you are interested if you are interested!
Very helpful, thanks for sharing
Thank you for watching!
thank you, i was looking for a nodeJs tutorial, i am having some trouble when embeding - it is receiving an empty object or unexpected format, i think my initial docs in the publis directory aren't formated well.
Okay, I’m sorry to hear that. We’re you able to resolve the issue?
@@DevelopersDigest yes! Thank you, was able to make the pinecone method work as well as the hsnlib method. I started on small txt files but i'm wondering how well these methods will perform on very large sets of txt(like thousands of pages, have you had some test runs with very big files ?
Is this Be A Better Dev’s alternative channel?
Hi Cody 👋 this is my only CZcams channel 🙂
@@DevelopersDigest go listen to “Be A Better Dev”, you sound just like him, good video though!
I’ll go have a listen and thank you 🙏 that means a lot coming you! Cheers
Why are you concatenating all the docs before passing them to the LLM? Could you please explain the reason behind that decision instead of passing them directly to GTP? By doing this, as far as I understand, you are losing all the metadata attached to the doc.
Thanks for this video, I implemented this in a project but the cost to the OPENAI API is really high
Make sure to set up conditions to not re embed data each time if you are loading up a lot of document! Should also be able to with a bit of work be able to be tweaked to work with some other models!
@@DevelopersDigest I did set up conditions...the issue is that i live in a thrid world country so the cost of 3.5 dollars on average per day here is still quite high...I can send you the Github link you see if some optimazations are required
man, tysm!
Thanks for watching!
what if we only have one documents (2000pages doc) and we do not want to change our document each time ? I think you check if the document is new or not and if it is not new it will not do pinecone and embedding , am I right ?
You could do something like that potentially by checking for and adding a namespace.
docs.pinecone.io/docs/namespaces
A way to do this could be if you made your namespace your document name and then prior to the embedding process query for whether that namespace exists, if it does, just go straight to querying. Would just need a few tweaks to accomplish what you are asking
Perfect job sir. Just one question. Where did you config the Openai_key?
OPENAI_API_KEY=your key in a .env.
Make sure dotenv is installed. Cheers!
the video is awesome can you tell me how can add the prompt in the above while query from the pincone and also want to add the histroy of chat in that prompt how can do that can you give me some guidance about this.
its very helpfull for me i am stuck with this problem
Firstly, thank you for great content, delivered in very succinct and easy to digest way.
I was wondering if you looked at ways of updating documents in existing index as well as updating existing index with additional documents? From what I'm seeing at the moment it seems that the index might need to be recreated each time. I did find some information on using other vector storage solutions with suggestions of removing existing documents from the index first, and then adding the updated docs. Is this something you looked at?
Thank you, I know exactly what you mean. I haven’t been thinking on how to cover this and implement. With pinecone knowing which group of vectors to target. My thought would be to store the ids that correlate with each document and then when you update the new document you look to those stored ids and perform your delete operation. I might try and make a video out of this idea. Thank you for pointing this out, it’s a really good area to cover I think. You should not have to rebuild the index each time.
Thaynk you!!! Suscribed 🙂
Thanks Raphael!
Hello!Can you help me with my code, where I using your code.I have error:Error starting the bot: Error: OpenAI or Azure OpenAI API key not found.I dont know where i should to use that AI api key.
You must get the OpenAI api key from their website, make sure you have a .env in your project, make sure to have installed dotenv. And that you have the correct variable name between what’s in your .env and your js. Hope that helps, cheers!
Nice, I prefer python, but I'm not a coder heavy person. Gpt4 will need to explain me a lot of the code
But where did you pass the OPEN AI KEY ?
Awesome tutorial. When changing the vector dimension to 512, why do I get error "[Error: PineconeClient: Error calling upsert: Error: Vector dimension 1536 does not match the dimension of the index 512]"?
If you made a vector you want to use in the pinecone GUI and set it to 512 you would have to make sure to set it up with 1536 for OpenAI, alternatively make sure the embeddings model you are using matches that which you set within pinecone. Cheers!
[Error: PineconeClient: Error calling upsert: Error: PineconeClient: Error calling upsertRaw: FetchError: The request failed and the interceptors did not return an alternative response]
please help
will this work on pdf and csv files as well ? I have tried but i keep getting stuck in the update pinecone for loop
You might need to make some tweaks on normalizing the data. I have not dug into csvs too much yet. I might dive into this in a future video on some approaches to handle csvs where the responses from the vector db can be used in a meaningful way.
My intuition on this is maybe for the csvs upload, upload the header for each column in each set of rows that are uploaded but with that said there might be a better way, I just have to dig in more
I get a Maximum call stack size exceeded when trying to load a large amount of html data. Is there a good way to incrementally load documents and update the vector store without exceeding this size?
Recursive character splitter should work within langchain
Great video!
I'm sorry but I wanted to ask you a question. I'm building a small project for a client, but I'm having problems with "3-queryPineconeAndQueryGPT.js". On local it works fine but on Railway (where I deployed for testing), it doesn't return the "result.text".
I went through console.log() and I see that even concatenatedPageContent works fine, the problem seems to happen in :
const result = await chain.call({
input_documents: [new Document({ pageContent: concatenatedPageContent })],
question: question,
});
I don't know if the problem is in the call to the chain or where it creates a new document.
If you have any idea what's going on I'd appreciate it!
Error:
C:\Users\User\Desktop\Get-Started-With-Langchain-and-Pinecone-in-Node.js-main
ode_modules\@pinecone-database\pinecone\dist\index.js:102
case 5: return [2 /*return*/, Promise.reject(new Error("PineconeClient: Error calling ".concat(func.name.replace("bound ", ""), ": ").concat(error)))]; ^
[Error: PineconeClient: Error calling listIndexes: FetchError: The request failed and the interceptors did not return an alternative response]
Can You help me, please?
Make sure all the api keys are configured and the versions match what were used in the example. That would be my first recommendatikn
Can you help me please? I have error when running the command:
Created with client:
triggerUncaughtException(err, true /* fromPromise */);
^
[PineconeError: PineconeClient: Error calling query: PineconeError: PineconeClient: Error calling queryRaw: no healthy upstream]
This could be a pinecone specific issue, you can check status.pinecone.io/ if there are issues if you or others run into this. If you try and exit out and run it again after a period of time does this error persist?
@@DevelopersDigest Thank you for your reply, when I try to run it again it doesn't give the error anymore.
Thank you. Don't you know how to make it remember chat history?
That would be an easy swap in langchain if you are looking to do that!
@@DevelopersDigest yes i do. Also I'm interested in some way to put a "in your role as a..." system prompt to this model to make it answer me in the way I need and maybe format its answer as JSON for example
@@ivanivanivanivan1592 I have a lot more Langchain content coming. Next one will show how to build out a full stack chat app leveraging Upstash Redis to store and organize conversations if that is something you are interested in. Additionally for reliably returning JSON. There is a really handy trick to get a JSON response by leveraging OpenAI function calling. Check this out it might help! Finally, I have a video on langchain output parsers which may help if using models outside of OpenAI GPT models. Cheers! twitter.com/jaredpalmer/status/1673056725446844417
@@DevelopersDigest thank you! this link is
exactly what i need right now! 🤩
So this code is safe for not leaking api key , we need to add frontend to it?
If you take the necessarily precautions such as not pushing your environment variables to GitHub and have them secured in your production you should be good to go. In terms of front end you will have to incorporate it and add in a way to interact with the backend such as express.js if you’d like to turn this into a full stack app. Cheers!
Bro i achived by convert csv into txt file and use your code to question it's works, now i want to create a chat history how can i achive that and
i can see the create_pandas_dataframe_agent in python can answer the question in only three line code below
df = pd.read_csv('data.csv', encoding='ISO-8859-1')
agent = create_pandas_dataframe_agent(OpenAI(temperature=0), df, verbose=True)
result=agent.run(question)
using this vector pinecone we use OpenAI Embeddings API and OpenAI model to generate an answer
which one is better and less cost?
Great! All the costs are listed on OpenAI’s website. Embedding apis are considerably cheaper than LLMs. I have some more content and a recent video on Huggingface if you are exploring open source alternatives
@@DevelopersDigest sure i am also looking for that please make sure to use csv file 😅
Thank you so much for making this. I tried this today but I checked with a CSV file that contains 100 rows
So I use CSVLoader form langchain i just console the docs, it created multiple object for each row😢
So I can't use that in updatePinecone.js
Please give me solution..
You may need adjust a little bit, first a function just to normalize the data you want to embed. Then you could create a vector based on each row and embed those one by one, just make sure what you pass in the embedding function is normalized to be a string. Then you could send the metadata with an id of each row with the data each contains. There are a handful of approaches here, that’s the first that came to mind!
@@DevelopersDigest embed each row? so call OpenAIEmbeddings for 100 times it will cost me more please guide me if i am worng or please you can add some more minutes in video to explain this please..
for every file we need to create new index?
No, you only need to create the index once and can upsert subsequent documents as you need from there.
@@DevelopersDigest there will no override will occur?
What VSCode theme is that?
Cobalt2
Thanks! I've been using Palenight - really like it @@DevelopersDigest
GG ♥🙏👏
Thank you very much Rahul!
Openai is charging me $0.06 per answer. Is there any way to reduce this cost?
To create embeddings it uses text-embeddings-ada model which is consuming 13 tokens only for each call that is fine but to get the answer it uses davinci model which is consuming 2813 tokens to each. Is there any way I can avoid the use of davinci model to get the answer? Thanks in advance
A few things you can do. First use got-3.5 turbo. That should lower considerably. Next if you wanted you could limit the size of the embeddings before adding them to pinecone. You could also shrink the topK results if you want to bring it down further. Changing to 3.5 turbo should be a fraction of a penny for that amount of tokens
@@DevelopersDigest Thanks for your response. I have changed the model to gpt-3.5 turbo. It has resolved the issue
Beautiful, thanks. Plans for a Python version by chance?
I don't currently have one planned, right now I have a handful more Node.js + Langchain videos coming down the pike for upcoming videos I will be coding out and recording over the next several weeks. With that said, I won't rule it out if there is enough interest!
@@DevelopersDigest sounds great to me, I prefer the JS route myself, just giving a ChatGPT workshop next week, python is a bit more default. Happy to watch any and all content you produce, it is stellar.
Thanks for the great course.
Can I use OpenAIChat instead of OpenAI to get answers inside a PDF document? If so, how can I modify it?
Yes, absolutely
I have a number of langchain videos planned over the next month. I will be covering some chat options in upcoming videos. Stay tuned
I got this error 'The model `text-davinci-003` has been deprecated. I replaced it with text-embedding-ada-002. I got this response:
{
res: {
text: 'This (a,chain,a,1, 1,Chainl( 1,1,1,1)aL2d,aand,and,1,Chain,1,1,1l,1,Chainand,1 l1l2a,chain,1,chainin,1,1and,1n1c1 ( 1,1,1,1l1,1 1and 1 1 1
' +
. ..
}
}
Any idea?
Good tutorial, i did create and update all went successfully, the last querying i got an error, TypeError: text.replaceAll is not a function
at OpenAIEmbeddings.embedQuery (webpack-internal:///(sc_server)/./node_modules/langchain/dist/embeddings/openai.js:128:46)
The code brought an error: let queryResponse = await index.query({vector:queryEmbeddings}) Please help me fix this error
When I am trying to embedDocument it throws an error Request failed with status code 429 and sometime
const subPrompts = (0, chunk_js_1.chunkArray)(this.stripNewLines ? texts.map((t) => t.replaceAll("
", " ")) : texts, this.batchSize);
^
TypeError: t.replaceAll is not a function
I would first check your version of node and make sure you have an up to date version. You can do so by adding node -v in your terminal. I believe it was node version 15 or 16 when replaceAll was added into the engine :)
@@DevelopersDigest I am using node version 19