= """Answer the question based only on the following context:{context}Question: {question}"""prompt = ChatPromptTemplate.from_template(template)retrieval_chain = (    {"context": retriever, "question": RunnablePassthrough()}     | prompt     | model     | StrOutputParser())retrieval_chain.invoke("where did harrison work?")    'Harrison worked at Kensho.'Here the input to prompt is expected to be a map with keys "context" and "question". The user input is just the question. So we need to get the context using our retriever and passthrough the user input under the "question" key.Note that when composing a RunnableMap when another Runnable we don't even need to wrap our dictionary in the RunnableMap class ‚Äî¬†the type conversion is handled for us.Parallelism‚ÄãRunnableMaps are also useful for running independent processes in parallel, since each Runnable in the map is executed in parallel. For example, we can see our earlier joke_chain, poem_chain and map_chain all have about the same runtime, even though map_chain executes both of the other two.joke_chain.invoke({"topic": "bear"})    958 ms ¬± 402 ms per loop (mean ¬± std. dev. of 7 runs, 1 loop each)poem_chain.invoke({"topic": "bear"})    1.22 s ¬± 508 ms per loop (mean ¬± std. dev. of 7 runs, 1 loop each)map_chain.invoke({"topic": "bear"})    1.15 s ¬± 119 ms per loop (mean ¬± std. dev. of 7 runs, 1 loop each)PreviousRun arbitrary functionsNextRoute between multiple RunnablesManipulating outputs/inputsParallelismCommunityDiscordTwitterGitHubPythonJS/TSMoreHomepageBlogCopyright ¬© 2023 LangChain, Inc.
RunnableParallel (aka. RunnableMap) makes it easy to execute multiple Runnables in parallel, and to return the output of these Runnables as a map.
RunnableParallel (aka. RunnableMap) makes it easy to execute multiple Runnables in parallel, and to return the output of these Runnables as a map. ->: = """Answer the question based only on the following context:{context}Question: {question}"""prompt = ChatPromptTemplate.from_template(template)retrieval_chain = (    {"context": retriever, "question": RunnablePassthrough()}     | prompt     | model     | StrOutputParser())retrieval_chain.invoke("where did harrison work?")    'Harrison worked at Kensho.'Here the input to prompt is expected to be a map with keys "context" and "question". The user input is just the question. So we need to get the context using our retriever and passthrough the user input under the "question" key.Note that when composing a RunnableMap when another Runnable we don't even need to wrap our dictionary in the RunnableMap class ‚Äî¬†the type conversion is handled for us.Parallelism‚ÄãRunnableMaps are also useful for running independent processes in parallel, since each Runnable in the map is executed in parallel. For example, we can see our earlier joke_chain, poem_chain and map_chain all have about the same runtime, even though map_chain executes both of the other two.joke_chain.invoke({"topic": "bear"})    958 ms ¬± 402 ms per loop (mean ¬± std. dev. of 7 runs, 1 loop each)poem_chain.invoke({"topic": "bear"})    1.22 s ¬± 508 ms per loop (mean ¬± std. dev. of 7 runs, 1 loop each)map_chain.invoke({"topic": "bear"})    1.15 s ¬± 119 ms per loop (mean ¬± std. dev. of 7 runs, 1 loop each)PreviousRun arbitrary functionsNextRoute between multiple RunnablesManipulating outputs/inputsParallelismCommunityDiscordTwitterGitHubPythonJS/TSMoreHomepageBlogCopyright ¬© 2023 LangChain, Inc.