run-llama / llama_index

LlamaIndex is a data framework for your LLM applications
https://docs.llamaindex.ai
MIT License
37.07k stars 5.32k forks source link

[Question]: Using RedisChatStore in a workflow #16615

Open hristogg opened 1 month ago

hristogg commented 1 month ago

Question Validation

Question

Hi,

I have a workflow in which i initialize a CondensePlusContextChatEngine.from_defualts() passing a ChatMemoryBuffer.from_defaults which gets passed a RedisChatStore

Every run of the workflow I get Exception ignored in: <function AbstractConnection.__del__ at 0x000001CD05D63EC0> Traceback (most recent call last): File "c:\Users\hgospodinov\venv\v3_gradio\Lib\site-packages\redis\asyncio\connection.py", line 217, in __del__ File "c:\Users\hgospodinov\venv\v3_gradio\Lib\site-packages\redis\asyncio\connection.py", line 224, in _close File "C:\Users\hgospodinov\venv\python3119\Lib\asyncio\streams.py", line 358, in close File "C:\Users\hgospodinov\venv\python3119\Lib\asyncio\proactor_events.py", line 109, in close File "C:\Users\hgospodinov\venv\python3119\Lib\asyncio\base_events.py", line 762, in call_soon File "C:\Users\hgospodinov\venv\python3119\Lib\asyncio\base_events.py", line 520, in _check_closed RuntimeError: Event loop is closed

I am not sure whether I am doing something wrong myself or it is part of how the chatstore is actually called. If I understand correctly the flow CondensePlusContextChatEngine's achat calls _arun_c3 which calls _memory.get(input=message) going to the ChatMemoryBuffer which calls get_messages of the RedisChatStore, my assumption was that if I am doing achat it should finally reach the aget_messages in the clienet and not the get_messages.

The versions I have: llama-index-storage-chat-store-redis==0.3.2 llama-index==0.11.18 llama-index-core==0.11.18

I am guessing I am doing something wrong but hope you guys can point me in the right direction, let me know if I should post the full code.

dosubot[bot] commented 1 month ago

Hello, @hristogg! I'm here to assist you with any bugs, questions, or contributions you need help with. Let's tackle this issue together!

The error you're encountering, "RuntimeError: Event loop is closed," typically occurs when an asynchronous operation is attempted after the event loop has been closed. This can happen if the asynchronous resources are not properly managed or closed before the event loop ends.

In your workflow, it seems like the CondensePlusContextChatEngine might be using synchronous methods instead of asynchronous ones, which could lead to this issue. Specifically, if get_messages is being called instead of aget_messages, it might indicate that the asynchronous context is not being properly utilized.

Here are a few suggestions to resolve this issue:

  1. Ensure Asynchronous Context: Make sure that all parts of your workflow that involve asynchronous operations are running within an async function and that you are using await where necessary.

  2. Check Method Usage: Verify that the CondensePlusContextChatEngine and ChatMemoryBuffer are configured to use asynchronous methods. If achat is expected to be asynchronous, ensure that it is correctly reaching aget_messages instead of get_messages.

  3. Properly Close Connections: Ensure that any connections or resources opened during the workflow are properly closed before the event loop is terminated. This might involve explicitly closing the Redis connection or other resources.

  4. Review Initialization: Double-check the initialization of your components to ensure they are set up for asynchronous operation. This includes verifying that the RedisChatStore is initialized with an asynchronous client if needed.

If these steps do not resolve the issue, you might want to review the specific implementation details of the CondensePlusContextChatEngine and ChatMemoryBuffer to ensure they are compatible with asynchronous workflows.

To continue talking to Dosu, mention @dosu.

logan-markewich commented 1 month ago

This seems fine actually?

If I had to guess, your workflow is running fine, and you are able to get a result. This is getting printed when the program shuts down (probably due to the class not closing the connection properly?)

hristogg commented 1 month ago

Oh thanks, not to worry about it then, saw the documentation on redis for closing the connection but thought it might have other impacts and then ran down the rabbit hole of seeing what is happenning.