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

ERROR: RemoteProtocolError: API通信遇到错误:peer closed connection without sending complete message body (incomplete chunked read)

Open ICYHunterr opened this issue 10 months ago • 4 comments

image 使用知识库问答的时候,匹配知识条数比较大的时候如5,可能无法匹配到,然后模型能自己回答。 当匹配知识条数比较小的时候如1,可能匹配到了,但是却报错了: `ERROR: Exception in ASGI application Traceback (most recent call last): File "/usr/local/lib/python3.11/dist-packages/sse_starlette/sse.py", line 269, in call await wrap(partial(self.listen_for_disconnect, receive)) File "/usr/local/lib/python3.11/dist-packages/sse_starlette/sse.py", line 258, in wrap await func() File "/usr/local/lib/python3.11/dist-packages/sse_starlette/sse.py", line 215, in listen_for_disconnect message = await receive() ^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/dist-packages/uvicorn/protocols/http/httptools_impl.py", line 568, in receive await self.message_event.wait() File "/usr/lib/python3.11/asyncio/locks.py", line 213, in wait await fut asyncio.exceptions.CancelledError: Cancelled by cancel scope 7f3bd8746f10

During handling of the above exception, another exception occurred:

  • Exception Group Traceback (most recent call last): | File "/usr/local/lib/python3.11/dist-packages/uvicorn/protocols/http/httptools_impl.py", line 411, in run_asgi | result = await app( # type: ignore[func-returns-value] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | File "/usr/local/lib/python3.11/dist-packages/uvicorn/middleware/proxy_headers.py", line 69, in call | return await self.app(scope, receive, send) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | File "/usr/local/lib/python3.11/dist-packages/fastapi/applications.py", line 1054, in call | await super().call(scope, receive, send) | File "/usr/local/lib/python3.11/dist-packages/starlette/applications.py", line 119, in call | await self.middleware_stack(scope, receive, send) | File "/usr/local/lib/python3.11/dist-packages/starlette/middleware/errors.py", line 186, in call | raise exc | File "/usr/local/lib/python3.11/dist-packages/starlette/middleware/errors.py", line 164, in call | await self.app(scope, receive, _send) | File "/usr/local/lib/python3.11/dist-packages/starlette/middleware/exceptions.py", line 62, in call | await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send) | File "/usr/local/lib/python3.11/dist-packages/starlette/_exception_handler.py", line 64, in wrapped_app | raise exc | File "/usr/local/lib/python3.11/dist-packages/starlette/_exception_handler.py", line 53, in wrapped_app | await app(scope, receive, sender) | File "/usr/local/lib/python3.11/dist-packages/starlette/routing.py", line 762, in call | await self.middleware_stack(scope, receive, send) | File "/usr/local/lib/python3.11/dist-packages/starlette/routing.py", line 782, in app | await route.handle(scope, receive, send) | File "/usr/local/lib/python3.11/dist-packages/starlette/routing.py", line 297, in handle | await self.app(scope, receive, send) | File "/usr/local/lib/python3.11/dist-packages/starlette/routing.py", line 77, in app | await wrap_app_handling_exceptions(app, request)(scope, receive, send) | File "/usr/local/lib/python3.11/dist-packages/starlette/_exception_handler.py", line 64, in wrapped_app | raise exc | File "/usr/local/lib/python3.11/dist-packages/starlette/_exception_handler.py", line 53, in wrapped_app | await app(scope, receive, sender) | File "/usr/local/lib/python3.11/dist-packages/starlette/routing.py", line 75, in app | await response(scope, receive, send) | File "/usr/local/lib/python3.11/dist-packages/sse_starlette/sse.py", line 255, in call | async with anyio.create_task_group() as task_group: | File "/usr/local/lib/python3.11/dist-packages/anyio/_backends/_asyncio.py", line 678, in aexit | raise BaseExceptionGroup( | ExceptionGroup: unhandled errors in a TaskGroup (1 sub-exception) +-+---------------- 1 ---------------- | Traceback (most recent call last): | File "/usr/local/lib/python3.11/dist-packages/sse_starlette/sse.py", line 258, in wrap | await func() | File "/usr/local/lib/python3.11/dist-packages/sse_starlette/sse.py", line 245, in stream_response | async for data in self.body_iterator: | File "/T20200133/Langchain-Chatchat/server/chat/knowledge_base_chat.py", line 81, in knowledge_base_chat_iterator | docs = await run_in_threadpool(search_docs, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | File "/usr/local/lib/python3.11/dist-packages/starlette/concurrency.py", line 40, in run_in_threadpool | return await anyio.to_thread.run_sync(func, *args) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | File "/usr/local/lib/python3.11/dist-packages/anyio/to_thread.py", line 56, in run_sync | return await get_async_backend().run_sync_in_worker_thread( | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | File "/usr/local/lib/python3.11/dist-packages/anyio/_backends/_asyncio.py", line 2144, in run_sync_in_worker_thread | return await future | ^^^^^^^^^^^^ | File "/usr/local/lib/python3.11/dist-packages/anyio/_backends/_asyncio.py", line 851, in run | result = context.run(func, *args) | ^^^^^^^^^^^^^^^^^^^^^^^^ | File "/T20200133/Langchain-Chatchat/server/knowledge_base/kb_doc_api.py", line 38, in search_docs | docs = kb.search_docs(query, top_k, score_threshold) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | File "/T20200133/Langchain-Chatchat/server/knowledge_base/kb_service/base.py", line 182, in search_docs | docs = self.do_search(query, top_k, score_threshold) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | File "/T20200133/Langchain-Chatchat/server/knowledge_base/kb_service/faiss_kb_service.py", line 68, in do_search | docs = vs.similarity_search_with_score_by_vector(embeddings, k=top_k, score_threshold=score_threshold) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | File "/usr/local/lib/python3.11/dist-packages/langchain_community/vectorstores/faiss.py", line 332, in similarity_search_with_score_by_vector | _id = self.index_to_docstore_id[i] | ~~~~~~~~~~~~~~~~~~~~~~~~~^^^ | KeyError: 0 +------------------------------------ 2024-04-16 14:07:12,813 - utils.py[line:197] - ERROR: RemoteProtocolError: API通信遇到错误:peer closed connection without sending complete message body (incomplete chunked read) `

ICYHunterr avatar Apr 16 '24 14:04 ICYHunterr

The errors you're encountering, RemoteProtocolError and KeyError, suggest issues with HTTP communication and data access in your application. Here's a focused approach to address them:

  1. RemoteProtocolError: This error is often linked to HTTP communication problems, such as incorrect handling of headers or premature connection closures. Since your application uses Server-Sent Events (SSE) and is built with sse_starlette, uvicorn, and fastapi, ensure that:

    • Your SSE endpoint is correctly setting the necessary headers (Content-Type: text/event-stream) and adheres to SSE protocol standards.
    • Uvicorn server settings are optimized for long-lived connections, which might involve adjusting timeout settings.
    • Any middleware or proxies support the requirements of SSE, as they can interfere with connection handling.
  2. KeyError: This error occurs when trying to access a non-existent dictionary key. It's crucial in your application, especially when dealing with dynamic data:

    • Use dict.get() for safer dictionary access, providing a default value if the key is missing.
    • Validate data structures before accessing specific keys to prevent unexpected errors.
    • In the context of the KeyError with self.index_to_docstore_id[i], ensure that the key exists in the dictionary before accessing it. This can prevent the error from occurring.

Implementing comprehensive logging and robust error handling can significantly help in diagnosing and mitigating these issues. For network-related errors, consider retries with exponential backoff. For data-related errors, ensure your application can handle missing or unexpected data gracefully.

If you need further assistance, providing more details about the code, especially around the error occurrences, would be helpful.

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 Apr 16 '24 14:04 dosubot[bot]

同遇到这个错误,不过我是LLM问答的时候都会报这个错。我看有的issue说这个问题是显存不够,能问问你的配置吗?

cjrzs avatar Apr 23 '24 10:04 cjrzs

同遇到这个错误,不过我是LLM问答的时候都会报这个错。我看有的issue说这个问题是显存不够,能问问你的配置吗?

我是A800 80G跑的,显存看了只用了12G左右,直接拉的2.10的镜像,不知道什么问题,刚刚发现初始化知识库好像有问题,出现Segmentation fault (core dumped)

ICYHunterr avatar Apr 23 '24 11:04 ICYHunterr

同遇到这个错误,不过我是LLM问答的时候都会报这个错。我看有的issue说这个问题是显存不够,能问问你的配置吗?

已经大概解决了,把原本知识库里的文件都删掉,然后用一个小的csv文件进去,就可以了

ICYHunterr avatar Apr 23 '24 15:04 ICYHunterr