AI / LangGraph LangChain Interview questions
What are common chain composition patterns?
Beyond simple prompt | model | parser pipes, a handful of patterns appear repeatedly in production LangChain applications:
- RAG pattern — retrieve relevant documents, inject them into a prompt, generate an answer. The retriever and passthrough run in parallel so both context and question reach the prompt:
{context: retriever, question: RunnablePassthrough()} | rag_prompt | llm | parser - Router / conditional branch — use
RunnableBranchor a lambda to route different inputs to different sub-chains. Useful for multi-intent chatbots where a general question goes to one chain and a SQL query goes to another. - Map-reduce — split a long document into chunks, process each chunk in parallel with
.batch(), then reduce the results with a combine chain. Standard pattern for summarising books or analysing large codebases. - Refine — process chunks sequentially, passing the previous summary into the next iteration to progressively build a better answer. More accurate than map-reduce for certain summarisation tasks.
- Fallback chain — primary chain with a backup:
gpt4_chain.with_fallbacks([gpt35_chain]). If the primary raises an exception, the fallback is tried automatically. - Branching + merge — run parallel branches (e.g. extract entities, summarise, classify sentiment) and merge their outputs into a final dict for downstream use.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
