有没有方法将向量嵌入集成到Langchain代理中?
我正在尝试使用Langchain的ReAct代理,并想把我的pinecone索引提供给它们作为上下文。不过,我找不到任何接口可以让我把使用ReAct链的语言模型(LLM)和我的向量嵌入一起提供。
在这里,我设置了语言模型并获取了我的向量嵌入。
llm = ChatOpenAI(temperature=0.1, model_name="gpt-4")
retriever = vector_store.as_retriever(search_type='similarity', search_kwargs={'k': k})
接下来,我开始我的ReAct链。
prompt = hub.pull("hwchase17/structured-chat-agent")
agent = create_structured_chat_agent(llm, tools, prompt)
agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)
result = agent_executor.invoke(
{
"input": question,
"chat_history": chat_history
}
)
在使用ReAct代理之前,我是这样使用向量嵌入的。
crc = ConversationalRetrievalChain.from_llm(llm, retriever)
result = crc.invoke({'question': systemPrompt, 'chat_history': chat_history})
chat_history.append((question, result['answer']))
有没有办法把这两种方法结合起来,让ReAct代理也能使用向量嵌入呢?
1 个回答
2
你可以把检索器指定为代理的一个工具。举个例子:
from langchain.tools.retriever import create_retriever_tool
retriever = vector_store.as_retriever(search_type='similarity', search_kwargs={'k': k})
retriever_tool = create_retriever_tool(
retriever,
"retriever_name",
"A detailed description of the retriever and when the agent should use it.",
)
tools = [retriever_tool]
agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)
参考资料: