Langchain-Chatchat icon indicating copy to clipboard operation
Langchain-Chatchat copied to clipboard

v0.2.10 版本添加到向量库的条目显示可能有问题

Open MarshalW opened this issue 1 year ago • 3 comments

问题描述 / Problem Description

v0.2.10 版本添加到向量库的条目显示可能有问题。

markdown 文件,上传和添加到知识库都没有报错。

可以正常在知识库问答模式下匹配结果。

问题出在显示上:

image

以前版本这里都是✅。

环境信息 / Environment Information

  • langchain-ChatGLM 版本/commit 号:(例如:v0.2.10)
  • 是否使用 Docker 部署(是/否):是
  • 使用的模型:ChatGLM3-6B
  • 使用的 Embedding 模型(moka-ai/m3e-base 等):bge-large-zh-v1.5 @ cuda
  • 使用的向量库类型 (faiss / milvus / pg_vector 等): faiss
  • 操作系统及版本 / Operating system and version: ubuntu 22.04.3
  • Python 版本 / Python version: 3.10.12
  • 其他相关环境信息 / Other relevant environment information:

MarshalW avatar Feb 04 '24 08:02 MarshalW

🤖

嘿,@MarshalW!又见面了,遇到新问题了吗?希望这次我们也能快乐地解决它!

这个问题可能是由于在将文档添加到 Elasticsearch 索引后,索引没有被刷新。在 Elasticsearch 中,通过索引、更新或删除操作所做的更改并不会立即对搜索可见。你需要刷新索引以使更改可见。

do_add_doc 方法中,调用 _load_es 方法添加文档后,你应该刷新索引。你可以通过在 es_client_python 对象上调用 refresh 方法来实现。

以下是更新后的 do_add_doc 方法:

def do_add_doc(self, docs: List[Document], **kwargs):
    '''向知识库添加文件'''
    print(f"server.knowledge_base.kb_service.es_kb_service.do_add_doc 输入的docs参数长度为:{len(docs)}")
    print("*"*100)
    self._load_es(docs=docs, embed_model=self.embeddings_model)
    # Refresh the index
    self.es_client_python.indices.refresh(index=self.index_name)
    print("写入数据成功.")
    print("*"*100)
    
    if self.es_client_python.indices.exists(index=self.index_name):
        file_path = docs[0].metadata.get("source")
        query = {
            "query": {
                "term": {
                    "metadata.source.keyword": file_path
                }
            }
        }
        search_results = self.es_client_python.search(body=query)
        if len(search_results["hits"]["hits"]) == 0:
            raise ValueError("召回元素个数为0")
    info_docs = [{"id":hit["_id"], "metadata": hit["_source"]["metadata"]} for hit in search_results["hits"]["hits"]]
    return info_docs

这应该可以使新添加的条目在知识库问答模式下立即可见。

源代码:

关于 v0.2.10 版本的 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.

dosubot[bot] avatar Feb 04 '24 08:02 dosubot[bot]

这个 issue 涉及的环境,没有用到 es。

MarshalW avatar Feb 04 '24 11:02 MarshalW

根据我的使用,注释掉:knowledge_base.py 中的202和203 这两行就好了。

zhengwanbo avatar Feb 07 '24 09:02 zhengwanbo

根据我的使用,注释掉:knowledge_base.py 中的202和203 这两行就好了。

确实能够解决,请问你有遇到doc无法向量的问题吗?docx向量没问题。由win11运行anaconda。

pakchoily avatar Feb 29 '24 02:02 pakchoily