Performance: LangChain architecture overview
This affects the speed and responsiveness of applications built with LangChain by influencing how data flows and how many external calls are made.
Jump into concepts and practice - no test required
from langchain.schema.runnable import RunnableParallel chain = RunnableParallel(chain1, chain2, chain3) result = chain.invoke(input_data)
from langchain.chains import SimpleSequentialChain chain = SimpleSequentialChain(chains=[chain1, chain2, chain3]) result = chain.run(input_data)
| Pattern | Data Calls | Wait Time | User Interaction Delay | Verdict |
|---|---|---|---|---|
| Sequential Chains | Multiple sequential calls | Sum of all calls | High delay before response | [X] Bad |
| Concurrent Chains | Multiple parallel calls | Max of all calls | Lower delay, faster response | [OK] Good |
from langchain import PromptTemplate, LLMChain
prompt = PromptTemplate(template="What is the capital of {country}?")
chain = LLMChain(prompt=prompt)
result = chain.run(country="France")
print(result)from langchain import PromptTemplate, LLMChain
prompt = PromptTemplate(template="Say hello to {name}")
chain = LLMChain(prompt=prompt, llm=None)
output = chain.run(name="Alice")
print(output)