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

【BUG】使用API和WEBUI进行对话时出现“no such table: message”对应表不存在的问题

Open WilkinsLiu opened this issue 1 year ago • 6 comments

使用webui进行对话时出现 sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such table: message | [SQL: INSERT INTO message (id, conversation_id, chat_type, "query", response, meta_data, feedback_score, feedback_reason, create_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP) RETURNING create_time] | [parameters: ('e9f54b52ff324abf8bf407488d50f091', 'debcdd278ce64387b756840ffee2de3f', 'llm_chat', '你好', '', '{}', -1, '')] | (Background on this error at: https://sqlalche.me/e/20/e3q8) 模型使用的是chatglm2-6b,像是初始化之后没有建message表,导致查询向量数据库的时候报错

WilkinsLiu avatar Feb 25 '24 17:02 WilkinsLiu

🤖

你好呀 @WilkinsLiu,很高兴再次见到你!🛸

根据您提供的错误信息,这个问题可能是由于在初始化数据库时,message表没有被正确创建,导致在查询向量数据库时出现了错误。在Langchain-Chatchat中,create_tables()函数负责在数据库中创建所有的表。这个函数在reset_tables()函数中被调用,reset_tables()函数首先删除数据库中的所有表,然后重新创建它们。

如果在初始化后message表没有被创建,可能是由于以下原因:

  1. 在初始化过程中没有调用create_tables()函数。
  2. 在创建message表时出现了错误。这可能是由于MessageModel类的问题,该类用于定义message表。

要解决这个问题,您应该确保在初始化过程中调用了create_tables()函数。如果函数被调用了,但message表仍然没有被创建,您应该检查MessageModel类是否有任何错误。

这是相关的代码:

def create_tables():
    Base.metadata.create_all(bind=engine)

def reset_tables():
    Base.metadata.drop_all(bind=engine)
    create_tables()

在这段代码中,Base.metadata.create_all(bind=engine)负责创建数据库中的所有表。如果这行代码没有被执行,message表将不会被创建。

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

  1. [BUG]第一次提问显示API通信错误,第二次提问显示DuplicateWidgetID: There are multiple widgets with the same key=''. 通信错误 提出的解决方案是执行python init_database.py --create-tables或者完全重建知识库。

  2. [BUG] 服务运行成功,对话出错,无返回 | WARNING: Retrying langchain.chat_models.openai.acompletion_with_retry.._completion_with_retry in 4.0 seconds as it raised APIConnectionError: Error communicating with OpenAI. 提出的解决方案是修改server/llm_api.pyconfigs/model_config.py中的端口设置。

希望这些信息能帮助您解决问题。如果您有任何其他问题或需要进一步的帮助,请随时告诉我。

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

怎么感觉是你没有初始化模型和数据库呢

zRzRzRzRzRzRzR avatar Feb 26 '24 01:02 zRzRzRzRzRzRzR

@dosu-bot我反复执行了python init_database.py --recreate-vs 和 python init_database.py --create-tables 两个命令,其中python init_database.py --recreate-vs 可以看到重新加载了知识库数据,python init_database.py --create-tables 执行后没有任何反应,仍然出现no such table: message的错误,MessageModel这个源代码查看过但是没有修改过。python init_database.py --recreate-vs执行过程中出现 ERROR: RuntimeError: 从文件 samples/test_files/langchain-ChatGLM_closed.csv 加载文档时出错:Error loading F:\Github\Langchain-Chatchat\knowledge_base\samples\content\test_files/langchain-ChatGLM_closed.csv 2024-02-26 21:36:31,341 - utils.py[line:377] - ERROR: ImportError: 从文件 samples/test_files/langchain-ChatGLM_closed.jsonl 加载文档时出错:jq package not found, please install it with pip install jq 两个错误,无其他错误,完成后显示2024-02-26 21:39:18,127 - faiss_cache.py[line:38] - INFO: 已将向量库 ('samples', 'm3e-base') 保存到磁盘 总计用时: 0:05:23.308167 不知道是否跟上述两个Error有关,问题未得到解决

WilkinsLiu avatar Feb 26 '24 13:02 WilkinsLiu

🤖

Based on the information you've provided, it seems like the "message" table is not being created successfully in your database. This could be due to a variety of reasons, such as issues with the database connection or permissions, or a problem with the create_tables() function in the server.knowledge_base.migrate module.

The create_tables() function is implemented as follows:

def create_tables():
    Base.metadata.create_all(bind=engine)

This function uses SQLAlchemy's create_all method to create all tables in the database represented by the metadata. The bind=engine argument specifies the engine with which to bind this operation. You can find this in the server/knowledge_base/migrate.py file.

If the function is implemented correctly, then the issue might be with the database connection or permissions. Please ensure that your database is set up correctly and that the user has the necessary permissions to create tables.

Regarding the errors you encountered during the execution of python init_database.py --recreate-vs, they seem to be related to loading documents from the specified files. The first error indicates that there was a problem loading the document from the langchain-ChatGLM_closed.csv file, while the second error suggests that the jq package is not installed.

You can install the jq package by running pip install jq in your terminal. If you're still encountering these errors after installing the jq package, please provide the error messages for further assistance.

As for the similar issues in the Langchain-Chatchat repository, they suggest checking your network connection and trying to download the BAAI/bge-large-zh-v1.5 model locally from the Hugging Face model repository. You can then specify the local model path during the database initialization instead of fetching it online. You can find more details in these issues: 初始化不成功,请指导, python init_database.py --recreate-vs报错, and python init_database.py --recreate-vs执行出错.

If the issue persists after trying these solutions, please provide additional information such as your operating system, Python version, and whether all necessary dependencies are installed. This will help in diagnosing the problem and providing a more specific solution.

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

@dosu-bot我反复执行了python init_database.py --recreate-vs 和 python init_database.py --create-tables 两个命令,其中python init_database.py --recreate-vs 可以看到重新加载了知识库数据,python init_database.py --create-tables 执行后没有任何反应,仍然出现no such table: message的错误,MessageModel这个源代码查看过但是没有修改过。python init_database.py --recreate-vs执行过程中出现 ERROR: RuntimeError: 从文件 samples/test_files/langchain-ChatGLM_closed.csv 加载文档时出错:Error loading F:\Github\Langchain-Chatchat\knowledge_base\samples\content\test_files/langchain-ChatGLM_closed.csv 2024-02-26 21:36:31,341 - utils.py[line:377] - ERROR: ImportError: 从文件 samples/test_files/langchain-ChatGLM_closed.jsonl 加载文档时出错:jq package not found, please install it with pip install jq 两个错误,无其他错误,完成后显示2024-02-26 21:39:18,127 - faiss_cache.py[line:38] - INFO: 已将向量库 ('samples', 'm3e-base') 保存到磁盘 总计用时: 0:05:23.308167 不知道是否跟上述两个Error有关,问题未得到解决

你是先停止 startup.py,再 init_database,然后再 启动 startup 服务的吗?

liunux4odoo avatar Feb 29 '24 14:02 liunux4odoo

🤖

Based on the information you provided and the similar issues I found in the Langchain-Chatchat repository, it seems like the "no such table: message" error is due to the database schema not being correctly set up or missing entirely.

To resolve this issue, you should stop startup.py before running init_database.py and then restart the startup service. This is necessary because the init_database.py script initializes the database schema or migrates it to a new version, which is required for the application to run correctly. Stopping the startup.py script ensures that no processes are using the database, which could prevent schema modifications. After running init_database.py successfully, restarting the startup service will launch the application with the updated database schema, resolving the "no such table: message" error. You can refer to the startup.py for more details.

Regarding the errors encountered during the execution of python init_database.py --recreate-vs, the purpose of this command is to recreate the vector store. This option should be used if document files have been copied to the content folder, but the vector store has not been populated, or if the DEFAUL_VS_TYPE or EMBEDDING_MODEL has changed. You can refer to the init_database.py for more details.

For the errors you encountered, the first one seems to be a file loading error. Please ensure that the file F:\Github\Langchain-Chatchat\knowledge_base\samples\content\test_files/langchain-ChatGLM_closed.csv exists and is accessible. The second error indicates that the jq package is not found. You can install it by running pip install jq.

If the issue persists, please provide additional information such as your operating system, Python version, and whether all necessary dependencies are installed.

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

建议删除Langchain-Chatchat/knowledge_base下面的info.db文件及Langchain-Chatchat\knowledge_base\samples\vector_store文件夹,重新进行初始化python init_database.py --recreate-vs

skywolf123 avatar Mar 01 '24 13:03 skywolf123

这个问题已经被标记为 stale ,因为它已经超过 30 天没有任何活动。

github-actions[bot] avatar Mar 31 '24 21:03 github-actions[bot]