chatchat-space / Langchain-Chatchat

Langchain-Chatchat(原Langchain-ChatGLM, Qwen 与 Llama 等)基于 Langchain 与 ChatGLM 等语言模型的 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
29.58k stars 5.19k forks source link

执行chatchat-kb -r报错 #4304

Open dingziyang2022 opened 1 week ago

dingziyang2022 commented 1 week ago

问题描述 / Problem Description 执行chatchat-kb -r报错

复现问题的步骤 / Steps to Reproduce 执行chatchat-kb -r

预期的结果 / Expected Result 初始化数据库成功

实际结果 / Actual Result (chatchat1) root@huiji-desktop:~# chatchat-kb -r 2024-06-24 18:13:38,288 - provider_configuration.py[line:241] - WARNING: get custom model schema failed, int() argument must be a string, a bytes-like object or a real number, not 'NoneType' 2024-06-24 18:13:38,358 uvicorn.error 3140827 INFO Started server process [3140827] 2024-06-24 18:13:38,358 uvicorn.error 3140827 INFO Waiting for application startup. 2024-06-24 18:13:38,359 uvicorn.error 3140827 INFO Application startup complete. 2024-06-24 18:13:38,360 uvicorn.error 3140827 INFO Uvicorn running on http://127.0.0.1:20000 (Press CTRL+C to quit) recreating all vector stores /home/huiji/miniconda3/envs/chatchat1/lib/python3.11/site-packages/langchain/_api/module_import.py:87: LangChainDeprecationWarning: Importing GuardrailsOutputParser from langchain.output_parsers is deprecated. Please replace the import with the following: from langchain_community.output_parsers.rail_parser import GuardrailsOutputParser warnings.warn( 2024-06-24 18:13:38,791 - utils.py[line:244] - ERROR: failed to create Embeddings for model: znbang/bge:large-zh-v1.5-f32. Traceback (most recent call last): File "/home/huiji/miniconda3/envs/chatchat1/lib/python3.11/site-packages/chatchat/server/utils.py", line 242, in get_Embeddings return LocalAIEmbeddings(params) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/huiji/miniconda3/envs/chatchat1/lib/python3.11/site-packages/pydantic/v1/main.py", line 341, in init raise validation_error pydantic.v1.error_wrappers.ValidationError: 1 validation error for LocalAIEmbeddings root Did not find openai_api_key, please add an environment variable OPENAI_API_KEY which contains it, or pass openai_api_key as a named parameter. (type=value_error) 2024-06-24 18:13:38,792 - faiss_cache.py[line:131] - ERROR: 'NoneType' object has no attribute 'embed_documents' Traceback (most recent call last): File "/home/huiji/miniconda3/envs/chatchat1/lib/python3.11/site-packages/chatchat/server/knowledge_base/kb_cache/faiss_cache.py", line 119, in load_vector_store vector_store = self.new_vector_store(kb_name=kb_name, embed_model=embed_model) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/huiji/miniconda3/envs/chatchat1/lib/python3.11/site-packages/chatchat/server/knowledge_base/kb_cache/faiss_cache.py", line 61, in new_vector_store vector_store = FAISS.from_documents([doc], embeddings, normalize_L2=True) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/huiji/miniconda3/envs/chatchat1/lib/python3.11/site-packages/langchain_core/vectorstores.py", line 550, in from_documents return cls.from_texts(texts, embedding, metadatas=metadatas, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/huiji/miniconda3/envs/chatchat1/lib/python3.11/site-packages/langchain_community/vectorstores/faiss.py", line 930, in from_texts embeddings = embedding.embed_documents(texts) ^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'NoneType' object has no attribute 'embed_documents' 2024-06-24 18:13:38,793 - init_database.py[line:171] - ERROR: 向量库 samples 加载失败。 Traceback (most recent call last): File "/home/huiji/miniconda3/envs/chatchat1/lib/python3.11/site-packages/chatchat/server/knowledge_base/kb_cache/faiss_cache.py", line 119, in load_vector_store vector_store = self.new_vector_store(kb_name=kb_name, embed_model=embed_model) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/huiji/miniconda3/envs/chatchat1/lib/python3.11/site-packages/chatchat/server/knowledge_base/kb_cache/faiss_cache.py", line 61, in new_vector_store vector_store = FAISS.from_documents([doc], embeddings, normalize_L2=True) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/huiji/miniconda3/envs/chatchat1/lib/python3.11/site-packages/langchain_core/vectorstores.py", line 550, in from_documents return cls.from_texts(texts, embedding, metadatas=metadatas, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/huiji/miniconda3/envs/chatchat1/lib/python3.11/site-packages/langchain_community/vectorstores/faiss.py", line 930, in from_texts embeddings = embedding.embed_documents(texts) ^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'NoneType' object has no attribute 'embed_documents'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/huiji/miniconda3/envs/chatchat1/lib/python3.11/site-packages/chatchat/init_database.py", line 156, in main folder2db(kb_names=args.kb_name, mode="recreate_vs", embed_model=args.embed_model) File "/home/huiji/miniconda3/envs/chatchat1/lib/python3.11/site-packages/chatchat/server/knowledge_base/migrate.py", line 130, in folder2db kb.create_kb() File "/home/huiji/miniconda3/envs/chatchat1/lib/python3.11/site-packages/chatchat/server/knowledge_base/kb_service/base.py", line 80, in create_kb self.do_create_kb() File "/home/huiji/miniconda3/envs/chatchat1/lib/python3.11/site-packages/chatchat/server/knowledge_base/kb_service/faiss_kb_service.py", line 51, in do_create_kb self.load_vector_store() File "/home/huiji/miniconda3/envs/chatchat1/lib/python3.11/site-packages/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 "/home/huiji/miniconda3/envs/chatchat1/lib/python3.11/site-packages/chatchat/server/knowledge_base/kb_cache/faiss_cache.py", line 132, in load_vector_store raise RuntimeError(f"向量库 {kb_name} 加载失败。") RuntimeError: 向量库 samples 加载失败。 2024-06-24 18:13:38,794 - init_database.py[line:172] - WARNING: Caught KeyboardInterrupt! Setting stop event... 2024-06-24 18:13:38,794 - init_database.py[line:176] - WARNING: Sending SIGKILL to

环境信息 / Environment Information (chatchat1) root@huiji-desktop:~# chatchat-config model --show { "DEFAULT_LLM_MODEL": "qwen:7b", "DEFAULT_EMBEDDING_MODEL": "znbang/bge:large-zh-v1.5-f32", "Agent_MODEL": null, "HISTORY_LEN": 3, "MAX_TOKENS": null, "TEMPERATURE": 0.7, "SUPPORT_AGENT_MODELS": [ "chatglm3-6b", "openai-api", "Qwen-14B-Chat", "Qwen-7B-Chat", "qwen-turbo" ], "LLM_MODEL_CONFIG": { "preprocess_model": { "glm4-chat": { "temperature": 0.05, "max_tokens": 4096, "history_len": 100, "prompt_name": "default", "callbacks": false } }

/home/huiji/miniconda3/envs/chatchat1/lib/python3.11/site-packages/chatchat/configs/model_providers.yaml

ollama: model_credential:

python:3.11.9

zmh2000829 commented 1 week ago

same error,是不是这里没有引入XinferenceEmbeddings导致的? image

zmh2000829 commented 1 week ago

我直接把/home/xxx/miniconda3/envs/RAG_new/lib/python3.10/site-packages/chatchat/server/utils.py 的get_Embeddings函数修改如下目前可以解决问题,可能要晚一些提pr from langchain_community.embeddings import OllamaEmbeddings, XinferenceEmbeddings from langchain_openai import OpenAIEmbeddings from chatchat.server.localai_embeddings import ( LocalAIEmbeddings, ) return XinferenceEmbeddings( server_url="http://127.0.0.1:9997", model_uid="my-bge-large-zh" )