langchain
langchain copied to clipboard
Get the source document info with result
System Info
ValueError: run not supported when there is not exactly one output key. Got ['result', 'source_documents'
]
Who can help?
No response
Information
- [X] The official example notebooks/scripts
- [ ] My own modified scripts
Related Components
- [X] LLMs/Chat Models
- [X] Embedding Models
- [X] Prompts / Prompt Templates / Prompt Selectors
- [ ] Output Parsers
- [X] Document Loaders
- [X] Vector Stores / Retrievers
- [X] Memory
- [X] Agents / Agent Executors
- [X] Tools / Toolkits
- [X] Chains
- [ ] Callbacks/Tracing
- [ ] Async
Reproduction
qa = RetrievalQA.from_chain_type( llm=OpenAI(), chain_type = "stuff", retriever=db.as_retriever(), return_source_documents=True )
agent = ZeroShotAgent(llm_chain=llm_chain, tools=tools, verbose=True)#, output_keys=['result','source_documents']) agent_chain = AgentExecutor.from_agent_and_tools( agent=agent, tools=tools, verbose=True, memory=memory)# return_intermediate_steps=True)#, output_keys=['result','source_documents']
#)
Expected behavior
Returns the answer and source doc as well
Same error message here when using a VectorDBQAWithSourcesChain as tool in combination with an agent.
Using the following workaround I got it to work (adding the lambda).
tool_data_source = Tool(
name = data_source_name,
func=lambda question: chain({"question": question}, return_only_outputs=False),
description="data set description",
return_direct=True, # Finish the chain directly after using this tool.
)
It returns the 'answer' 'question, and 'sources' nested in the 'output' key
faced same issue work with
result = chain(query)
result = chain.run(query)
throws error
It seems you have to call qa directly with qa({"query": query}) see https://python.langchain.com/docs/modules/chains/popular/vector_db_qa.
Hi, @Sadaf-Syeda. I'm Dosu, and I'm helping the LangChain team manage their backlog. I wanted to let you know that we are marking this issue as stale.
From what I understand, you opened this issue regarding a ValueError that occurs when running a script without exactly one output key. Vermaat suggested a workaround by adding a lambda function to the script, which resolved the issue for them. SDcodehub also faced the same issue and mentioned that using result = chain(query) or result = chain.run(query) throws an error. Paluchasz suggested calling qa({"query": query}) directly to resolve the issue.
Before we close this issue, we wanted to check if it is still relevant to the latest version of the LangChain repository. If it is, please let us know by commenting on the issue. Otherwise, feel free to close the issue yourself or it will be automatically closed in 7 days.
Thank you for your understanding.