I’m stepping the world of Langchain. I have tried several approaches to build/learn a basic ChatBot application.
However, I’m still not clear on the differences between RunnableSerializable vs RetrievalQA
. I noticed they are both defined in different packages as well langchain.chains
and langchain_core
Both of the below codes produce the same responses on my data!
Here’s my sample code using RetrievalQA
#Time taken: 48 sec
retrieval_qa = RetrievalQA.from_chain_type(
llm=llm,
chain_type="stuff",
retriever=db.as_retriever(search_kwargs={'k': 10}),
return_source_documents=True,
chain_type_kwargs={"prompt": prompt},
verbose=True )
And using RunnableSerializable
#Time taken: 69 sec
retrieval_chain = (
{ "context": db.as_retriever(search_kwargs={'k': 10})
, "question": RunnablePassthrough()
}
| prompt
| llm
| StrOutputParser()
)
My questions here are:
- What is the performance impact of one over the other?
- How do I set
verbose=True
for debugging purposes in RunnableSerializable - Can I do
return_source_documents
in RunnableSerializable - What are some of the use cases where I would prefer one other the other?
Sys Config for benchmarking performance:
- Macbook Pro : 8GB – M1 Chip
- LLM : Llama3 (via Ollama)
- Embedding : “mxbai-embed-large”
- Langchain : 0.2
References:
-
https://api.python.langchain.com/en/latest/runnables/langchain_core.runnables.base.RunnableSerializable.html
-
https://api.python.langchain.com/en/latest/chains/langchain.chains.retrieval_qa.base.RetrievalQA.html