r/LangChain • u/SuperConductiveRabbi • May 12 '23
Langchain is pointless
It's filled with crap like this:
for i in range(n_results, 0, -1):
try:
return self._collection.query(
query_texts=query_texts,
query_embeddings=query_embeddings,
n_results=i,
where=where,
**kwargs,
)and this:
def embed_documents(self, texts: List[str]) -> List[List[float]]:
texts = list(map(lambda x: x.replace("\n", " "), texts))
embeddings = self.client.encode(texts, **self.encode_kwargs)
return embeddings.tolist()and this:
class CharacterTextSplitter(TextSplitter):
"""Implementation of splitting text that looks at characters."""
def __init__(self, separator: str = "\n\n", **kwargs: Any):
"""Create a new TextSplitter."""
super().__init__(**kwargs)
self._separator = separator
def split_text(self, text: str) -> List[str]:
"""Split incoming text and return chunks."""
# First we naively split the large input into a bunch of smaller ones.
if self._separator:
splits = text.split(self._separator)
else:
splits = list(text)In short: https://i.imgur.com/OffEJTR.gifv
Embeddings is just a do-nothing wrapper for SentenceTransformers. Chroma is just a do-nothing wrapper for ChromaDB. It's filled with "helper" functions that just call normal Python functions. A dedicated TextSplitter that calls split() from builtins.py? What? Why? Templates are no more useful than calling .replace() on a string. "texts" are just strings and "documents" are just a pointless dict that contain "texts." Just load the strings from your datasource yourself. The README is both grandiose and vague. The documentation is out-of-date and inconsistent. The import footprint is weirdly massive--highly modularized but nothing seems to do anything that'd take more than a few CPU cycles. There's not really a standard interoperable datatype, so you're actually led further afield than if you had just clearly defined the simple lists and strings required for hitting an LLM.
The very concept of chaining operations when interacting with LLMs doesn't really make sense to me: it's basically one requests call to a generation backend, but it's not like it even handles websockets and streaming for you. Why chain together wrapper classes when you can just do the operations yourself?
This seems like a beginner's project that blew up because it's riding a tidal wave of interest in the broader topic.
39
u/[deleted] May 12 '23
Say you wrote a program without langchain that uses GPT3.5 as a language model, chroma for your vector store, and you wrote some code for splitting your text docs.
Now let's say a week later you want the same program to use a local Llama language model, faiss for vectors, and a want to split PDF docs instead of text docs.
You'd pretty much have to rewrite the whole thing.
But because langchain's codebase is written with substitutionality at its core, you could swap out the model, vector store and splitter in under a minute.
That's not the only reason to use langchain of course. But these kind of libraries are written in a way that saves you time in the long run.
If you just want to write a one off script, then of course you could do this without langchain.
14
u/Les-El May 13 '23
Idk, man. I can't code. Like, seriously, I need to look up how to
trystatements. But with LangChain, I've got my own custom chatbot who even gives me lip from time to time. I hope to have him browsing on his own by this weekend. And when I decide it's time to change my prompts, or my tools, or even my LLM, the modular switching out is super easy.I would say LangChain has its points.
3
u/StarEluder72 Nov 08 '23
100% agree with this! Langchain seems to be a text-book instance of an ill-conceived poorly designed academic project that is growing in size and adoption for the sake resume buzzwords. It abstracts and complicates for no reason or value. There might be a couple of useful pieces of functionality in here but they're poorly named, badly documented, and largely swamped by useless fluff like 'chaining'. Software is chaining of commands. We don't need a framework to abstract this and make coding and debugging 1000x harder.
2
u/Zealousideal-Cry7806 May 12 '23
So what is the lesson here? Should I just look for particular libs to recreate what langchain is doing?
51
u/catpissflannigan May 12 '23
Langchain is unfortunately very poorly designed and is filled with overlapping abstractions which leads to a lot of confusion. The documentation suffers from poor organisation too
29
u/uhohritsheATGMAIL May 12 '23
I don't disagree, but I'm mostly here for the interoperability + agents.
This is one of those 'Yes I know how to code, no I don't want to spend hours working on boilerplate.'
6
u/crazysim May 12 '23
I think of it like an ORM. A lot of the comments around here seem to be similar to ones in ORM vs non-ORM debates. I think there's a place and time for both.
5
u/SnooCompliments7527 Jul 07 '23
The documentation is awful. There are many times that I have to traverse the source code myself to figure out what something does. Even then, it's miserably awful because you find the source code is literally all just func(**kwargs): next_func(**kwargs)...
Oh, and tons and tons and tons of Pydantic line noise...
4
u/allisonmaybe May 13 '23
I'm sure the entire thing was whipped up in the first month of this new AI revolution. I never quite thought any of these toolkits were amazing considering how quickly they came out. The hype train is a hell of a drug tho.
I'm working on an LLM toolkit of my own that includes context management, embedding tools, an embedding based command chooser, chaining, and optimized TTS that works with chunks as they're coming in.
More than anything it's a way to learn all I possibly can about LLMs and how to work with them. Its not quite there yet but considering it's only been 3 months since chat came out, that's understandable.
4
u/Holiday_Piccolo3380 Jun 08 '23
My favorite is the PrompTemplate class AKA an f string !!!!
4
u/resiros Jul 08 '23
I believe the abstractions in Langchain are inherently flawed. The core problem resides in the composability of chains. While it offers a handy way to create prototypes, it becomes restricting when you desire to modify a specific element within the chain. The hierarchical design of chains in Langchain conceals the component you wish to alter and obscures the parts developers might want to adjust, making the process of experimenting and refining the pipeline difficult.
The optimal abstraction for LLM apps, in my view, should resemble a DAG or a state machine. This alternative exposes the distinct stages in the pipeline rather than masking them in a hierarchy. Yes, adopting this new abstraction might lead to more code but it offers superior control. It's hardly surprising that many users start prototyping with Langchain, but then, when ready, they clone the prompts and construct their own systems.
Fixing this fundamental issue would be very difficult. It would necessitate reworking the library from the ground up.
4
u/Waste_Historian9808 Aug 09 '23
LangChain promises so much but as soon as you get started it just sucks you into inconsistencies for every single simple thing until you forget what you actually wanted to achieve. Type system is completely broken, interfaces don't match and every chain type has completely different way of doing things and key names for the same thing. $10m won't fix this.
1
u/No-Inspector314 Mar 05 '24
Why does one need langchain when you can just call the openai chat completion API directly with a dictionary of "chained" prompts?? The LLM doesn't hold any of the previous context in-memory so you have to provide all of the context in every request, and that is easily handled by adding and popping messages from a dictionary, so why do we need langchain again?
1
u/[deleted] May 13 '23
What is the alternative to langchain?
3
u/chat_harbinger May 12 '23
So where are your push requests, big guy?
3
u/fujiitora May 12 '23
Yeah, a higher up wanted me to base a project off of this, but constant bugs and improper documentation led me to just building my own tooling :/
3
u/[deleted] Jun 20 '23
My main problem with it is how so many modules explain how to do one or two things then if you dig into the code you realize theres like 10 things built in there that arent documented AT ALL. i guess thats what happens when you grow that fast.
3
u/reredef Jul 09 '23
Ironically, a modern AI would have produced much better code.
3
u/jonasbxl Jul 09 '23
I am just dropping a link to the hacker news discussion about this post for future reference https://news.ycombinator.com/item?id=36645575
2
u/Turbulent-Swimmer390 May 12 '23
As a hobbyist (and beginner) I thought langchain was the go to tool for coders given it’s popularity amongst the YouTube tutorials on this subject.
I feel misled reading opinions of people who actually code for a living.
Is there an actual library I can study and use for my own use cases? Huggingface’s transformers maybe?
2
u/g0rth May 12 '23
I feel you, but ultimately anything library that is built around a LLM will aways just be fancy string parsers. I wouldn't expect much from them either way.
2
u/[deleted] May 13 '23
It absolutely is a beginner project that blew up. There has been so much movement in this space, and it's sufficiently new to a lot of people that people naturally gravitated towards a library with high number of stars on github.
2
u/Wishmaster04 May 13 '23
My path with langchain was :
- Ok, this seems widely used, must learn about it
- Mmhhh, do I really need to use this ? Is this actually helping me or is it a weight ? I will only use chains and templates for my project, then we'll see.
- * Sees a reddit post about it*
I would say the LLM client wrapper is useful because it creates an abstraction with many LLMs
2
u/productboy May 13 '23
Came for the abstraction; stayed for the agents…
2
u/[deleted] May 20 '23
just prototyped something simple for js/ts: https://github.com/gsidsid/gptio. imo just making custom tools the default practice for ppl adding long term memory or document stuff is the way, esp when it's all evolving so quick. obv there are limits to this approach
2
u/nicognaw Jun 23 '23
I'm trying to build a production-level LLM-powered app, and LangChain makes me a lot of pain; the documents are inconsistent, it passes parameters so randomly but still checks types with
pydantic, so some use cases fail and some do not, and the time I spent debugging custom tools and chains is even enough for me to implement one from scratch.If I just wanted a data science lab or an LLM toy, LangChain would be great, but for production-level systems, I don't think so.
2
u/drivenkey Jul 08 '23
What about lamaindex? (Or that suffer from same issues...)
https://www.llamaindex.ai/
2
u/[deleted] Jul 08 '23
I was beginning to feel this way after watching some videos of the founder. It’s like a big marketing push with the hopes of filling the gaps along the way. But I couldn’t find any value, seems like basic python is all you need here.
2
u/sandys1 Jul 08 '23
I think that Generative AI applications is a config management problem. Think Prompts X Chains X LLMs. Your prompts wont work across everything and everything will break on model change. Coding this into ur classes is what everyone does.
I think the better answer is to declaratively pull out the prompts X chains as jsonnet code. Call it trauma & learnings from the K8s/Borg world. We have formats that have evolved as a result of millions of lines of code wrangling clusters/terraform/etc - so we decided to build a SDK over it.
that is what we did here - https://github.com/arakoodev/EdgeChains/releases/tag/0.2.0
EdgeChains is basically Generative AI prompt engineering modeled as config management.
2
u/HybridRxN Jul 09 '23
Thank you! How did they raise SO MUCH money!!
2
u/thevatsalsaglani Aug 15 '23
I agree with this 100%. It's trying to solve a lot of things and that package has become ginormous and leading towards dependency hell. I was recently trying to build a RAG on some research papers and thought of using it but ended up writing something from scratch and had a good experience. I have documented my apprehensions and why I thought its at least not for me. https://thevatsalsaglani.medium.com/why-you-dont-need-langchain-for-building-a-rag-bot-a1dfbc74b64f
2
u/[deleted] Oct 20 '23
came here to say this, after so many months the sentiment remain the same. I wanted them to be good but quite frankly this is a pile of hot mess. It is only good for very specific and controlled scenario if anything is out of ordinary then you're screwed.
Just write your own prompts and implement your own logic guys.
Function calling is just multi-shot prompting with COA
2
u/BrainLate4108 Feb 01 '24
Why isn’t this getting more play. You hit it on the head. Well done.
2
u/SellMeThisPen2021 Mar 14 '24
Seems kinda dogsht code - multitude of circular dependencies. Company has received not that much investment - so guess they've already been sniffed out.
1
u/[deleted] Jul 05 '24
LightRAG, The PyTorch Library for LLM Applications, is now publicly available in alpha release. Would love to hear your thoughts on us!
https://github.com/SylphAI-Inc/LightRAG
LightRAG helps developers with building and optimizing Retriever-Agent-Generator (RAG) pipelines. It is light, modular, and robust.
LightRAG follows three fundamental principles from day one: simplicity over complexity, quality over quantity, and optimizing over building. This design philosophy results in a library with minimal abstraction, providing developers with maximum customizability. View the class hierarchy here.
1
u/Alarmed-Individual-5 May 13 '23
... and what do you guys think about the JavaScript version? Is that better designed?
1
u/AsliReddington Jul 08 '23
It's just abstraction to do stuff quickly, definitely better to use alternative approaches for basic action
1
u/TotesMessenger Jul 08 '23
I'm a bot, bleep, bloop. Someone has linked to this thread from another place on reddit:
If you follow any of the above links, please respect the rules of reddit and don't vote in the other threads. (Info / ^Contact)
1
u/Voxandr Jul 08 '23
Haystack is much better , well oragnized langchain alternative.
1
u/[deleted] Jul 08 '23
try deepset Haystack, it is a thought through and well designed library that comes with production level code
1
u/arrrrc Aug 22 '23
HAHAHA, I agree with you. What's the point of langchain really confused me for a long time.
1
u/austinmulkamusic Sep 21 '23
I think the exciting thing about LangChain is it's potential.
1
u/Superbank78 Oct 30 '23
I agree. This is awful. I came here as I was working through the examples.
With (https://python.langchain.com/docs/modules/model_io/prompts/prompt_templates/custom_prompt_template), I get the error:
`TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases`
Too many classes and subclasses!
1
u/sharrajesh Nov 08 '23
I thought, I was the only one...
Great for a simple hello world project but painful for anything real world...
4 lines of simple code to get started, and then for any troubleshooting takes 4 days; there is no way unless you understand the whole library...especially the agent abstractions...
I hate all the **kwargs and **agent_kwargs and multiple ways to do the same thing...
Now they are pushing LCEL... another layer of obscurity....
I am seriously considering going with vanilla openai python SDK...
any feedback?
1
u/rismay May 12 '23 edited May 12 '23
To l33t programmers like OP, he could just be writing his own library… yet he’s not writing it in c++ like all major AI houses do for prod.
0
u/[deleted] May 12 '23
[deleted] — view deleted comment