Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] 初始化数据库出现错误'NoneType' object has no attribute 'drop' #1206

Closed
Pickupppp opened this issue Aug 23, 2023 · 4 comments
Closed
Labels
bug Something isn't working

Comments

@Pickupppp
Copy link

问题描述 / Problem Description
执行 python init_database.py --recreate-vs 时,出现错误,错误如下:

Traceback (most recent call last):
  File "init_database.py", line 33, in <module>
    recreate_all_vs()
  File "/home/share/demo/master/Langchain-Chatchat/server/knowledge_base/migrate.py", line 114, in recreate_all_vs
    folder2db(kb_name, "recreate_vs", vs_type, embed_mode, **kwargs)
  File "/home/share/demo/master/Langchain-Chatchat/server/knowledge_base/migrate.py", line 39, in folder2db
    kb.clear_vs()
  File "/home/share/demo/master/Langchain-Chatchat/server/knowledge_base/kb_service/base.py", line 61, in clear_vs
    self.do_clear_vs()
  File "/home/share/demo/master/Langchain-Chatchat/server/knowledge_base/kb_service/milvus_kb_service.py", line 73, in do_clear_vs
    self.milvus.col.drop()
AttributeError: 'NoneType' object has no attribute 'drop'

复现问题的步骤 / Steps to Reproduce

  1. 修改 model_config.py 和 server_config.py ,这里选择默认数据库为 milvus
  2. 执行 python init_database.py --recreate-vs
  3. 问题出现

预期的结果 / Expected Result
预期结果应该是没有报错

实际结果 / Actual Result

Traceback (most recent call last):
  File "init_database.py", line 33, in <module>
    recreate_all_vs()
  File "/home/share/demo/master/Langchain-Chatchat/server/knowledge_base/migrate.py", line 114, in recreate_all_vs
    folder2db(kb_name, "recreate_vs", vs_type, embed_mode, **kwargs)
  File "/home/share/demo/master/Langchain-Chatchat/server/knowledge_base/migrate.py", line 39, in folder2db
    kb.clear_vs()
  File "/home/share/demo/master/Langchain-Chatchat/server/knowledge_base/kb_service/base.py", line 61, in clear_vs
    self.do_clear_vs()
  File "/home/share/demo/master/Langchain-Chatchat/server/knowledge_base/kb_service/milvus_kb_service.py", line 73, in do_clear_vs
    self.milvus.col.drop()
AttributeError: 'NoneType' object has no attribute 'drop'

环境信息 / Environment Information

  • langchain-ChatGLM 版本/commit 号:langchain版本:0.0.266. fastchat版本:0.2.24 commit d79676c
  • 是否使用 Docker 部署(是/否):否
  • 使用的模型(ChatGLM2-6B / Qwen-7B 等):ChatGLM-6B
  • 使用的 Embedding 模型(moka-ai/m3e-base 等):text2vec
  • 使用的向量库类型 (faiss / milvus / pg_vector 等): milvus
  • 操作系统及版本 / Operating system and version:Linux-5.15.0-79-generic-x86_64-with-glibc2.17.
  • Python 版本 / Python version:3.8.17
  • 其他相关环境信息 / Other relevant environment information: milvus 按照 docs/docker/milvus 下的docker-compose.yml 安装,pymilvus版本为2.1.3

附加信息 / Additional Information
添加与问题相关的任何其他信息 / Add any other information related to the issue.

@Pickupppp Pickupppp added the bug Something isn't working label Aug 23, 2023
@Pickupppp
Copy link
Author

后续使用的时候,添加文件会报错,错误信息:

add_doc() got an unexpected keyword argument 'not_refresh_vs_cache'

@liunux4odoo
Copy link
Collaborator

后续使用的时候,添加文件会报错,错误信息:

add_doc() got an unexpected keyword argument 'not_refresh_vs_cache'

感谢反馈,这是个bug,我们会尽快修复。

liunux4odoo pushed a commit that referenced this issue Aug 23, 2023
@Pickupppp
Copy link
Author

后来在如下环境下也试了一下
环境信息 / Environment Information

  • langchain-ChatGLM 版本/commit 号:langchain版本:0.0.266. fastchat版本:0.2.24 commit d79676c
  • 是否使用 Docker 部署(是/否):否
  • 使用的模型(ChatGLM2-6B / Qwen-7B 等):GPT3.5
  • 使用的 Embedding 模型(moka-ai/m3e-base 等):m3e-base
  • 使用的向量库类型 (faiss / milvus / pg_vector 等): milvus
  • 操作系统及版本 / Operating system and version:Windows-10-10.0.19045-SP0.
  • Python 版本 / Python version:3.8.17 (default, Jul 5 2023, 20:44:21) [MSC v.1916 64 bit (AMD64)]
  • 其他相关环境信息 / Other relevant environment information:milvus 按照 docs 中运行,pymilvus 版本为 2.1.3

初始化时候仍然会报

Traceback (most recent call last):
  File ".\init_database.py", line 33, in <module>
    recreate_all_vs()
  File "E:\Github\Langchain-Chatchat\server\knowledge_base\migrate.py", line 114, in recreate_all_vs
    folder2db(kb_name, "recreate_vs", vs_type, embed_mode, **kwargs)
  File "E:\Github\Langchain-Chatchat\server\knowledge_base\migrate.py", line 39, in folder2db
    kb.clear_vs()
  File "E:\Github\Langchain-Chatchat\server\knowledge_base\kb_service\base.py", line 61, in clear_vs
    self.do_clear_vs()
  File "E:\Github\Langchain-Chatchat\server\knowledge_base\kb_service\milvus_kb_service.py", line 73, in do_clear_vs
    self.milvus.col.drop()
AttributeError: 'NoneType' object has no attribute 'drop'

@Pickupppp
Copy link
Author

这个问题解决了,我查看代码发现如果milvus中指定名称的collection不存在,则在插入文档时会自动创建,所以测试 milvus_service文件中的测试代码没问题,但是如果是在初始化的时候,是先清除,再插入数据库,这时候milvus中collection还没建立(因为原本数据库中没有这个名字的collection,且未插入文档),解决方法如下:
milvus_kb_service.py 中加入判断

def do_clear_vs(self):
        if self.milvus.col:
            self.milvus.col.drop()

或者在 milvus_kb_service.py 中实现

def do_create_kb(self):
        pass

但是如果实现建库,原本就存在可能会报错(没有尝试过),用上述方法已经解决问题了。
最后感谢各位项目负责人开源一个好项目

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants