'metadata': {},                       'name': 'Docs',                       'start_time': '2023-10-05T12:52:36.935',                       'streamed_output_str': [],                       'tags': ['map:key:context', 'FAISS'],                       'type': 'retriever'}},     'streamed_output': ['',                         'H',                         'arrison',                         ' worked',                         ' at',                         ' Kens',                         'ho',                         '.',                         '']})Parallelism‚ÄãLet's take a look at how LangChain Expression Language support parallel requests as much as possible. For example, when using a RunnableParallel (often written as a dictionary) it executes each element in parallel.from langchain.schema.runnable import RunnableParallelchain1 = ChatPromptTemplate.from_template("tell me a joke about {topic}") | modelchain2 = ChatPromptTemplate.from_template("write a short (2 line) poem about {topic}") | modelcombined = RunnableParallel(joke=chain1, poem=chain2)chain1.invoke({"topic": "bears"})    CPU times: user 31.7 ms, sys: 8.59 ms, total: 40.3 ms    Wall time: 1.05 s    AIMessage(content="Why don't bears like fast food?\n\nBecause they can't catch it!", additional_kwargs={}, example=False)chain2.invoke({"topic": "bears"})    CPU times: user 42.9 ms, sys: 10.2 ms, total: 53 ms    Wall time: 1.93 s    AIMessage(content="In forest's embrace, bears roam free,\nSilent strength, nature's majesty.", additional_kwargs={}, example=False)combined.invoke({"topic": "bears"})    CPU times: user 96.3 ms, sys: 20.4 ms, total: 117 ms    Wall time: 1.1 s    {'joke': AIMessage(content="Why don't bears wear socks?\n\nBecause they have bear feet!", additional_kwargs={}, example=False),     'poem': AIMessage(content="In forest's embrace,\nMajestic bears leave their trace.", additional_kwargs={}, example=False)}PreviousLangChain Expression Language (LCEL)NextHow toInput SchemaOutput
In an effort to make it as easy as possible to create custom chains, we've implemented a "Runnable" protocol that most components implement. This is a standard interface with a few different methods, which makes it easy to define custom chains as well as making it possible to invoke them in a standard way. The standard interface exposed includes:
In an effort to make it as easy as possible to create custom chains, we've implemented a "Runnable" protocol that most components implement. This is a standard interface with a few different methods, which makes it easy to define custom chains as well as making it possible to invoke them in a standard way. The standard interface exposed includes: ->: 'metadata': {},                       'name': 'Docs',                       'start_time': '2023-10-05T12:52:36.935',                       'streamed_output_str': [],                       'tags': ['map:key:context', 'FAISS'],                       'type': 'retriever'}},     'streamed_output': ['',                         'H',                         'arrison',                         ' worked',                         ' at',                         ' Kens',                         'ho',                         '.',                         '']})Parallelism‚ÄãLet's take a look at how LangChain Expression Language support parallel requests as much as possible. For example, when using a RunnableParallel (often written as a dictionary) it executes each element in parallel.from langchain.schema.runnable import RunnableParallelchain1 = ChatPromptTemplate.from_template("tell me a joke about {topic}") | modelchain2 = ChatPromptTemplate.from_template("write a short (2 line) poem about {topic}") | modelcombined = RunnableParallel(joke=chain1, poem=chain2)chain1.invoke({"topic": "bears"})    CPU times: user 31.7 ms, sys: 8.59 ms, total: 40.3 ms    Wall time: 1.05 s    AIMessage(content="Why don't bears like fast food?\n\nBecause they can't catch it!", additional_kwargs={}, example=False)chain2.invoke({"topic": "bears"})    CPU times: user 42.9 ms, sys: 10.2 ms, total: 53 ms    Wall time: 1.93 s    AIMessage(content="In forest's embrace, bears roam free,\nSilent strength, nature's majesty.", additional_kwargs={}, example=False)combined.invoke({"topic": "bears"})    CPU times: user 96.3 ms, sys: 20.4 ms, total: 117 ms    Wall time: 1.1 s    {'joke': AIMessage(content="Why don't bears wear socks?\n\nBecause they have bear feet!", additional_kwargs={}, example=False),     'poem': AIMessage(content="In forest's embrace,\nMajestic bears leave their trace.", additional_kwargs={}, example=False)}PreviousLangChain Expression Language (LCEL)NextHow toInput SchemaOutput