Performance Issue with Langchain 0.2.6 #26521
Replies: 2 comments 1 reply
-
Hey there, @herbertmoses! I'm here to help you with any bugs, questions, or contributions you may have. Let's tackle this issue together. To resolve performance issues when invoking a Here is an example of how you can use from langchain_core.runnables import RunnableLambda, RunnableParallel
# Define your functions for generating, creating, getting, updating, and deleting tickets
def generate_ticket(data):
# Implementation for generating a ticket
pass
def create_ticket(data):
# Implementation for creating a ticket
pass
def get_ticket(data):
# Implementation for getting a ticket
pass
def update_ticket(data):
# Implementation for updating a ticket
pass
def delete_ticket(data):
# Implementation for deleting a ticket
pass
# Wrap the functions in RunnableLambda
generate_runnable = RunnableLambda(generate_ticket)
create_runnable = RunnableLambda(create_ticket)
get_runnable = RunnableLambda(get_ticket)
update_runnable = RunnableLambda(update_ticket)
delete_runnable = RunnableLambda(delete_ticket)
# Create a RunnableParallel to run the tasks in parallel
parallel_runnable = RunnableParallel({
"generate": generate_runnable,
"create": create_runnable,
"get": get_runnable,
"update": update_runnable,
"delete": delete_runnable,
})
# Invoke the parallel runnable
result = parallel_runnable.invoke(data)
# Or asynchronously
result = await parallel_runnable.ainvoke(data) By using Additionally, you can take advantage of the from langchain.chains.base import Chain
class TicketChain(Chain):
def __init__(self):
super().__init__()
self.input_keys = ["data"]
self.output_keys = ["result"]
def _call(self, inputs, run_manager=None):
# Implement the sequence of operations here
data = inputs["data"]
# Example: generate, create, get, update, delete tickets
generate_ticket(data)
create_ticket(data)
ticket = get_ticket(data)
update_ticket(data)
delete_ticket(data)
return {"result": ticket}
async def _acall(self, inputs, run_manager=None):
# Implement the sequence of operations here
data = inputs["data"]
# Example: generate, create, get, update, delete tickets
generate_ticket(data)
create_ticket(data)
ticket = get_ticket(data)
update_ticket(data)
delete_ticket(data)
return {"result": ticket}
# Create an instance of the chain
ticket_chain = TicketChain()
# Invoke the chain
result = ticket_chain.invoke({"data": data})
# Or asynchronously
result = await ticket_chain.ainvoke({"data": data}) By structuring your tasks within a |
Beta Was this translation helpful? Give feedback.
-
In the provided example, it's impossible to tell whether issues are in user code, user database configuration, or langchain. You should use a tool to benchmark the code and identify where lagging issues come from. We have made some improvements that are available as of langchain 0.3 and should speed up some common use cases in terms of performance. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Checked other resources
Commit to Help
Example Code
Description
Creating tools using LCEL and Pydantic to perform the following tasks in Rally:
i. Generate and create a ticket
ii. Get details of an existing ticket
iii. Update an existing ticket
iv. Delete an existing ticket
While invoking the Runnable, we are facing lagging issues some occasion
System Info
Pydantic = 2.8.2
Langchain = 0.2.6
Beta Was this translation helpful? Give feedback.
All reactions