如何使用Conversational Retrieval Agent通过参考来源获得最终答案

问题描述 投票:0回答:1

Langchain 发布了一个名为 Conversational Retrieval Agent 的新 Agent。我的问题是如何使用会话检索代理通过参考源获得最终答案,例如使用 create_qa_with_sources_chain 函数创建?

我尝试制作一个SuffDocumentChain作为工具,但是最终的答案没有得到用于回答的参考来源。如果我只是使用检索器作为工具,它将从向量数据库返回相关文档,我找不到可以告诉代理使用 AnswerWithSources 类作为最终输出格式的地方。

python agent langchain
1个回答
0
投票

如果您使用以下代理执行器

agent_executor = create_conversational_retrieval_agent(llm=llm, tools=tools, verbose=True)

然后,以下应该可以工作

retriever = vectorstore.as_retriever() # or whatever retriever you are using

query = "what is the definition of attention?"
result = agent_executor({"input": query})
# Get the answer to the query
print(result["output"])
# Get the sources
print(retriever.get_relevant_documents(query))
© www.soinside.com 2019 - 2024. All rights reserved.