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

[BUG] 简洁阐述问题 / Concise description of the issue

Open RaspberrySun opened this issue 1 year ago • 1 comments

问题描述 / Problem Description 用简洁明了的语言描述这个问题 / Describe the problem in a clear and concise manner.

复现问题的步骤 / Steps to Reproduce 部署执行 inti_database.py --recreate-vs

预期的结果 / Expected Result 描述应该出现的结果 / Describe the expected result.

实际结果 / Actual Result 描述实际发生的结果 / Describe the actual result.

环境信息 / Environment Information

  • langchain-ChatGLM 版本/commit 号:0.2.10
  • 是否使用 Docker 部署(是/否):否
  • 使用的模型(ChatGLM2-6B / Qwen-7B 等):ChatGLM-6B
  • 使用的 Embedding 模型(moka-ai/m3e-base 等):moka-ai
  • 使用的向量库类型 (faiss / milvus / pg_vector 等): faiss
  • 操作系统及版本 / Operating system and version: Ubuntu20.04
  • Python 版本 / Python version: 3.11.0
  • 其他相关环境信息 / Other relevant environment information:

附加信息 / Additional Information 添加与问题相关的任何其他信息 / Add any other information related to the issue. 2024-02-23 16:26:51,451 - embeddings_api.py[line:39] - ERROR: (MaxRetryError("HTTPSConnectionPool(host='huggingface.co', port=443): Max retries exceeded with url: /api/models/BAAI/bge-large-zh-v1.5 (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x7f1f440c3350>, 'Connection to huggingface.co timed out. (connect timeout=None)'))"), '(Request ID: 9a6415b5-5272-405b-9d62-3853e1023fcb)') AttributeError: 'NoneType' object has no attribute 'conjugate'

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/apps/svr/Langchain/Langchain-Chatchat/init_database.py", line 107, in folder2db(kb_names=args.kb_name, mode="recreate_vs", embed_model=args.embed_model) File "/apps/svr/Langchain/Langchain-Chatchat/server/knowledge_base/migrate.py", line 121, in folder2db kb.create_kb() File "/apps/svr/Langchain/Langchain-Chatchat/server/knowledge_base/kb_service/base.py", line 81, in create_kb self.do_create_kb() File "/apps/svr/Langchain/Langchain-Chatchat/server/knowledge_base/kb_service/faiss_kb_service.py", line 51, in do_create_kb self.load_vector_store() File "/apps/svr/Langchain/Langchain-Chatchat/server/knowledge_base/kb_service/faiss_kb_service.py", line 28, in load_vector_store return kb_faiss_pool.load_vector_store(kb_name=self.kb_name, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/apps/svr/Langchain/Langchain-Chatchat/server/knowledge_base/kb_cache/faiss_cache.py", line 102, in load_vector_store vector_store = self.new_vector_store(embed_model=embed_model, embed_device=embed_device) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/apps/svr/Langchain/Langchain-Chatchat/server/knowledge_base/kb_cache/faiss_cache.py", line 60, in new_vector_store vector_store = FAISS.from_documents([doc], embeddings, normalize_L2=True,distance_strategy="METRIC_INNER_PRODUCT") ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/apps/svr/Langchain/lib/python3.11/site-packages/langchain_core/vectorstores.py", line 508, in from_documents return cls.from_texts(texts, embedding, metadatas=metadatas, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/apps/svr/Langchain/lib/python3.11/site-packages/langchain_community/vectorstores/faiss.py", line 965, in from_texts embeddings = embedding.embed_documents(texts) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/apps/svr/Langchain/Langchain-Chatchat/server/knowledge_base/kb_service/base.py", line 425, in embed_documents return normalize(embeddings).tolist() ^^^^^^^^^^^^^^^^^^^^^ File "/apps/svr/Langchain/Langchain-Chatchat/server/knowledge_base/kb_service/base.py", line 37, in normalize norm = np.linalg.norm(embeddings, axis=1) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "<array_function internals>", line 200, in norm File "/apps/svr/Langchain/lib/python3.11/site-packages/numpy/linalg/linalg.py", line 2541, in norm s = (x.conj() * x).real ^^^^^^^^ TypeError: loop of ufunc does not support argument 0 of type NoneType which has no callable conjugate method

RaspberrySun avatar Feb 23 '24 08:02 RaspberrySun

🤖

嗨,@RaspberrySun!很高兴再次看到你。希望你一切都好!

根据您提供的错误信息,问题可能出现在 normalize 函数中,该函数在 base.py 文件中定义。这个函数的作用是对文档的嵌入进行归一化,它接收一个浮点数的列表(代表文档的嵌入)作为输入,并返回一个相同形状的 numpy 数组,其中每个嵌入向量都被归一化为单位范数。

这个错误信息表明 normalize 函数接收到了一个 NoneType 参数,这是不被支持的。这可能是因为在调用 normalize 函数之前,embeddings 参数没有正确地初始化或赋值。

我建议您检查调用 normalize 函数的代码,确保在将 embeddings 参数传入函数之前,它已经被正确地初始化并赋值为一个浮点数的列表。

此外,我在 Langchain-Chatchat 仓库中找到了几个类似的已解决问题,可能对您有所帮助:

  1. [BUG] 3. 初始化知识库和配置文件 报错 python init_database.py --recreate-vs
  2. 初始化不成功,请指导
  3. 创建知识库出错

这些问题的解决方案包括确保 sentence-transformers 包正确安装,手动下载 bge-large-zh 模型,修改 model_config.py 文件以更新 EMBEDDING_MODELMODEL_PATH,以及检查网络连接等。

如果问题仍然存在,可能需要更多的上下文信息来提供更好的解决方案。

Sources

About Dosu

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 23 '24 08:02 dosubot[bot]

两种解决方案,一个是降级langchain- community,严格按照req装,另一个检查自己文件有没有全,大概率问题是后者,模型文件少了

zRzRzRzRzRzRzR avatar Feb 24 '24 02:02 zRzRzRzRzRzRzR