LangChain Tutorial (JS) #7: Long Term Conversation Memory

  Рет қаралды 3,679

Leon van Zyl

Leon van Zyl

Күн бұрын

#openai #langchain #langchainjs
The Memory modules in Langchain make it simple to permanently store conversations in a database, so that we can recall and continue those conversations in the future - just like the conversations in ChatGPT.
📑 Useful Links:
Langchain JS Chat Memory Docs: js.langchain.com/docs/integra...
Source Code: github.com/leonvanzyl/langcha...
Upstash: upstash.com/?Leon_...
☕ Buy me a coffee:
www.buymeacoffee.com/leonvanzyl
💬 Chat with Like-Minded Individuals on Discord:
/ discord
🧠 I can build your chatbots for you!
www.cognaitiv.ai
🕒 TIMESTAMPS:
00:00 - Introduction to Memory
00:47 - The Problem
01:40 - Project Setup
03:30 - BufferMemory
05:33 - ConversationChain
08:43 - Long Term Memory
08:56 - Adding Upstash Redis Memory
10:50 - Create Upstash Account
12:41 - LCEL RunnableSequence Approach
17:31 - Save Context to Memory

Пікірлер: 28
@leonvanzyl
@leonvanzyl 5 ай бұрын
Forgot to mention that you can add memory to an agent in the exact same way. The AgentExecutor class also accepts the memory property. The rest is exactly the same 😎.
@nomad4691
@nomad4691 4 ай бұрын
I"m blown away you don't have more subs. Following your Finance Tracker, nextJS, and now your LangChain series. All relevant to my career, and you have such a great way to explain and demonstrate.
@leonvanzyl
@leonvanzyl 4 ай бұрын
Thank you!
@zmeireles68
@zmeireles68 5 ай бұрын
Awesome video Leon. A bit confusing the runnables part, but I guess I'll have to dig in the langchain docs.
@leonvanzyl
@leonvanzyl 5 ай бұрын
Honestly, I prefer the first method. For completeness sake, I had to introduce RunnableSequence.
@divyamjain8804
@divyamjain8804 Ай бұрын
Please continue this series. 🥹🥹
@leonvanzyl
@leonvanzyl Ай бұрын
Will do.
@mrinank
@mrinank Ай бұрын
please continue this series
@TheWhoIsTom
@TheWhoIsTom 2 ай бұрын
Dedicated videos about runnable sequence would be nice
@ehiaig
@ehiaig 2 ай бұрын
Thanks for this video, it really simplifies langchain. However I keep getting this error "Error: output values have 1 keys, you must specify an output key or pass only 1 key as output" from the saveContext line. Would really appreciate any suggestion you have. Thanks alot async function callChain(userInput) { const res = await chainHistory.invoke( { input: userInput }, { configurable: { sessionId: String(chatId) } } ) await memoryInstance.saveContext({ input: userInput }, { output: res.content }) return res }
@jonymnimonik-ff7dg
@jonymnimonik-ff7dg Ай бұрын
Yes
@judgebot7353
@judgebot7353 4 ай бұрын
How to integrate retrieval chain that we created in previous video-5 with conversational Chain ? e.g. const HistoryAwareRetrievalChain = await createRetrievalChain({ retriever: historyAwareRetriever, combineDocsChain: documentChainChat, });
@michaeldavidgarcia5998
@michaeldavidgarcia5998 3 ай бұрын
Thanks for these videos Leon, amazing job !!! I wanted to ask you, how can I implement this memory, with the documents, like the tutorial in the video 5, working with for example 'historyAwareRetriever' and my own documents ??
@leonvanzyl
@leonvanzyl 3 ай бұрын
Most of these chain take memory as input.
@michaeldavidgarcia5998
@michaeldavidgarcia5998 3 ай бұрын
@@leonvanzyl thanks for replying Leon! I mean neither createStuffDocumentsChain, createHistoryAwareRetriever, createRetrievalChain, take memory as input, can't find an example in the documentation, to do it with my own documents, do you know how. Maybe I have to create a separate database, select the rows and start creating an Human and AIMessage ?
@ahmadalmasri1583
@ahmadalmasri1583 3 ай бұрын
thanks
@leonvanzyl
@leonvanzyl 3 ай бұрын
You're welcome!
@Jaimie-C
@Jaimie-C 4 ай бұрын
Thank you for the great video! I think a video on runnable sequences would be good.
@leonvanzyl
@leonvanzyl 4 ай бұрын
You're welcome 🤗
@Jaimie-C
@Jaimie-C 4 ай бұрын
also maybe do a video on connecting this with a html/css/javascript ui@@leonvanzyl
@verticalstatue
@verticalstatue 3 ай бұрын
I agree. Runnable sequence pls
4 ай бұрын
The video is great! I would like to know how to use the stream function of the chain. usually, I use: const outputParser = new StringOutputParser() const chain = prompt.pipe(model).pipe(outputParser) let stream = await chain.stream({ question: "what are structs in Golang?", }) for await (const chunk of stream) { process.stdout.write(chunk) } But I understand that ConversationChain has no pipe method I tried with a runnable sequence, but it does not work (no response)
4 ай бұрын
ok, I think it was because of my prompt, and now with the runnables and RunnableWithMessageHistory it works again, your videos are great
4 ай бұрын
this is what I did: const prompt = ChatPromptTemplate.fromMessages([ SystemMessagePromptTemplate.fromTemplate( "You are a TV series expert. Make short answer only" ), new MessagesPlaceholder("history"), HumanMessagePromptTemplate.fromTemplate( `Question: {question}` ) ]) const outputParser = new StringOutputParser() const chain = prompt.pipe(model).pipe(outputParser) const messageHistory = new ChatMessageHistory(); const chainWithHistory = new RunnableWithMessageHistory({ runnable: chain, getMessageHistory: (_sessionId) => messageHistory, inputMessagesKey: "question", historyMessagesKey: "history", }) const config = { configurable: { sessionId: "1" } }; let stream = await chainWithHistory.stream({ question: "Who is James T Kirk?" }, config)
@michaeldavidgarcia5998
@michaeldavidgarcia5998 3 ай бұрын
Please dedicated video for Runnables :D
@judgebot7353
@judgebot7353 4 ай бұрын
Response from agents are not quite accurate. I liked retrievalChain approach much better . I just want to add long term memory . Can you help me in that pls ? const HistoryAwareRetrievalChain = await createRetrievalChain({ retriever: historyAwareRetriever, combineDocsChain: documentChainChat, });
@nocnydrwal9499
@nocnydrwal9499 4 ай бұрын
Please create video about runnables.
@leonvanzyl
@leonvanzyl 4 ай бұрын
Will do
LangChain Tutorial (JS) #6: Self-Reasoning Agents with Tools
17:09
Final muy increíble 😱
00:46
Juan De Dios Pantoja 2
Рет қаралды 50 МЛН
Became invisible for one day!  #funny #wednesday #memes
00:25
Watch Me
Рет қаралды 52 МЛН
ROCK PAPER SCISSOR! (55 MLN SUBS!) feat @PANDAGIRLOFFICIAL #shorts
00:31
Memory in LLM Applications
16:16
Weights & Biases
Рет қаралды 6 М.
A Competition for Unreadable Code?
12:33
LaurieWired
Рет қаралды 155 М.
Memory in LangChain | Deep dive (python)
20:40
Eden Marco
Рет қаралды 9 М.
LangChain: Giving Memory to LLMs
15:48
Prompt Engineering
Рет қаралды 20 М.
The future of AI looks like THIS (& it can learn infinitely)
32:32
LangChain Master Class For Beginners 2024 [+20 Examples, LangChain V0.2]
3:17:51
Собери ПК и Получи 10,000₽
1:00
build monsters
Рет қаралды 2,3 МЛН
Tag her 🤭💞 #miniphone #smartphone #iphone #samsung #fyp
0:11
Pockify™
Рет қаралды 23 МЛН
Здесь упор в процессор
18:02
Рома, Просто Рома
Рет қаралды 73 М.
Blue Mobile 📲 Best For Long Audio Call 📞 💙
0:41
Tech Official
Рет қаралды 1 МЛН