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

修复使用Milvus数据库时上传知识库文件报错的问题 #3155

Merged
merged 2 commits into from
Mar 6, 2024

Conversation

hollowdjj
Copy link
Contributor

@hollowdjj hollowdjj commented Mar 3, 2024

当使用Milvus数据库时,上传知识库文件报错。

image

前台报错信息如上所示,后台报错信息如下所示:

`INFO:     127.0.0.1:41796 - "POST /knowledge_base/search_docs HTTP/1.1" 500 Internal Server Error
ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "/opt/anaconda3/envs/Chat-v0.2.10/lib/python3.11/site-packages/fastapi/encoders.py", line 322, in jsonable_encoder
    data = dict(obj)
           ^^^^^^^^^
TypeError: 'numpy.float32' object is not iterable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/anaconda3/envs/Chat-v0.2.10/lib/python3.11/site-packages/fastapi/encoders.py", line 327, in jsonable_encoder
    data = vars(obj)
           ^^^^^^^^^
TypeError: vars() argument must have __dict__ attribute

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

Traceback (most recent call last):
  File "/opt/anaconda3/envs/Chat-v0.2.10/lib/python3.11/site-packages/uvicorn/protocols/http/httptools_impl.py", line 419, in run_asgi
    result = await app(  # type: ignore[func-returns-value]
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/anaconda3/envs/Chat-v0.2.10/lib/python3.11/site-packages/uvicorn/middleware/proxy_headers.py", line 84, in __call__
    return await self.app(scope, receive, send)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/anaconda3/envs/Chat-v0.2.10/lib/python3.11/site-packages/fastapi/applications.py", line 1054, in __call__
    await super().__call__(scope, receive, send)
  File "/opt/anaconda3/envs/Chat-v0.2.10/lib/python3.11/site-packages/starlette/applications.py", line 119, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/opt/anaconda3/envs/Chat-v0.2.10/lib/python3.11/site-packages/starlette/middleware/errors.py", line 186, in __call__
    raise exc
  File "/opt/anaconda3/envs/Chat-v0.2.10/lib/python3.11/site-packages/starlette/middleware/errors.py", line 164, in __call__
    await self.app(scope, receive, _send)
  File "/opt/anaconda3/envs/Chat-v0.2.10/lib/python3.11/site-packages/starlette/middleware/exceptions.py", line 62, in __call__
    await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
  File "/opt/anaconda3/envs/Chat-v0.2.10/lib/python3.11/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app
    raise exc
  File "/opt/anaconda3/envs/Chat-v0.2.10/lib/python3.11/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    await app(scope, receive, sender)
  File "/opt/anaconda3/envs/Chat-v0.2.10/lib/python3.11/site-packages/starlette/routing.py", line 762, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/opt/anaconda3/envs/Chat-v0.2.10/lib/python3.11/site-packages/starlette/routing.py", line 782, in app
    await route.handle(scope, receive, send)
  File "/opt/anaconda3/envs/Chat-v0.2.10/lib/python3.11/site-packages/starlette/routing.py", line 297, in handle
    await self.app(scope, receive, send)
  File "/opt/anaconda3/envs/Chat-v0.2.10/lib/python3.11/site-packages/starlette/routing.py", line 77, in app
    await wrap_app_handling_exceptions(app, request)(scope, receive, send)
  File "/opt/anaconda3/envs/Chat-v0.2.10/lib/python3.11/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app
    raise exc
  File "/opt/anaconda3/envs/Chat-v0.2.10/lib/python3.11/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    await app(scope, receive, sender)
  File "/opt/anaconda3/envs/Chat-v0.2.10/lib/python3.11/site-packages/starlette/routing.py", line 72, in app
    response = await func(request)
               ^^^^^^^^^^^^^^^^^^^
  File "/opt/anaconda3/envs/Chat-v0.2.10/lib/python3.11/site-packages/fastapi/routing.py", line 315, in app
    content = await serialize_response(
              ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/anaconda3/envs/Chat-v0.2.10/lib/python3.11/site-packages/fastapi/routing.py", line 170, in serialize_response
    return jsonable_encoder(
           ^^^^^^^^^^^^^^^^^
  File "/opt/anaconda3/envs/Chat-v0.2.10/lib/python3.11/site-packages/fastapi/encoders.py", line 301, in jsonable_encoder
    jsonable_encoder(
  File "/opt/anaconda3/envs/Chat-v0.2.10/lib/python3.11/site-packages/fastapi/encoders.py", line 235, in jsonable_encoder
    return jsonable_encoder(
           ^^^^^^^^^^^^^^^^^
  File "/opt/anaconda3/envs/Chat-v0.2.10/lib/python3.11/site-packages/fastapi/encoders.py", line 287, in jsonable_encoder
    encoded_value = jsonable_encoder(
                    ^^^^^^^^^^^^^^^^^
  File "/opt/anaconda3/envs/Chat-v0.2.10/lib/python3.11/site-packages/fastapi/encoders.py", line 287, in jsonable_encoder
    encoded_value = jsonable_encoder(
                    ^^^^^^^^^^^^^^^^^
  File "/opt/anaconda3/envs/Chat-v0.2.10/lib/python3.11/site-packages/fastapi/encoders.py", line 301, in jsonable_encoder
    jsonable_encoder(
  File "/opt/anaconda3/envs/Chat-v0.2.10/lib/python3.11/site-packages/fastapi/encoders.py", line 330, in jsonable_encoder
    raise ValueError(errors) from e
ValueError: [TypeError("'numpy.float32' object is not iterable"), TypeError('vars() argument must have __dict__ attribute')]
2024-03-03 23:50:32,003 - _client.py[line:1027] - INFO: HTTP Request: POST http://127.0.0.1:7861/knowledge_base/search_docs "HTTP/1.1 500 Internal Server Error"
2024-03-03 23:50:32.004 Uncaught app exception
Traceback (most recent call last):
  File "/opt/anaconda3/envs/Chat-v0.2.10/lib/python3.11/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 535, in _run_script
    exec(code, module.__dict__)
  File "/opt/Langchain-Chatchat/webui.py", line 64, in <module>
    pages[selected_page]["func"](api=api, is_lite=is_lite)
  File "/opt/Langchain-Chatchat/webui_pages/knowledge_base/knowledge_base.py", line 328, in knowledge_base_page
    data = [
           ^
  File "/opt/Langchain-Chatchat/webui_pages/knowledge_base/knowledge_base.py", line 329, in <listcomp>
    {"seq": i + 1, "id": x["id"], "page_content": x["page_content"], "source": x["metadata"].get("source"),
                         ~^^^^^^
TypeError: string indices must be integers, not 'str'`

错误的地方在server/knowage_base/kb_doc_api.py的search_docs函数中
image
DocumentWithVSId对象的metadata中包含有向量化后的数据,导致报错:
image

@dosubot dosubot bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Mar 3, 2024
@3cdota
Copy link

3cdota commented Mar 4, 2024

我也遇到了同样的问题

@liunux4odoo liunux4odoo merged commit e48f4a2 into chatchat-space:master Mar 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size:XS This PR changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants