LangGraph vs. LangChain LCEL - Can we get rid of LCEL (LangChain Expression Language)
ฝัง
- เผยแพร่เมื่อ 8 ก.ค. 2024
- Many people seem to dislike LCEL. It is hard to debug chains, they are hard to read and can really become complex. Can we use LangGraph to create complex Chains instead of using LCEL for that? Let´s find that out!
Timestamps
0:00 Introduction
0:58 Simple RAG Chain with LCEL
4:00 RAG chain with LangGraph
8:07 Comparison & Discussion
I agree with you, thanks for showing us the light :D
I use LangGraph almost exclusively and on a daily basis, it makes the code more readable. Debugging also works much better. But sometimes I use LCEL as a one-liner for simple things (prompt template | llm | output parser). This can also make the code more readable, because otherwise you have some kind of subgraph again instead of a one-liner.
Conclusion: Your opinion is tried and tested 👍
Now there are two people on the internet who agree that using LangGraph exclusively whether for simple DAG (Directed Acyclic Graphs) or to add cycles and persistence is the way to go. Thank you very much for this most excellent walkthrough and code example.
You and me? ;-)
THREE people now :)
Make it four 😄
LangGraph seem very complicated but it's actually very modularized and aligns with the human brain's of logical thinking since human always thinks logically and tends to work step-by-step. Then, I can't agree more with you on the matter of debugging. Sometimes, I don't even understand my code even when it works after I have written a tons of codes on computer using LCEL😅 (U can imagine when it doesn't work and needs debugging😂)
After understanding the three most important concepts its actually quite easy :). I struggle less than just using lcel
Interesting, first I had the same thought of, only use Langgraph for complex scenarios, but since I've beign trying Langgraph I dont get why dont use it more, even for more simple scenarios.
Im pretty sure that for DAG might be less stressing/less code with only LCEL but coming back later for the same code is a little bit more complex to read and understand what is happening, Langgraph on the other way, its easier to debug, check the graph and see how the flow is working. But thats only my opinion, right now I definely agree with your final conclusions
Introducted that idea to my colleagues today, but they did not appreciate my initiave too much :(
I've suspected as much; not that I'm super experienced in either as yet.
It’s really cool to see the comparison. Langgraph is the winner. You can use lcel in langgraph, but not vice versa. There are a lot more options with langgraph
Anyone who've built complex systems will agree that the langgraph approach is, yes more complex, but also better structured.
That's a golden rule in software, if you want things to be standardized, easier to extend, easier to debug, and harder to break, you will need to write a bit more code.
Of course simplicity wins always, but simplicity != less code, it means easily readable and understandable code.
Which would you recommend for creating complex, production-ready agents with more than 30 nodes, with cycling and branching capabilities: Haystack, LangGraph, or a custom-built framework? I haven't seen a comparison between Haystack and LangGraph for real product development. What is your opinion?
I am not that familiar with Haystack I have to admit and since I am pretty familar with LangChain my opinion would be pretty biased
I might be wrong here but we cant send the response as a stream with langgraph right?
yes, it depends on the model. You can stream with Langgraph and openai
I had success using Langgraph with openai, check his video about streaming with fastapi, it helped me a lot.
BTW I had to use astream_events
the langchain docs go only for now to langchain and langsmith, I imagine LangGraph documentation is going to mature tremendously over time. the langchain videos bounce over to langsmith to trace stuff can you incorporate that so we can see 'under-the-hood'?
Yes, but often its the way the data looks that leads to an error and with that langsmith is not too great tbh
how would you store a chat history here? So e.g. saving the last 2 qa pairs
just create a new attribute for that: history: list[BaseMessage]. You can just append to that and do whatever you want with it
Can you make a in-depth playlist for langchain for 2024 a lot of things have changed , it would be amazing ! And you can make it with both lcel and langgraph
My in depth stuff is actually Happening on udemy. :). Thats Kind of my Business Model if you want to say so ;)
@@codingcrashcourses8533 does it have the latest update on lcel ?
@@codingcrashcourses8533 is it updated for
Lcel
LangGraph is very flexible, but their documentation is really bad.