LLamaIndex-ReACT 代理自言自语并产生幻觉

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

我刚开始创建自定义 ReACT 代理来使用 RAG 技术查询我的数据。 事实证明,我本地运行的 LLama2 7B 模型(使用 Ollama)可以很好地处理有关我的数据的问题(我将检索器添加为查询引擎工具),但对于随意的对话,它最终还是会调用该工具并产生幻觉。 为了克服这个问题,我为休闲对话创建了一个单独的索引,并将检索器添加为另一个查询引擎工具。正如预期的那样,当我开始随意对话时,它最终会调用指定的工具,但后来通过自言自语而产生幻觉(至少我是这么认为的)。 是因为我使用的是轻量级本地模型,还是我必须改变处理它的方式? 这是我的代码。由于如果我开始休闲对话,ReACT 会调用工具,因此我必须在 pinecone 数据库中添加另一个休闲对话索引。我用的数据,也附上。

我希望模型使用其已经预先内置的知识,例如休闲对话并基于此进行回复,而不是依赖于工具,即使它确实依赖于该工具,它也不会使用我提供的信息。这就好像代理正在使用检索到的信息作为其内部思维过程的一部分,并错误地将其视为新输入而不是形成最终响应。您可以查看所附图像以更清楚地了解。代理能够响应“你好”使用该工具,但当我问“你好吗?”时,它产生了幻觉

index_name = "custom-data"
pinecone_index = pc.Index(index_name)
pinecone_index_2 = pc.Index("casualconversation")

vector_store = PineconeVectorStore(pinecone_index=pinecone_index)
vector_store_2 = PineconeVectorStore(pinecone_index=pinecone_index_2)

vector_index = VectorStoreIndex.from_vector_store(vector_store=vector_store)
vector_index_2 = VectorStoreIndex.from_vector_store(vector_store=vector_store_2)


llm = Ollama(model="llama3", request_timeout=1000000)
retriever = VectorIndexRetriever(index=vector_index, similarity_top_k=5)
retriever_2 = VectorIndexRetriever(index=vector_index_2, similarity_top_k=5)


tools = [
    QueryEngineTool(
        query_engine=RetrieverQueryEngine(retriever=retriever),
        metadata=ToolMetadata(
            name="phc_data",
            description="this has data for the company XYZ ",
        ),
    ),
    QueryEngineTool(
        query_engine=RetrieverQueryEngine(retriever=retriever_2),
        metadata=ToolMetadata(
            name="casualconversation",
            description="Use this whenever the user asks a casual question or for casual conversations",
        ),
    ),
]
agent = ReActAgent.from_tools(
    tools=tools,
    llm=llm,
    verbose=True,
    # context=context
)



response = agent.chat("Hi")
print(str(response))
response=agent.chat("How are you doing?")
print(str(response))

代码结果 休闲车队数据

large-language-model llama-index ollama pinecone
1个回答
0
投票

我也有同样的问题。 我通过设置下面的上下文解决了这个问题。

context = "If the user asks a question the you already know the answer to OR the user is making idle banter, just respond without calling any tools."

agent = ReActAgent.from_tools(
    tools=tools,
    llm=llm,
    verbose=True,
    context=context
)
© www.soinside.com 2019 - 2024. All rights reserved.