chatchat-space / Langchain-Chatchat

Langchain-Chatchat(原Langchain-ChatGLM)基于 Langchain 与 ChatGLM, Qwen 与 Llama 等语言模型的 RAG 与 Agent 应用 | Langchain-Chatchat (formerly langchain-ChatGLM), local knowledge based LLM (like ChatGLM, Qwen and Llama) RAG and Agent app with langchain
Apache License 2.0
30.81k stars 5.39k forks source link

使用知识库问答,为什么检索出来的前几条知识库都是重复的呢? #2922

Closed phphappy closed 6 months ago

phphappy commented 6 months ago

问题描述 / Problem Description 使用知识库问答,为什么检索出来的前几条知识库都是重复的呢?

复现问题的步骤 / Steps to Reproduce 使用知识库问答模型,输入知识库能够匹配到的问题 预期的结果 / Expected Result 知识库匹配结果不同 实际结果 / Actual Result 知识库匹配出来的前3条记录都是重复的

dosubot[bot] commented 6 months ago

🤖

你好,@phphappy!很高兴再次遇见你。👾

您好,phphappy。这个问题可能是由于在处理搜索结果时没有检查和删除重复结果的机制。在Langchain-Chatchat的代码中,应用程序使用了三个不同的搜索引擎:Bing,DuckDuckGo和Metaphor。每个搜索引擎都会返回一系列结果,然后这些结果被处理并转换为文档。

如果同一结果出现在多个搜索引擎的顶部结果中,它将在最终的文档列表中多次出现。

要解决此问题,您可以在从所有搜索引擎收集结果后添加一个步骤来删除重复项。这可以通过比较结果的'link'或'title'字段,并删除任何重复项来完成。以下是一个简单的方法:

def remove_duplicates(docs):
    seen = set()
    unique_docs = []
    for doc in docs:
        link = doc['link']
        if link not in seen:
            unique_docs.append(doc)
            seen.add(link)
    return unique_docs

您可以在lookup_search_engine函数返回最终的文档列表之前调用此函数:

def lookup_search_engine(...):
    ...
    docs = search_result2docs(results)
    docs = remove_duplicates(docs)
    return docs

请注意,这是一个简单的解决方案,如果不同搜索引擎的同一结果的URL或标题有轻微的差异,可能无法完美工作。更强大的解决方案将涉及使用更复杂的方法来比较结果并识别重复项。

另外,我还查看了Langchain-Chatchat代码库中的已知问题或错误,但没有找到与您描述的问题直接相关的问题。如果您能提供更多关于您遇到的问题的信息,我可能能提供更准确的答案。

希望这个答案对您有所帮助。如果您有任何其他问题或需要进一步的澄清,请随时告诉我。

Sources


This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

phphappy commented 6 months ago

1707032000639 我的疑问是知识库中检索出来的三条记录是一样的

zhengwanbo commented 6 months ago

不知道你使用的是哪个向量库,你需要注意在同一个知识库中,上传相同的文件的时候,之前的是否在向量库中真正删除了。如果没有真正删除,查找出来的就会多条相同的数据。

zRzRzRzRzRzRzR commented 6 months ago

同一个文件里面多个相似的文本就算多个答案

sevenandseven commented 4 months ago
docs = remove_duplicates(docs)

你好,请问在哪里设置搜索引擎的类型呢?看着好像直接默认设置为bing是吗?