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

I have the same issue,The problem seems due to the ContextualCompressionRetriever,It outputs some info cannot be serialized. #726

Open
hpx502766238 opened this issue Aug 8, 2024 · 1 comment

Comments

@hpx502766238
Copy link

          @maximeperrindev it looks like either the input or output (probably output) of one of the chains is a numpy array. If you want to output it and are sending the data over a web-server, you need to provide a way to encode the data as json.

The easiest thing to do is add another runnable lambda that takes the numpy and outputs a string representation of the numpy that can be sent over the wire (i.e., search online for ways to encode JSON)

Originally posted by @eyurtsev in langchain-ai/langchain#17875 (comment)

@hpx502766238
Copy link
Author

INFO: 127.0.0.1:50194 - "POST /stream_log HTTP/1.1" 200 OK
ERROR: Exception in ASGI application
Traceback (most recent call last):
File "/mnt/vdb1/app/venv/lib/python3.10/site-packages/sse_starlette/sse.py", line 269, in call
await wrap(partial(self.listen_for_disconnect, receive))
File "/mnt/vdb1/app/venv/lib/python3.10/site-packages/sse_starlette/sse.py", line 258, in wrap
await func()
File "/mnt/vdb1/app/venv/lib/python3.10/site-packages/sse_starlette/sse.py", line 215, in listen_for_disconnect
message = await receive()
File "/mnt/vdb1/app/venv/lib/python3.10/site-packages/uvicorn/protocols/http/httptools_impl.py", line 553, in receive
await self.message_event.wait()
File "/usr/lib/python3.10/asyncio/locks.py", line 214, in wait
await fut
asyncio.exceptions.CancelledError: Cancelled by cancel scope 7f0a502eba60

During handling of the above exception, another exception occurred:

  • Exception Group Traceback (most recent call last):
    | File "/mnt/vdb1/app/venv/lib/python3.10/site-packages/uvicorn/protocols/http/httptools_impl.py", line 399, in run_asgi
    | result = await app( # type: ignore[func-returns-value]
    | File "/mnt/vdb1/app/venv/lib/python3.10/site-packages/uvicorn/middleware/proxy_headers.py", line 70, in call
    | return await self.app(scope, receive, send)
    | File "/mnt/vdb1/app/venv/lib/python3.10/site-packages/fastapi/applications.py", line 1054, in call
    | await super().call(scope, receive, send)
    | File "/mnt/vdb1/app/venv/lib/python3.10/site-packages/starlette/applications.py", line 123, in call
    | await self.middleware_stack(scope, receive, send)
    | File "/mnt/vdb1/app/venv/lib/python3.10/site-packages/starlette/middleware/errors.py", line 186, in call
    | raise exc
    | File "/mnt/vdb1/app/venv/lib/python3.10/site-packages/starlette/middleware/errors.py", line 164, in call
    | await self.app(scope, receive, _send)
    | File "/mnt/vdb1/app/venv/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 65, in call
    | await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
    | File "/mnt/vdb1/app/venv/lib/python3.10/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app
    | raise exc
    | File "/mnt/vdb1/app/venv/lib/python3.10/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    | await app(scope, receive, sender)
    | File "/mnt/vdb1/app/venv/lib/python3.10/site-packages/starlette/routing.py", line 756, in call
    | await self.middleware_stack(scope, receive, send)
    | File "/mnt/vdb1/app/venv/lib/python3.10/site-packages/starlette/routing.py", line 776, in app
    | await route.handle(scope, receive, send)
    | File "/mnt/vdb1/app/venv/lib/python3.10/site-packages/starlette/routing.py", line 297, in handle
    | await self.app(scope, receive, send)
    | File "/mnt/vdb1/app/venv/lib/python3.10/site-packages/starlette/routing.py", line 77, in app
    | await wrap_app_handling_exceptions(app, request)(scope, receive, send)
    | File "/mnt/vdb1/app/venv/lib/python3.10/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app
    | raise exc
    | File "/mnt/vdb1/app/venv/lib/python3.10/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    | await app(scope, receive, sender)
    | File "/mnt/vdb1/app/venv/lib/python3.10/site-packages/starlette/routing.py", line 75, in app
    | await response(scope, receive, send)
    | File "/mnt/vdb1/app/venv/lib/python3.10/site-packages/sse_starlette/sse.py", line 255, in call
    | async with anyio.create_task_group() as task_group:
    | File "/mnt/vdb1/app/venv/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 680, in aexit
    | raise BaseExceptionGroup(
    | exceptiongroup.ExceptionGroup: unhandled errors in a TaskGroup (1 sub-exception)
    +-+---------------- 1 ----------------
    | RuntimeError: super(): class cell not found
    |
    | The above exception was the direct cause of the following exception:
    |
    | Traceback (most recent call last):
    | File "/mnt/vdb1/app/venv/lib/python3.10/site-packages/sse_starlette/sse.py", line 258, in wrap
    | await func()
    | File "/mnt/vdb1/app/venv/lib/python3.10/site-packages/sse_starlette/sse.py", line 245, in stream_response
    | async for data in self.body_iterator:
    | File "/mnt/vdb1/app/venv/lib/python3.10/site-packages/langserve/api_handler.py", line 1243, in _stream_log
    | "data": self._serializer.dumps(data).decode("utf-8"),
    | File "/mnt/vdb1/app/venv/lib/python3.10/site-packages/langserve/serialization.py", line 168, in dumps
    | return orjson.dumps(obj, default=default)
    | TypeError: Type is not JSON serializable: numpy.float64
    ###################################################
    redundant_filter = EmbeddingsRedundantFilter(embeddings=embeddings)
    relevant_filter = EmbeddingsFilter(embeddings=embeddings, similarity_threshold=0.76)
    pipeline_compressor_fast = DocumentCompressorPipeline(
    transformers=[redundant_filter, relevant_filter]
    )
    compressed_retriever = ContextualCompressionRetriever(
    base_compressor=pipeline_compressor_fast, base_retriever=retriever
    )
    app = FastAPI(
    title="LangChain Server",
    version="1.0",
    description="Spin up a simple api server using Langchain's Runnable interfaces",
    )
    add_routes(app, compressed_retriever,path="/retriever")
    ###################################################
    If I use the original retriever(no compressed),the error won't occur:
    add_routes(app, retriever,path="/retriever")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant